List of usage examples for com.google.gwt.dom.client NodeList getLength
public int getLength()
From source file:org.waveprotocol.wave.client.wavepanel.view.dom.DomUtil.java
License:Apache License
/** * Returns the specified child element of the given element. * //from w ww. j a v a 2 s . c o m * @param parent parent element * @param childTypeString string representaton of the child element * @param toExclude element to be excluded from the search * @param startFrom element to start search with * @param step step to change the child index */ private static Element findChildElementExclusive(Element parent, String childTypeString, Element toExclude, Element startFrom, int step) { if (parent != null) { NodeList<Node> children = parent.getChildNodes(); int begin; int end; if (step == +1) { begin = 0; end = children.getLength(); } else { begin = children.getLength() - 1; end = -1; } boolean startFound = false; for (int i = begin; i != end; i += step) { Node child = children.getItem(i); if (child instanceof Element) { Element e = (Element) child; if (doesElementHaveTypeString(e, childTypeString)) { if (e != toExclude) { if (startFrom != null && !startFound) { startFound = true; } else { return e; } } } } } } return null; }
From source file:org.xwiki.gwt.dom.client.Element.java
License:Open Source License
/** * Expands inner elements with meta data. * /*from ww w . jav a 2 s .c om*/ * @return this element */ public final Element expandInnerMetaData() { // Get all the inner elements with meta data. NodeList<com.google.gwt.dom.client.Element> elements = getElementsByTagName("*"); List<Element> elementsWithMetaData = new ArrayList<Element>(); for (int i = 0; i < elements.getLength(); i++) { Element element = (Element) elements.getItem(i); if (element.xHasAttribute(META_DATA_ATTR)) { elementsWithMetaData.add(element); } } // Expand meta data. Don't iterate the node list directly because it is live and meta data can contain elements. for (Element element : elementsWithMetaData) { // Remove the cached reference to the meta data document fragment because it might be shared by clone nodes. // We could have cloned the meta data document fragment but this is not reliable with some DOM nodes like // embedded objects. element.removeProperty(META_DATA_REF); element.expandMetaData(false); } return this; }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.font.DynamicListBoxPicker.java
License:Open Source License
/** * @return the additional option group, which contains all the options that were added dynamically *///from ww w . j a v a2s. c o m private Element getAdditionalOptionGroup() { NodeList<Element> groups = getElement().getElementsByTagName("optgroup"); if (groups.getLength() > 0) { // The last group should be the additional group. return groups.getItem(groups.getLength() - 1); } else { Element additionalGroup = getElement().getOwnerDocument().createOptGroupElement(); additionalGroup.setAttribute("label", getAdditionalOptionGroupLabel()); getElement().appendChild(additionalGroup); return additionalGroup; } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.image.ImageMetaDataExtractor.java
License:Open Source License
/** * {@inheritDoc}/*from w ww. ja v a 2 s. c o m*/ * * @see InnerHTMLListener#onInnerHTMLChange(Element) */ public void onInnerHTMLChange(Element parent) { // look up all images in this subtree NodeList<com.google.gwt.dom.client.Element> imgs = parent.getElementsByTagName("img"); for (int i = 0; i < imgs.getLength(); i++) { Element img = (Element) imgs.getItem(i); processElement(img); } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.importer.IEPasteFilter.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j av a 2s . c o m * * @see PasteFilter#filter(Document) */ @Override public void filter(Document document) { // We get the list of elements using a native DOM API instead of traversing the document because the DOM // document can be in an invalid state. NodeList<Element> descendants = document.getElementsByTagName("*"); List<Element> nonHTMLElements = new ArrayList<Element>(); for (int i = 0; i < descendants.getLength(); i++) { Element descendant = descendants.getItem(i); if (!StringUtils.isEmpty(descendant.getPropertyString("tagUrn"))) { nonHTMLElements.add(descendant); } } for (Element element : nonHTMLElements) { try { element.getParentNode().removeChild(element); } catch (Exception e) { // Skip this element. The DOM is in a bad state. } } super.filter(document); }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * Marks the BRs that have been added as spacers during the editing. These BRs were added to overcome a Mozilla bug * that prevents us from typing inside an empty block level element. *///w w w . j a va2 s . c o m protected void markSpacers() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> brs = document.getBody().getElementsByTagName(BR); for (int i = 0; i < brs.getLength(); i++) { Element br = brs.getItem(i).cast(); // Ignore the BRs that have been there from the beginning. if (LINE_BREAK.equals(br.getClassName())) { continue; } Node container = domUtils.getNearestBlockContainer(br); Node leaf = domUtils.getNextLeaf(br); boolean emptyLine = true; // Look if there is any visible element on the new line, taking care to remain in the current block // container. while (leaf != null && container == domUtils.getNearestBlockContainer(leaf)) { if (needsSpace(leaf)) { emptyLine = false; break; } leaf = domUtils.getNextLeaf(leaf); } if (emptyLine) { br.setClassName(SPACER); } else { br.removeAttribute(CLASS_NAME); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * @see #markSpacers()/*from w ww. j a v a 2 s. c om*/ */ protected void unMarkSpacers() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> brs = document.getBody().getElementsByTagName(BR); for (int i = 0; i < brs.getLength(); i++) { Element br = (Element) brs.getItem(i); if (SPACER.equals(br.getClassName())) { br.removeAttribute(CLASS_NAME); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * Marks the initial line breaks so they are not mistaken as {@link #SPACER}. */// w w w .j a va2 s . c o m protected void markInitialLineBreaks() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> brs = document.getBody().getElementsByTagName(BR); for (int i = 0; i < brs.getLength(); i++) { Element br = (Element) brs.getItem(i); // Skip the spaces and the BRs added by the browser before the document was loaded. if (!br.hasAttribute("_moz_dirty") && !SPACER.equals(br.getClassName())) { br.setClassName(LINE_BREAK); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * Replaces {@code <div class="wikimodel-emptyline"/>} with {@code <p/>}. Empty lines are used by WikiModel to * separate block level elements, but since the user should be able to write on these empty lines we convert them to * paragraphs.//ww w. ja v a 2s . c o m */ protected void replaceEmptyLinesWithParagraphs() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> divs = document.getBody().getElementsByTagName("div"); // Since NodeList is updated when one of its nodes are detached, we store the empty lines in a separate list. List<Node> emptyLines = new ArrayList<Node>(); for (int i = 0; i < divs.getLength(); i++) { Element div = divs.getItem(i).cast(); if (div.hasClassName("wikimodel-emptyline")) { emptyLines.add(div); } } // Replace the empty lines with paragraphs. for (Node emptyLine : emptyLines) { emptyLine.getParentNode().replaceChild(document.createPElement(), emptyLine); } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.link.EmptyLinkFilter.java
License:Open Source License
/** * @return the list of empty anchors//from www. j a v a 2s. c o m * @see #isEmpty(Element) */ private List<Element> getEmptyAnchors() { List<Element> emptyAnchors = new ArrayList<Element>(); NodeList<Element> anchorsList = rta.getDocument().getElementsByTagName("a"); for (int i = 0; i < anchorsList.getLength(); i++) { Element anchor = anchorsList.getItem(i); if (isEmpty(AnchorElement.as(anchor))) { emptyAnchors.add(anchor); } } return emptyAnchors; }