List of usage examples for com.google.gwt.dom.client NodeList getLength
public int getLength()
From source file:client.net.sf.saxon.ce.dom.HTMLWriter.java
License:Mozilla Public License
/** * Start of an element.// w ww. j av a 2 s . c o m */ public void startElement(int nameCode, int properties) throws XPathException { String localName = namePool.getLocalName(nameCode); String prefix = namePool.getPrefix(nameCode); String uri = namePool.getURI(nameCode); // TODO: For XML Writer it should write prefixes in a // way compliant with the XSLT2.0 specification - using xsl:output attributes Element element = null; if (uri != null && !uri.isEmpty()) { if (mode == WriteMode.XML && !prefix.equals("")) { element = createElementNS(document, uri, prefix + ":" + localName); } else { // no svg specific prefix now used, for compliance with HTML5 element = createElementNS(document, uri, localName); } } // if there's no namespace - or no namespace support if (element == null) { element = document.createElement(localName); } // special case for html element: write to the document node Controller controller = pipe.getController(); if (controller != null && controller.getApiCommand() == APIcommand.UPDATE_HTML && (localName.equals("html") || localName.equals("head") || localName.equals("body"))) { if (localName.equals("html")) { element = (Element) document.getFirstChild(); } else { element = (Element) document.getElementsByTagName(localName.toUpperCase()).getItem(0); NodeList<Node> nodes = element.getChildNodes(); for (int n = 0; n < nodes.getLength(); n++) { Node node = nodes.getItem(n); node.removeFromParent(); } } currentNode = element; level++; return; } if (nextSibling != null && level == 0) { currentNode.insertBefore(element, nextSibling); } else { try { currentNode.appendChild(element); } catch (JavaScriptException err) { if (uri.equals(NamespaceConstant.IXSL)) { XPathException xpe = new XPathException( "Error on adding IXSL element to the DOM, the IXSL namespace should be added to the 'extension-element-prefixes' list."); throw (xpe); } else { throw (new XPathException(err.getMessage())); } } catch (Exception exc) { XPathException xpe = new XPathException( "Error on startElement in HTMLWriter for element '" + localName + "': " + exc.getMessage()); throw (xpe); } } currentNode = element; level++; }
From source file:client.net.sf.saxon.ce.trans.update.InsertAction.java
License:Mozilla Public License
/** * Apply the pending update action to the affected nodes * * @param context the XPath evaluation context *//*from w w w . j a v a 2 s .co m*/ public void apply(XPathContext context) { switch (position) { case FIRST: { NodeList list = content.getChildNodes(); int count = list.getLength(); for (int i = count - 1; i >= 0; i--) { targetNode.insertFirst(list.getItem(i)); } break; } case LAST: { while (content.hasChildNodes()) { targetNode.appendChild(content.getFirstChild()); } break; } case BEFORE: { Node refNode = targetNode.getChild(position); NodeList list = content.getChildNodes(); int count = list.getLength(); for (int i = 0; i < count; i++) { targetNode.insertBefore(list.getItem(i), refNode); } break; } case AFTER: { Node refNode = targetNode.getChild(position); NodeList list = content.getChildNodes(); int count = list.getLength(); for (int i = count - 1; i >= 0; i--) { targetNode.insertAfter(list.getItem(i), refNode); } break; } default: throw new UnsupportedOperationException("Unknown insert position " + position); } }
From source file:client.net.sf.saxon.ce.Xslt20ProcessorImpl.java
License:Mozilla Public License
/** * The entry point for transforms initiate on module load, * fetches settings from the <code>application/xslt+xml style</code> element *///www .j a v a2s.c o m public void doTransformation() { Logger logger = Logger.getLogger("Xstl20Processor"); try { NodeList<Element> scripts = getScriptsOnLoad(); String sourceURI = null; String styleURI = null; String initialMode = null; String initialTemplate = null; boolean styleElementExists = false; for (int i = 0; i < scripts.getLength(); i++) { String type = scripts.getItem(i).getAttribute("type"); if (type.equals("application/xslt+xml")) { styleElementExists = true; styleURI = scripts.getItem(i).getAttribute("src"); sourceURI = scripts.getItem(i).getAttribute("data-source"); initialMode = scripts.getItem(i).getAttribute("data-initial-mode"); initialTemplate = scripts.getItem(i).getAttribute("data-initial-template"); break; } } if (!styleElementExists) { logger.info("Saxon-CE API initialised"); return; } else if (styleURI == null) { throw new XPathException("No XSLT stylesheet reference found"); } JavaScriptObject sourceDoc = null; String absSourceURI = null; if (sourceURI != null && sourceURI.length() != 0) { String pageHref = Window.Location.getHref(); absSourceURI = (new URI(pageHref).resolve(sourceURI)).toString(); if (pageHref.equals(absSourceURI)) { throw new XPathException("Cannot load XML with same URI as the host page"); } sourceDoc = SaxonceApi.createAsyncDoc(absSourceURI); // config.buildDocument(absSourceURI); } else if (initialTemplate == null) { throw new XPathException( "No data-source attribute or data-initial-template value found - one is required"); } String absStyleURI = (new URI(Window.Location.getHref()).resolve(styleURI)).toString(); DocumentInfo styleDoc; try { styleDoc = config.buildDocument(absStyleURI); } catch (XPathException e) { String reportURI = (absSourceURI != null) ? absSourceURI : styleURI; throw new XPathException("Failed to load XSLT stylesheet " + reportURI + ": " + e.getMessage()); } config.getDocumentPool().add(styleDoc, absStyleURI); // where document('') can find it Element body = getBodyElement(); localController.setInitialMode(initialMode); localController.setInitialTemplate(initialTemplate); localController.setApiCommand(APIcommand.UPDATE_HTML); localController.setTargetNode(Document.get()); // target node is the document node renderXML(sourceDoc, styleDoc, body); // principle output is to the body element } catch (Exception err) { logger.log(Level.SEVERE, err.getMessage()); } }
From source file:com.agnie.gwt.common.client.widget.ListBox.java
License:Open Source License
/** * To set ListItem Label as it's Title(tooltip) for each ListItem. *///from w ww. j av a 2 s.c om private void setTitle() { SelectElement selectElement = SelectElement.as(this.getElement()); NodeList<OptionElement> options = selectElement.getOptions(); for (int i = 0; i < options.getLength(); i++) { T t = this.list.get(i); options.getItem(i).setTitle(gt.getText(t)); } }
From source file:com.alkacon.geranium.client.util.DomUtil.java
License:Open Source License
/** * Returns all elements with the given CSS class and tag name including the root element.<p> * //from w w w . j av a 2 s.c om * @param className the class name to look for * @param tag the tag * @param rootElement the root element of the search * * @return the matching elements */ public static List<Element> getElementsByClass(String className, Tag tag, Element rootElement) { if ((rootElement == null) || (className == null) || (className.trim().length() == 0) || (tag == null)) { return null; } className = className.trim(); List<Element> result = new ArrayList<Element>(); if (internalHasClass(className, rootElement)) { result.add(rootElement); } NodeList<Element> elements = rootElement.getElementsByTagName(tag.toString()); for (int i = 0; i < elements.getLength(); i++) { if (internalHasClass(className, elements.getItem(i))) { result.add(elements.getItem(i)); } } return result; }
From source file:com.alkacon.geranium.client.util.DomUtil.java
License:Open Source License
/** * Returns the element position relative to its siblings.<p> * //w w w. j a v a 2s.com * @param e the element to get the position for * * @return the position, or <code>-1</code> if not found */ public static int getPosition(Element e) { NodeList<Node> childNodes = e.getParentElement().getChildNodes(); for (int i = childNodes.getLength(); i >= 0; i--) { if (childNodes.getItem(i) == e) { return i; } } return -1; }
From source file:com.alkacon.geranium.client.util.DomUtil.java
License:Open Source License
/** * Removes all script tags from the given element.<p> * /* w w w. jav a2 s. c o m*/ * @param element the element to remove the script tags from * * @return the resulting element */ public static Element removeScriptTags(Element element) { NodeList<Element> scriptTags = element.getElementsByTagName(Tag.script.name()); // iterate backwards over list to ensure all tags get removed for (int i = scriptTags.getLength() - 1; i >= 0; i--) { scriptTags.getItem(i).removeFromParent(); } return element; }
From source file:com.alkacon.geranium.client.util.PositionBean.java
License:Open Source License
/** * Returns a position info representing the dimensions of all visible child elements of the given panel (excluding elements with position:absolute). * If the panel has no visible child elements, it's outer dimensions are returned.<p> * /* w w w .j ava 2 s. c o m*/ * @param panel the panel * @param levels the levels to traverse down the DOM tree * @param includeSelf <code>true</code> to include the outer dimensions of the given panel * * @return the position info */ public static PositionBean getInnerDimensions(Element panel, int levels, boolean includeSelf) { boolean first = true; int top = 0; int left = 0; int bottom = 0; int right = 0; // if overflow is set to hidden, use the outer dimensions if (!Overflow.HIDDEN.getCssName().equals(DomUtil.getCurrentStyle(panel, Style.overflow))) { if (!includeSelf) { // check for any text content NodeList<Node> children = panel.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if ((children.getItem(i).getNodeType() == Node.TEXT_NODE) && (children.getItem(i).getNodeValue().trim().length() > 0)) { includeSelf = true; break; } } } if (includeSelf) { top = panel.getAbsoluteTop(); left = panel.getAbsoluteLeft(); bottom = top + panel.getOffsetHeight(); right = left + panel.getOffsetWidth(); first = false; } Element child = panel.getFirstChildElement(); while (child != null) { String tagName = child.getTagName(); if (tagName.equalsIgnoreCase("br") || tagName.equalsIgnoreCase("tr") || tagName.equalsIgnoreCase("thead") || tagName.equalsIgnoreCase("tfoot") || tagName.equalsIgnoreCase("script") || tagName.equalsIgnoreCase("style")) { // ignore tags with no relevant position info child = child.getNextSiblingElement(); continue; } String positioning = DomUtil.getCurrentStyle(child, Style.position); if (!Display.NONE.getCssName().equals(DomUtil.getCurrentStyle(child, Style.display)) && !(positioning.equalsIgnoreCase(Position.ABSOLUTE.getCssName()) || positioning.equalsIgnoreCase(Position.FIXED.getCssName()))) { PositionBean childDimensions = levels > 0 ? getInnerDimensions(child, levels - 1, true) : generatePositionInfo(panel); if (first) { first = false; top = childDimensions.getTop(); left = childDimensions.getLeft(); bottom = top + childDimensions.getHeight(); right = left + childDimensions.getWidth(); } else { int wTop = childDimensions.getTop(); top = top < wTop ? top : wTop; int wLeft = childDimensions.getLeft(); left = left < wLeft ? left : wLeft; int wBottom = wTop + childDimensions.getHeight(); bottom = bottom > wBottom ? bottom : wBottom; int wRight = wLeft + childDimensions.getWidth(); right = right > wRight ? right : wRight; } } child = child.getNextSiblingElement(); } } if (!first) { PositionBean result = new PositionBean(); result.setHeight(bottom - top); result.setWidth(right - left); result.setTop(top); result.setLeft(left); return result; } else { return generatePositionInfo(panel); } }
From source file:com.arcbees.chosen.client.ChosenImpl.java
License:Apache License
private boolean isAllowSingleDeselect() { NodeList<OptionElement> optionsList = selectElement.getOptions(); return options.isAllowSingleDeselect() && optionsList.getLength() > 0 && "".equals(optionsList.getItem(0).getText()); }
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
/** * Return the values of all selected options in an array. * Usefull to know which options are selected in case of multiple ChosenListBox * * @return the values of all selected options in an array */// ww w . j av a 2s . c o m public String[] getValues() { ChosenImpl impl = getChosenImpl(); if (impl != null) { List<String> selectedValues = impl.getSelectedValues(); return selectedValues.toArray(new String[selectedValues.size()]); } else { JsArrayString values = JsArrayString.createArray().cast(); NodeList<OptionElement> options = SelectElement.as(getElement()).getOptions(); for (int i = 0; i < options.getLength(); i++) { OptionElement option = options.getItem(i); if (option.isSelected()) { values.push(option.getValue()); } } String[] result = new String[values.length()]; for (int i = 0; i < values.length(); i++) { result[i] = values.get(i); } return result; } }