List of usage examples for com.google.gwt.dom.client NodeList getLength
public int getLength()
From source file:bz.davide.dmxmljson.unmarshalling.dom.gwt.GWTDOMStructure.java
License:Open Source License
private void extractChildElementByName() { NodeList nl = this.element.element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.getItem(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String tagName = element.getTagName().toLowerCase(); String[] parts = extractNameAndSubtype(tagName); String attrName = parts[0]; ElementAndSubtype elementAndSubtype = new ElementAndSubtype(); elementAndSubtype.element = element; elementAndSubtype.subtype = parts[1]; ArrayList<ElementAndSubtype> elements = this.elementsByName.get(attrName); if (elements == null) { elements = new ArrayList<ElementAndSubtype>(); this.elementsByName.put(attrName, elements); }/* w w w . j a v a2 s. c om*/ elements.add(elementAndSubtype); ElementAndSubtype childElementAndSubtype = new ElementAndSubtype(); childElementAndSubtype.element = element; childElementAndSubtype.subtype = tagName; // Convert first letter to upper case, because java classes start normally with upper case childElementAndSubtype.subtype = childElementAndSubtype.subtype.substring(0, 1).toUpperCase() + childElementAndSubtype.subtype.substring(1); this.childNodes.add(childElementAndSubtype); } if (node.getNodeType() == Node.TEXT_NODE) { String txt = node.getNodeValue(); if (txt.trim().length() > 0) { ElementAndSubtype childElementAndSubtype = new ElementAndSubtype(); childElementAndSubtype.element = node; childElementAndSubtype.subtype = "TextNode"; this.childNodes.add(childElementAndSubtype); } } } }
From source file:bz.davide.dmxmljson.unmarshalling.dom.gwt.GWTDOMValue.java
License:Open Source License
void recursiveText(Node node, StringBuffer sb) { if (node.getNodeType() == Node.TEXT_NODE) { sb.append(node.getNodeValue());/*from w ww. j a va2s. c om*/ } if (node.getNodeType() == Node.ELEMENT_NODE) { NodeList<Node> nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { this.recursiveText(nl.getItem(i), sb); } } }
From source file:cc.alcina.framework.gwt.client.util.ClientUtils.java
License:Apache License
public static Element updateCss(Element styleElement, String css) { if (styleElement == null) { styleElement = Document.get().createStyleElement(); NodeList<Element> headList = Document.get().getElementsByTagName(HEAD); if (headList == null || headList.getLength() == 0) { // something wrong with the client here -- bail AlcinaTopics//www. j av a2s . c o m .notifyDevWarning(new Exception("headList - " + headList == null ? "null" : "length 0")); return null; } headList.getItem(0).appendChild(styleElement); LocalDom.flush(); } if (css.length() != 0) { try { if (!setCssTextViaCssTextProperty(styleElement, css)) { styleElement.setInnerText(css); } } catch (Exception e) { // squelch } } return styleElement; }
From source file:cc.kune.common.client.utils.MetaUtils.java
License:GNU Affero Public License
/** * Get the value of meta information writen in the html page. The meta * information is a html tag with name of meta usually placed inside the the * head section with two attributes: id and content. For example: * //from w w w .j a v a 2 s.co m * <code><meta name="name" value="userName" /></code> * * @param name the name * @return the value of the attribute 'content' or null if not found */ public static String get(final String name) { final NodeList<Element> tags = Document.get().getElementsByTagName("meta"); for (int i = 0; i < tags.getLength(); i++) { final MetaElement metaTag = ((MetaElement) tags.getItem(i)); if (metaTag.getName().equals(name)) { return metaTag.getContent(); } } return null; }
From source file:ch.bergturbenthal.hs485.frontend.gwtfrontend.client.svg.SVGProcessor.java
License:Open Source License
public static int normalizeIds(final OMSVGElement srcSvg) { docId++;/*from w w w.j ava 2 s .c om*/ // Collect all the original element ids and replace them with a // normalized id int idIndex = 0; final Map<String, Element> idToElement = new HashMap<String, Element>(); final Map<String, String> idToNormalizedId = new HashMap<String, String>(); final List<Element> queue = new ArrayList<Element>(); queue.add(srcSvg.getElement()); while (queue.size() > 0) { final Element element = queue.remove(0); final String id = element.getId(); if (id != null) { idToElement.put(id, element); final String normalizedId = "d" + docId + "_" + idIndex++; idToNormalizedId.put(id, normalizedId); element.setId(normalizedId); } final NodeList<Node> childNodes = element.getChildNodes(); for (int i = 0, length = childNodes.getLength(); i < length; i++) { final Node childNode = childNodes.getItem(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) queue.add((Element) childNode.cast()); } } // Change all the attributes which are URI references final Set<String> attNames = new HashSet<String>(Arrays.asList(new String[] { "clip-path", "mask", "marker-start", "marker-mid", "marker-end", "fill", "stroke", "filter", "cursor", "style" })); queue.add(srcSvg.getElement()); final IdRefTokenizer tokenizer = GWT.create(IdRefTokenizer.class); while (queue.size() > 0) { final Element element = queue.remove(0); if (DOMHelper.hasAttributeNS(element, SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_ATTRIBUTE)) { final String idRef = DOMHelper.getAttributeNS(element, SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_ATTRIBUTE).substring(1); final String normalizeIdRef = idToNormalizedId.get(idRef); DOMHelper.setAttributeNS(element, SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_ATTRIBUTE, "#" + normalizeIdRef); } final NamedNodeMap<Attr> attrs = DOMHelper.getAttributes(element); for (int i = 0, length = attrs.getLength(); i < length; i++) { final Attr attr = attrs.item(i); if (attNames.contains(attr.getName())) { final StringBuilder builder = new StringBuilder(); tokenizer.tokenize(attr.getValue()); IdRefTokenizer.IdRefToken token; while ((token = tokenizer.nextToken()) != null) { String value = token.getValue(); if (token.getKind() == IdRefTokenizer.IdRefToken.DATA) builder.append(value); else { value = idToNormalizedId.get(value); builder.append(value == null ? token.getValue() : value); } } attr.setValue(builder.toString()); } } final NodeList<Node> childNodes = element.getChildNodes(); for (int i = 0, length = childNodes.getLength(); i < length; i++) { final Node childNode = childNodes.getItem(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) queue.add((Element) childNode.cast()); } } return docId; }
From source file:ch.unifr.pai.twice.layout.client.mobile.MobileUtils.java
License:Apache License
/** * Add necessary html tags to ensure unified initial zoom levels of the web page, fullscreen establishment and add proprietary tags (e.g. * "apple-mobile-web-app-capable" for extended functionalities). * /* w w w .j ava2 s .c om*/ * The main purpose is to establish a "native" look of the application even within the boundaries of the web browser. */ public static void preparePage() { RootPanel.getBodyElement().getStyle().setHeight(100, Unit.PCT); RootPanel.getBodyElement().getStyle().setOverflow(Overflow.HIDDEN); RootPanel.getBodyElement().getStyle().setMargin(0, Unit.PX); RootPanel.getBodyElement().getStyle().setPadding(0, Unit.PX); Document.get().getDocumentElement().getStyle().setProperty("minHeight", "300px"); Document.get().getDocumentElement().getStyle().setHeight(100, Unit.PCT); NodeList<Element> tags = Document.get().getElementsByTagName("head"); Element head; if (tags.getLength() > 0) { head = tags.getItem(0); } else { head = DOM.createElement("head"); Document.get().insertFirst(head); } Element meta = DOM.createElement("meta"); meta.setAttribute("name", "viewport"); meta.setAttribute("content", "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"); head.appendChild(meta); LinkElement e = Document.get().createLinkElement(); e.setRel("stylesheet"); e.setHref(GWT.getModuleBaseURL() + "master.css"); head.appendChild(e); Element iphoneFullscreen = DOM.createElement("meta"); iphoneFullscreen.setAttribute("name", "apple-touch-fullscreen"); iphoneFullscreen.setAttribute("content", "yes"); head.appendChild(iphoneFullscreen); Element iphoneWebAppCapable = DOM.createElement("meta"); iphoneWebAppCapable.setAttribute("name", "apple-mobile-web-app-capable"); iphoneWebAppCapable.setAttribute("content", "yes"); head.appendChild(iphoneWebAppCapable); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { Window.scrollTo(0, 1); } }); }
From source file:ch.unifr.pai.twice.widgets.mpproxy.client.MPProxyBody.java
License:Apache License
/** * Replace all textboxes with multi focus text boxes * //from w w w. ja v a2 s . c o m * @param mainElement */ private void replaceAllTextBoxes(Element mainElement) { NodeList<com.google.gwt.dom.client.Element> inputFields = mainElement.getElementsByTagName("input"); for (int i = 0; i < inputFields.getLength(); i++) { final com.google.gwt.dom.client.Element el = inputFields.getItem(i); String type = el.getAttribute("type"); if (type == null || type.isEmpty() || type.equalsIgnoreCase("text")) { MultiFocusTextBox box = new MultiFocusTextBox(); box.replaceTextInput(InputElement.as(el)); replacements.add(box); // Scheduler.get().scheduleDeferred(new ScheduledCommand() { // // @Override // public void execute() { // el.getStyle().setDisplay(Display.NONE); // } // }); } } }
From source file:ch.unifr.pai.twice.widgets.mpproxy.client.ProxyBody.java
License:Apache License
/** * Client side logic to rewrite a given URL * /*from www . j ava 2 s .c o m*/ * @param element * @param servletPath * @param proxyPath */ public static void rewriteUrl(com.google.gwt.dom.client.Element element, String servletPath, String proxyPath) { NodeList<Node> nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.getItem(i); if (com.google.gwt.dom.client.Element.is(n)) { com.google.gwt.dom.client.Element e = com.google.gwt.dom.client.Element.as(n); if (e != null && e.getTagName() != null && e.getTagName().equalsIgnoreCase("a")) { AnchorElement anchor = AnchorElement.as(e); if (anchor.getHref() != null && !anchor.getHref().isEmpty()) anchor.removeAttribute("onmousedown"); } for (String att : attributesToManipulate) { String value = e.getAttribute(att); if (value != null && !value.startsWith(servletPath) && value.matches("((http)|/).*")) { String transformed = Rewriter.translateCleanUrl(value, servletPath, proxyPath); if (!transformed.equals(value)) e.setAttribute(att, transformed); } } rewriteUrl(e, servletPath, proxyPath); } } }
From source file:ch.unifr.pai.twice.widgets.mptransparentproxy.client.MPProxyBody.java
License:Apache License
/** * Replace all textboxes with multi focus text boxes * //w w w. j a v a 2 s . c o m * @param mainElement */ private void replaceAllTextBoxes(Element mainElement) { NodeList<com.google.gwt.dom.client.Element> inputFields = mainElement.getElementsByTagName("input"); for (int i = 0; i < inputFields.getLength(); i++) { final com.google.gwt.dom.client.Element el = inputFields.getItem(i); String type = el.getAttribute("type"); if (type == null || type.isEmpty() || type.equalsIgnoreCase("text") || type.equalsIgnoreCase("search")) { MultiFocusTextBox box = new MultiFocusTextBox(); box.replaceTextInput(InputElement.as(el)); replacements.add(box); } } }
From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java
License:Mozilla Public License
private static void expandStringValue(NodeList list, StringBuffer sb) { final int len = list.getLength(); for (int i = 0; i < len; i++) { Node child = list.getItem(i); switch (child.getNodeType()) { case Node.ELEMENT_NODE: expandStringValue(child.getChildNodes(), sb); break; case Type.COMMENT: case Type.PROCESSING_INSTRUCTION: break; default://from w w w. j a va2s. c o m sb.append(getValue(child)); } } }