List of usage examples for com.google.gwt.dom.client Node ELEMENT_NODE
short ELEMENT_NODE
To view the source code for com.google.gwt.dom.client Node ELEMENT_NODE.
Click Source Link
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); }/*ww w . j a va 2 s. com*/ 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.GWTDOMStructure.java
License:Open Source License
@Override public String getId() throws Exception { if (this.element.element.getNodeType() == Node.ELEMENT_NODE) { String attr = ((Element) this.element.element).getAttribute("id"); if (attr != null && attr.length() > 0) { return attr; }//from w ww . j a v a 2 s. c o m } return null; }
From source file:bz.davide.dmxmljson.unmarshalling.dom.gwt.GWTDOMStructure.java
License:Open Source License
@Override public String getRefId() throws Exception { if (this.element.element.getNodeType() == Node.ELEMENT_NODE) { String attr = ((Element) this.element.element).getAttribute("refid"); if (attr != null && attr.length() > 0) { return attr; }/* w w w. ja va 2 s . c om*/ } return null; }
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 ww w.j a va2 s . c o m*/ } 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.WidgetUtils.java
License:Apache License
public static Element getElementForPositioning0(Element from) { assert tempPositioningText == null; if (!isVisibleAncestorChain(from)) { return null; }/*from w w w .j ava2s .c o m*/ boolean hidden = isZeroOffsetDims(from); int kidCount = from.getChildCount(); if (kidCount != 0 && !hidden) { return from; } Node parent = from.getParentNode(); if (parent != null && parent.getFirstChild() == from && parent.getNodeType() == Node.ELEMENT_NODE && !isZeroOffsetDims((Element) parent)) { return (Element) parent; } ClientNodeIterator itr = new ClientNodeIterator(from, ClientNodeIterator.SHOW_ALL); Element fromContainingBlock = DomUtils.getContainingBlock(from); Node node = from; int insertTextIfOffsetMoreThanXChars = 100; while ((node = node.getPreviousSibling()) != null) { if (node.getNodeType() == Node.TEXT_NODE) { insertTextIfOffsetMoreThanXChars -= TextUtils.normalizeWhitespaceAndTrim(node.getNodeValue()) .length(); if (insertTextIfOffsetMoreThanXChars < 0) { // this causes a relayout - so we try and avoid. most of the // time, positioning elements will contain text (or be from // a friendly browser), or be at the start of a block elt) tempPositioningText = Document.get().createTextNode("---"); from.appendChild(tempPositioningText); return from; } } } // give up after 50 node iterations (big tables maybe) int max = 50; while ((node = itr.nextNode()) != null && max-- > 0) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (!isZeroOffsetDims(node.getParentElement()) && node.getNodeName().equalsIgnoreCase("img")) { return (Element) node; } if (!UIObject.isVisible((Element) node)) { itr.skipChildren(); } } else { // text if (!isZeroOffsetDims(node.getParentElement()) // we don't want the combined ancestor of everyone... && (!node.getParentElement().isOrHasChild(from) || // but we do want <p><a><b>*some-text*</b></p> DomUtils.getContainingBlock(node) == fromContainingBlock)) { return node.getParentElement(); } } } return from.getParentElement(); }
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 ww w . j ava 2 s .com*/ // 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:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java
License:Mozilla Public License
/** * Factory method to wrap a DOM node with a wrapper that implements the Saxon * NodeInfo interface./*from w w w . ja v a2s. c o m*/ * @param node The DOM node * @param docWrapper The wrapper for the containing Document node * * @param parent The wrapper for the parent of the JDOM node * @param index The position of this node relative to its siblings * @return The new wrapper for the supplied node */ protected HTMLNodeWrapper makeWrapper(Node node, HTMLDocumentWrapper docWrapper, HTMLNodeWrapper parent, int index) { HTMLNodeWrapper wrapper; switch (node.getNodeType()) { case Node.DOCUMENT_NODE: case DOCUMENT_FRAGMENT_NODE: return docWrapper; case Node.ELEMENT_NODE: wrapper = new HTMLNodeWrapper(node, parent, index); wrapper.nodeKind = Type.ELEMENT; break; case Type.ATTRIBUTE: wrapper = new HTMLNodeWrapper(node, parent, index); wrapper.nodeKind = Type.ATTRIBUTE; break; case Node.TEXT_NODE: wrapper = new HTMLNodeWrapper(node, parent, index); wrapper.nodeKind = Type.TEXT; break; case CDATA_SECTION_NODE: wrapper = new HTMLNodeWrapper(node, parent, index); wrapper.nodeKind = Type.TEXT; break; case Type.COMMENT: wrapper = new HTMLNodeWrapper(node, parent, index); wrapper.nodeKind = Type.COMMENT; break; case Type.PROCESSING_INSTRUCTION: wrapper = new HTMLNodeWrapper(node, parent, index); wrapper.nodeKind = Type.PROCESSING_INSTRUCTION; break; default: short nodeType = node.getNodeType(); throw new IllegalArgumentException( "Unsupported node type in DOM! " + node.getNodeType() + " instance " + node.toString()); } wrapper.docWrapper = docWrapper; return wrapper; }
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 . ja v a 2 s.co m*/ sb.append(getValue(child)); } } }
From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java
License:Mozilla Public License
/** * Get all namespace undeclarations and undeclarations defined on this element. * * @param buffer If this is non-null, and the result array fits in this buffer, then the result * may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap. * @return An array of integers representing the namespace declarations and undeclarations present on * this element. For a node other than an element, return null. Otherwise, the returned array is a * sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The * top half word of each namespace code represents the prefix, the bottom half represents the URI. * If the bottom half is zero, then this is a namespace undeclaration rather than a declaration. * The XML namespace is never included in the list. If the supplied array is larger than required, * then the first unused entry will be set to -1. * <p/>/* www . j av a 2s .com*/ * <p>For a node other than an element, the method returns null.</p> */ public NamespaceBinding[] getDeclaredNamespaces(NamespaceBinding[] buffer) { if (nodeKind == Node.ELEMENT_NODE) { if (namespaceBindings == null) { this.getAltAttributes(); } NamespaceBinding[] bindings = new NamespaceBinding[namespaceBindings.size()]; namespaceBindings.toArray(bindings); return bindings; } else { return null; } }
From source file:com.ait.toolkit.editors.ckeditor.client.CKEditor.java
License:Open Source License
/** * Use to disable CKEditor's instance/*from www .java 2 s. c om*/ * * @param disabled */ public void setEnabled(boolean enabled) { // FIXME : rework this part to remove the ! boolean disabled = !enabled; if (this.disabled != disabled) { this.disabled = disabled; if (disabled) { ScrollPanel scroll = new ScrollPanel(); disabledHTML = new HTML(); disabledHTML.setStyleName("GWTCKEditor-Disabled"); scroll.setWidget(disabledHTML); if (config.getWidth() != null) scroll.setWidth(config.getWidth()); if (config.getHeight() != null) scroll.setHeight(config.getHeight()); String htmlString = new String(); if (replaced) { htmlString = getHTML(); } else { htmlString = waitingText; } DivElement divElement = DivElement.as(this.getElement().getFirstChildElement()); Node node = divElement.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { com.google.gwt.dom.client.Element element = com.google.gwt.dom.client.Element.as(node); if (element.getTagName().equalsIgnoreCase("textarea")) { destroyInstance(); replaced = false; divElement.removeChild(node); ckEditorNode = node; } } node = node.getNextSibling(); } disabledHTML.setHTML(htmlString); div.appendChild(scroll.getElement()); } else { if (ckEditorNode != null) { DivElement divElement = DivElement.as(this.getElement().getFirstChildElement()); Node node = divElement.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { com.google.gwt.dom.client.Element element = com.google.gwt.dom.client.Element.as(node); if (element.getTagName().equalsIgnoreCase("div")) { divElement.removeChild(node); } } node = node.getNextSibling(); } div.appendChild(baseTextArea); initInstance(); } } } }