org.w3c.dom.html.HTMLElement Java Examples

The following examples show how to use org.w3c.dom.html.HTMLElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HtmlContent.java    From LoboBrowser with MIT License 6 votes vote down vote up
public String getDescription() {
  final NodeList nodeList = this.document.getElementsByTagName("meta");
  if (nodeList == null) {
    return null;
  }
  final int length = nodeList.getLength();
  for (int i = 0; i < length; i++) {
    final Node node = nodeList.item(i);
    if (node instanceof HTMLElement) {
      final HTMLElement element = (HTMLElement) node;
      final String name = element.getAttribute("name");
      if ((name != null) && name.equalsIgnoreCase("description")) {
        return element.getAttribute("description");
      }
    }
  }
  return null;
}
 
Example #2
Source File: ShowPanelFrame.java    From oim-fx with MIT License 6 votes vote down vote up
private void initEvent() {
	button.setOnAction(new EventHandler<ActionEvent>() {

		@Override
		public void handle(ActionEvent event) {
			
			Document doc = webPage.getDocument(webPage.getMainFrame());
			if (doc instanceof HTMLDocument) {
				HTMLDocument htmlDocument = (HTMLDocument) doc;
				Element e = htmlDocument.createElement("div");
				e.setTextContent("hhhhhhh");
				HTMLElement htmlDocumentElement = (HTMLElement)htmlDocument.getDocumentElement();
		        HTMLElement htmlBodyElement = (HTMLElement)htmlDocumentElement.getElementsByTagName("body").item(0);
		        
				//e.setAttribute(name, value);
		        //org.w3c.dom.Node n=htmlBodyElement.getLastChild();;
		        htmlBodyElement.appendChild(e);
		        webPage.getClientInsertPositionOffset();
		       // htmlBodyElement.ge
				//hd.appendChild(e);
				System.out.println(e.getClass());
			}
		}
	});

}
 
Example #3
Source File: DocumentImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Element getElementById( String elementId ) {
    for (Iterator each = preOrderIterator(); each.hasNext();) {
        Node node = (Node) each.next();
        if (!(node instanceof HTMLElement)) continue;
        HTMLElement element = (HTMLElement) node;
        if (elementId.equals( element.getId() )) return element;
    }
    return null;
}
 
Example #4
Source File: HtmlClientlet.java    From LoboBrowser with MIT License 5 votes vote down vote up
private Map<String, String> getHttpEquivData() {
  final Collection<HTMLElement> httpEquivElements = this.httpEquivElements;
  if (httpEquivElements == null) {
    return null;
  }
  final Map<String, String> httpEquivData = new HashMap<>(0);
  for (final Element element : httpEquivElements) {
    final String httpEquiv = element.getAttribute("http-equiv");
    if (httpEquiv != null) {
      final String content = element.getAttribute("content");
      httpEquivData.put(httpEquiv, content);
    }
  }
  return httpEquivData;
}
 
Example #5
Source File: HtmlClientlet.java    From LoboBrowser with MIT License 5 votes vote down vote up
private final static boolean mayBeVisibleElement(final NodeImpl node) {
  if (node instanceof HTMLElement) {
    final HTMLElement element = (HTMLElement) node;
    final boolean visible = !NON_VISIBLE_ELEMENTS.contains(element.getTagName().toLowerCase());
    if (visible && logger.isLoggable(Level.INFO)) {
      logger.info("mayBeVisibleElement(): Found possibly visible element: " + element.getTagName());
    }
    return visible;
  } else {
    return false;
  }
}
 
Example #6
Source File: HtmlClientlet.java    From LoboBrowser with MIT License 5 votes vote down vote up
private void addHttpEquivElement(final HTMLElement element) {
  Collection<HTMLElement> httpEquivElements = this.httpEquivElements;
  if (httpEquivElements == null) {
    httpEquivElements = new LinkedList<>();
    this.httpEquivElements = httpEquivElements;
  }
  httpEquivElements.add(element);
}
 
Example #7
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 5 votes vote down vote up
public boolean onContextMenu(final HTMLElement element, final MouseEvent event) {
  final JPopupMenu popupMenu = new JPopupMenu();
  if (popupMenu.isPopupTrigger(event)) {
    populatePopup(element, popupMenu);

    popupMenu.show(event.getComponent(), event.getX(), event.getY());
    return false;
  }
  return true;
}
 
Example #8
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 5 votes vote down vote up
public boolean onMiddleClick(final HTMLElement element, final MouseEvent event) {
  final Runnable task = getMiddleClickTask(element);
  if (task != null) {
    SwingUtilities.invokeLater(task);
    return false;
  }
  return true;
}
 
Example #9
Source File: WritePanel.java    From oim-fx with MIT License 5 votes vote down vote up
private void updateStyle() {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);
		htmlBodyElement.setAttribute("style", createStyleValue().toString());
	}
}
 
Example #10
Source File: HTMLCollectionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Node namedItem( String name ) {
    if (name == null) return null;

    Node nodeByName = null;
    for (int i = 0; null == nodeByName && i < getLength(); i++) {
        Node node = item(i);
        if (!(node instanceof HTMLElementImpl)) continue;
        if (name.equalsIgnoreCase( ((HTMLElement) node).getId() )) return node;
        if (name.equalsIgnoreCase( ((HTMLElementImpl) node).getAttributeWithNoDefault( "name" )) ) nodeByName = node;
    }
    return nodeByName;
}
 
Example #11
Source File: WritePane.java    From oim-fx with MIT License 5 votes vote down vote up
private void updateStyle() {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);
		htmlBodyElement.setAttribute("style", createStyleValue().toString());
	}
}
 
