Jump to content

How do i bind html DOM with java?


banzemanga

Recommended Posts

Hello, i know how to manipulate html DOM using Javascript but i want to do it with Java now.The thing is that i don't know how to use the dom library in java.I see that the dom library are interfaces and i don't know very much about interfaces.When i try to implement an interface, it says that the class must be abstract and i don't want to make abstract classes.So what i need is just a basic setup for the main method.Probably the simplest is to append some text on the body of the page.From there i believe i should be able to take it and make it run.I have been looking for simple examples like this one everywhere but i don't find any.I have been looking for books too but i can't find any neither.So, any sugestions?Thanks.Edit: Let's say i want to do this Javascript code in java:

window.onload = constructor;function constructor() { document.body.appendChild( document.createTextNode("Hello World!") );}

Edit2: So far i managed to code it but unable to load the jar file.

import java.io.IOException;import javax.xml.soap.SOAPElement;import javax.xml.soap.SOAPException;import org.w3c.dom.*;import org.w3c.dom.html.HTMLBodyElement;public class Main {	static HTMLBodyElement body = new HTMLBodyElement() {		public String getALink() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setALink(String aLink) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getBackground() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setBackground(String background) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getBgColor() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setBgColor(String bgColor) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getLink() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setLink(String link) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getText() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setText(String text) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getVLink() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setVLink(String vLink) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getId() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setId(String id) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getTitle() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setTitle(String title) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getLang() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setLang(String lang) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getDir() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setDir(String dir) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getClassName() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setClassName(String className) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getTagName() {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getAttribute(String name) {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setAttribute(String name, String value) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public void removeAttribute(String name) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public Attr getAttributeNode(String name) {			throw new UnsupportedOperationException("Not supported yet.");		}		public Attr setAttributeNode(Attr newAttr) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public Attr removeAttributeNode(Attr oldAttr) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public NodeList getElementsByTagName(String name) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getAttributeNS(String namespaceURI, String localName) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean hasAttribute(String name) {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public TypeInfo getSchemaTypeInfo() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setIdAttribute(String name, boolean isId) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getNodeName() {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getNodeValue() throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setNodeValue(String nodeValue) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public short getNodeType() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node getParentNode() {			throw new UnsupportedOperationException("Not supported yet.");		}		public NodeList getChildNodes() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node getFirstChild() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node getLastChild() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node getPreviousSibling() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node getNextSibling() {			throw new UnsupportedOperationException("Not supported yet.");		}		public NamedNodeMap getAttributes() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Document getOwnerDocument() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node insertBefore(Node newChild, Node refChild) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node replaceChild(Node newChild, Node oldChild) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node removeChild(Node oldChild) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node appendChild(Node newChild) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean hasChildNodes() {			throw new UnsupportedOperationException("Not supported yet.");		}		public Node cloneNode(boolean deep) {			throw new UnsupportedOperationException("Not supported yet.");		}		public void normalize() {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean isSupported(String feature, String version) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getNamespaceURI() {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getPrefix() {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setPrefix(String prefix) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getLocalName() {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean hasAttributes() {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getBaseURI() {			throw new UnsupportedOperationException("Not supported yet.");		}		public short compareDocumentPosition(Node other) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public String getTextContent() throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public void setTextContent(String textContent) throws DOMException {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean isSameNode(Node other) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String lookupPrefix(String namespaceURI) {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean isDefaultNamespace(String namespaceURI) {			throw new UnsupportedOperationException("Not supported yet.");		}		public String lookupNamespaceURI(String prefix) {			throw new UnsupportedOperationException("Not supported yet.");		}		public boolean isEqualNode(Node arg) {			throw new UnsupportedOperationException("Not supported yet.");		}		public Object getFeature(String feature, String version) {			throw new UnsupportedOperationException("Not supported yet.");		}		public Object setUserData(String key, Object data, UserDataHandler handler) {			throw new UnsupportedOperationException("Not supported yet.");		}		public Object getUserData(String key) {			throw new UnsupportedOperationException("Not supported yet.");		}	};		public static void main(String args[]) {		body.setText("Hello World");	}}

It is impossible to load an applet without an GUI?Edit3: Ok.... I learned something new. It seems that they were all empty interfaces that w3c provided and needed to be implemented by 'us' the programmers. I was able to find some libraries that implemented it -like Cobra, but it additionally required mozilla's rhino javascript library; so this is as crazy as ######. It is like Java calling for javascript functions to work. No wonder nobody does html dom manipulation with Java and go for JSP. But for JSP i need a server and it is quite troublesome. :)

Link to comment
Share on other sites

  • 2 weeks later...

Manipulating the DOM in Java is like trying to do it with ActiveX. It just wasn't made to do it. You may be able to hack something together but it probably isn't worth your effort. It is far easier to use Javascript and if you need have the server side code create the javascript commands.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...