Example #12
Source File: ChatWritePane.java    From oim-fx with MIT License 5 votes vote down vote up
public void insertImage(String path, String id, String name, String value) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
		}

		Element e = htmlDocument.createElement("img");
		e.setAttribute("id", id);
		e.setAttribute("name", name);
		e.setAttribute("value", value);
		e.setAttribute("src", path);

		// webEngine.get
		// webView.get

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}
		webPage.getClientInsertPositionOffset();
	}
}
 
Example #13
Source File: ChatWritePane.java    From oim-fx with MIT License 5 votes vote down vote up
public void insert(String text) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
		}

		Element e = htmlDocument.createElement("div");
		e.setTextContent(text);

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			// htmlBodyElement.
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}

		webPage.getClientInsertPositionOffset();

	}
}
 
Example #14
Source File: ChatWritePane.java    From oim-fx with MIT License 5 votes vote down vote up
private void updateStyle() {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);
		htmlBodyElement.setAttribute("style", createStyleValue().toString());
	}
}
 
Example #15
Source File: ShowPanel.java    From oim-fx with MIT License 5 votes vote down vote up
public void insertLast(String text, String fontName, int fontSize, String color, boolean bold, boolean underline, boolean italic) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		Element element = htmlDocument.createElement("div");
		element.setTextContent(text);
		element.setAttribute("style", createStyleValue(fontName, fontSize, color, bold, underline, italic).toString());
		htmlBodyElement.appendChild(element);

	}
}
 
Example #16
Source File: WritePanel.java    From oim-fx with MIT License 5 votes vote down vote up
public void insertImage(String path, String id, String name, String value) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
			// HTMLBodyElementImpl htmlBodyElementImpl =
			// (HTMLBodyElementImpl) htmlBodyElement;
			// Element e = htmlBodyElementImpl.getOffsetParent();
			// htmlBodyElementImpl.insertBefore(newChild, refChild)
			// htmlDocument.
		}

		Element e = htmlDocument.createElement("img");
		e.setAttribute("id", id);
		e.setAttribute("name", name);
		e.setAttribute("value", value);
		e.setAttribute("src", path);

		// webEngine.get
		// webView.get

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}
		webPage.getClientInsertPositionOffset();
	}
}
 
Example #17
Source File: HTMLSelectElementImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void add( HTMLElement element, HTMLElement before ) throws DOMException {
}
 
Example #18
Source File: HTMLTableRowElementImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public HTMLElement insertCell( int index ) throws DOMException {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
}
 
Example #19
Source File: WritePane.java    From oim-fx with MIT License 4 votes vote down vote up
public void insert(String text) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
			// HTMLBodyElementImpl htmlBodyElementImpl =
			// (HTMLBodyElementImpl) htmlBodyElement;
			// Element e = htmlBodyElementImpl.getOffsetParent();
			// htmlBodyElementImpl.insertBefore(newChild, refChild)
			// htmlDocument.
		}

		Element e = htmlDocument.createElement("div");
		e.setTextContent(text);

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			// htmlBodyElement.
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}

		webPage.getClientInsertPositionOffset();

		// webView.set
		// System.out.println(htmlDocument.);

		//
		// org.w3c.dom.Node n = htmlBodyElement.getLastChild();
		//
		//
		//
		// webPage.getClientInsertPositionOffset();
		// // htmlBodyElement.ge
		// // hd.appendChild(e);
		// htmlDocument.getp
		//
	}
}
 
Example #20
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 4 votes vote down vote up
public void linkClicked(final HTMLElement linkNode, final @NonNull URL url, final String target) {
  this.navigateImpl(url, target, RequestType.CLICK, linkNode);
}
 
Example #21
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 4 votes vote down vote up
public HtmlObject getHtmlObject(final HTMLElement element) {
  // TODO
  return null;
}
 
Example #22
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 4 votes vote down vote up
public void onMouseOut(final HTMLElement element, final MouseEvent event) {
  if (element instanceof HTMLLinkElementImpl) {
    this.clientletFrame.setStatus(null);
  }
}
 
Example #23
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 4 votes vote down vote up
public void onMouseOver(final HTMLElement element, final MouseEvent event) {
  if (element instanceof HTMLLinkElementImpl) {
    final HTMLLinkElementImpl linkElement = (HTMLLinkElementImpl) element;
    this.clientletFrame.setStatus(linkElement.getAbsoluteHref());
  }
}
 
Example #24
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 4 votes vote down vote up
public boolean onDoubleClick(final HTMLElement element, final MouseEvent event) {
  return true;
}
 
Example #25
Source File: HtmlRendererContextImpl.java    From LoboBrowser with MIT License 4 votes vote down vote up
public boolean onMouseClick(final HTMLElement element, final MouseEvent event) {
  return true;
}
 
Example #26
Source File: WritePanel.java    From oim-fx with MIT License 4 votes vote down vote up
public void insert(String text) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
			// HTMLBodyElementImpl htmlBodyElementImpl =
			// (HTMLBodyElementImpl) htmlBodyElement;
			// Element e = htmlBodyElementImpl.getOffsetParent();
			// htmlBodyElementImpl.insertBefore(newChild, refChild)
			// htmlDocument.
		}

		Element e = htmlDocument.createElement("div");
		e.setTextContent(text);

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			// htmlBodyElement.
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}

		webPage.getClientInsertPositionOffset();

		// webView.set
		// System.out.println(htmlDocument.);

		//
		// org.w3c.dom.Node n = htmlBodyElement.getLastChild();
		//
		//
		//
		// webPage.getClientInsertPositionOffset();
		// // htmlBodyElement.ge
		// // hd.appendChild(e);
		// htmlDocument.getp
		//
	}
}