List of usage examples for com.google.gwt.dom.client Node getChildCount
@Override
public int getChildCount()
From source file:client.net.sf.saxon.ce.expr.instruct.ResultDocument.java
License:Mozilla Public License
public TailCall processLeavingTail(XPathContext context) throws XPathException { final Controller controller = context.getController(); final APIcommand command = controller.getApiCommand(); XPathContext c2 = context.newMinorContext(); int action = APPEND_CONTENT; if (methodExpression != null) { String method = methodExpression.evaluateAsString(context).toString(); StructuredQName methodQ;//from w w w .j a va 2s .c o m if (method.indexOf(':') >= 0) { methodQ = StructuredQName.fromLexicalQName(method, false, nsResolver); } else { methodQ = new StructuredQName("", "", method); } if ("replace-content".equals(methodQ.getLocalName())) { // TODO: check the namespace URI is NamespaceConstant.IXSL action = REPLACE_CONTENT; } } String hrefValue = null; if (href != null) { hrefValue = href.evaluateAsString(context).toString(); } else if (command == APIcommand.UPDATE_HTML) { throw new XPathException("html update - no href value for result-document instruction"); } else { hrefValue = "result" + (controller.getResultDocumentCount() + 1); } NodeInfo target = null; Node targetNode = null; String contextNodeName = ""; String absURI = ""; if (command == APIcommand.TRANSFORM_TO_DOCUMENT) { absURI = getValidAbsoluteURI(controller, hrefValue); targetNode = XMLDOM.createDocument(absURI); } else if (command == APIcommand.TRANSFORM_TO_FRAGMENT || command == APIcommand.TRANSFORM_TO_HTML_FRAGMENT) { absURI = getValidAbsoluteURI(controller, hrefValue); targetNode = HTMLDocumentWrapper.createDocumentFragment((Document) controller.getTargetNode()); } else if (hrefValue.startsWith("#")) { hrefValue = hrefValue.substring(1); targetNode = ((Document) controller.getTargetNode()).getElementById(hrefValue); // com.google.gwt.dom.client.Document.get().getElementById(hrefValue); } else if (hrefValue.startsWith("?select=")) { String select = hrefValue.substring(8); AbstractStaticContext env = new AbstractStaticContext() { public String getURIForPrefix(String prefix) throws XPathException { return null; } public Expression bindVariable(StructuredQName qName) throws XPathException { return null; } public NamespaceResolver getNamespaceResolver() { return null; } //override getFunctionLibrary to return that loaded for the prepared stylesheet public FunctionLibrary getFunctionLibrary() { return controller.getPreparedStylesheet().getFunctionLibrary(); } }; ExpressionVisitor visitor = new ExpressionVisitor(); visitor.setConfiguration(context.getConfiguration()); visitor.setExecutable(new Executable(context.getConfiguration())); visitor.setStaticContext(env); env.setConfiguration(context.getConfiguration()); Container container = (StyleElement) getSourceLocator(); Expression expr = null; try { expr = ExpressionTool.make(select, env, container, 0, Token.EOF, getSourceLocator()); } catch (Exception e) { // occurs if expression contains references to variables etc. within the dynamic context throw new XPathException( "Error on evaluating (in static context) result-document href: " + hrefValue); } expr = visitor.typeCheck(expr, NodeKindTest.DOCUMENT); XPathContext c3 = context.newCleanContext(); //context for ?select expression is the html page if an external node is the context Document page = (Document) controller.getTargetNode(); //com.google.gwt.dom.client.Document.get(); Item cItem = context.getContextItem(); NodeInfo currentContextItem; if (cItem instanceof JSObjectValue) { currentContextItem = null; } else { currentContextItem = (NodeInfo) cItem; } boolean useCurrentContext; if (currentContextItem == null) { useCurrentContext = false; } else { useCurrentContext = (currentContextItem.getBaseURI().equals(page.getURL())); } NodeInfo contextItem; if (useCurrentContext) { contextItem = currentContextItem; if (LogConfiguration.loggingIsEnabled() && contextItem.getNodeKind() == Type.ELEMENT) { contextNodeName = controller.getNamePool().getLocalName(contextItem.getNameCode()); } } else { contextItem = new HTMLDocumentWrapper(page, page.getURL(), context.getConfiguration(), DocType.UNKNOWN); } if (LogConfiguration.loggingIsEnabled()) { contextNodeName = (contextNodeName.equals("") ? "" : " context node: " + contextNodeName); } AxisIterator iterator = SingleNodeIterator.makeIterator(contextItem); iterator.next(); // position on the single item c3.setCurrentIterator(iterator); SequenceIterator iter = expr.iterate(c3); Item resultItem = iter.next(); if (resultItem == null) { } // do nothing else if (!(resultItem instanceof NodeInfo)) { throw new XPathException("non-node returned by result-document href: " + hrefValue); } else { target = (NodeInfo) resultItem; targetNode = (com.google.gwt.dom.client.Node) ((HTMLNodeWrapper) target).getUnderlyingNode(); } } else if (command == APIcommand.UPDATE_HTML) { throw new XPathException( "expected '?select=' or '#' at start of result-document href, found: " + hrefValue); } if (targetNode == null) { logger.warning("result-document target not found for href: " + hrefValue + contextNodeName); return null; } else { logger.fine("processing result-document for href: " + hrefValue + contextNodeName); } //checkAcceptableUri(context, absoluteResultURI.toString()); //IFrameElement container = Document.get().createIFrameElement(); Node container = null; if (command == APIcommand.UPDATE_HTML) { container = HTMLDocumentWrapper.createDocumentFragment((Document) controller.getTargetNode()); } else { addResultDocument(context, new DocumentURI(absURI), (Document) targetNode); container = targetNode; } PipelineConfiguration pipe = controller.makePipelineConfiguration(); Receiver out = controller.openResult(pipe, c2, container, action); try { content.process(c2); out.endDocument(); } catch (XPathException err) { err.setXPathContext(context); err.maybeSetLocation(getSourceLocator()); throw err; } controller.closeResult(out, c2); if (command == APIcommand.UPDATE_HTML) { PendingUpdateList list = controller.getPendingUpdateList(); if (action == REPLACE_CONTENT && command == APIcommand.UPDATE_HTML) { int existingChildren = targetNode.getChildCount(); for (int i = 0; i < existingChildren; i++) { Node child = targetNode.getChild(i); list.add(new DeleteAction(child)); } } list.add(new InsertAction(container, targetNode, InsertAction.LAST)); } //controller.setResultTree(absoluteResultURI.toString(), root); return null; }
From source file:com.bfr.client.selection.HtmlBBox.java
License:Apache License
/** * Determine the index of a node within its parent * * @param child A node to determine the index of * @return index of the node, or -1 on failure *//* www . j a v a 2 s . c om*/ public static int getChildIndex(Node child) { int res = -1; Node parent = child.getParentNode(); if (parent != null) { for (int i = 0; i < parent.getChildCount(); i++) { if (child == parent.getChild(i)) { res = i; break; } } } return res; }
From source file:com.bfr.client.selection.impl.RangeImpl.java
License:Apache License
/** * If the found range is not on a text node, this finds the cooresponding * text node to where the selection is. If it is on a text node, just * directly creates the endpoint from it. * * @param node node returned as an endpoint of a range * @param offset offset returned to the endpoint of a range * @return A range end point with a proper (or null) text node *///from ww w .j a v a2 s .c o m private RangeEndPoint findTextPoint(Node node, int offset) { RangeEndPoint res; if (node.getNodeType() == Node.TEXT_NODE) { res = new RangeEndPoint((Text) node, offset); } else { // search backwards unless this is after the last node boolean dir = offset >= node.getChildCount(); Node child = (node.getChildCount() == 0) ? node : node.getChild(dir ? offset - 1 : offset); // Get the previous/next text node Text text = Range.getAdjacentTextElement(child, dir); if (text == null) { // If we didn't find a text node in the preferred direction, // try the other direction dir = !dir; text = Range.getAdjacentTextElement(child, dir); } res = new RangeEndPoint(text, dir); } return res; }
From source file:com.bfr.client.selection.Range.java
License:Apache License
/** * Returns the next adjacent text node in the given direction. Will move * down the hierarchy (if traversingUp is not set), then through siblings, * then up (but not past topMostNode), looking for the first node * <p/>// w w w.j a va 2 s. co m * This could be non-statically included in the Node class * * @param current An element to start the search from, can be any type * of node. * @param topMostNode A node that this will traverse no higher than * @param forward whether to search forward or backward * @param traversingUp if true, will not look at the children of this element * @return the next (previous) text node, or null if no more */ public static Text getAdjacentTextElement(Node current, Node topMostNode, boolean forward, boolean traversingUp) { Text res = null; Node node; // If traversingUp, then the children have already been processed if (!traversingUp) { if (current.getChildCount() > 0) { node = forward ? current.getFirstChild() : current.getLastChild(); if (node.getNodeType() == Node.TEXT_NODE) { res = (Text) node; } else { // Depth first traversal, the recursive call deals with // siblings res = getAdjacentTextElement(node, topMostNode, forward, false); } } } if (res == null) { node = forward ? current.getNextSibling() : current.getPreviousSibling(); // Traverse siblings if (node != null) { if (node.getNodeType() == Node.TEXT_NODE) { res = (Text) node; } else { // Depth first traversal, the recursive call deals with // siblings res = getAdjacentTextElement(node, topMostNode, forward, false); } } } // Go up and over if still not found if ((res == null) && (current != topMostNode)) { node = current.getParentNode(); // Stop at document (technically could stop at "html" tag) if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE)) { res = getAdjacentTextElement(node, topMostNode, forward, true); } } return res; }
From source file:com.dom_distiller.client.ContentExtractor.java
License:Open Source License
/** * Strips all "id" attributes from nodes in the tree rooted at |clonedSubtree| *///w w w .j av a2 s . c om private static void stripIds(Node node) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: Element e = Element.as(node); if (e.hasAttribute("id")) { e.setAttribute("id", ""); } // Intentional fall-through. case Node.DOCUMENT_NODE: for (int i = 0; i < node.getChildCount(); i++) { stripIds(node.getChild(i)); } } }
From source file:com.dom_distiller.client.JavaScript.java
License:Open Source License
private static boolean javaContains(Node l, Node r) { for (int i = 0; i < l.getChildCount(); i++) { Node c = l.getChild(i);//from w w w . jav a 2s . c o m if (c.equals(r)) return true; if (javaContains(c, r)) return true; } return false; }
From source file:com.ephesoft.gxt.core.client.ui.widget.util.HTMLDomUtil.java
License:Open Source License
/** * Gets the <code> grandChildren </code> of a parent which is the nth child of a grandParent, where 'n' is the childNumber. If * child number is less than 1 it returns the grand children of the last child of grandparent. * //from www . j a v a 2 s . c om * @param grandParent {@link Node} Element whose grandChildren needs to be returned. When NULL , null is returned. * @param childNumber int childNumber of the child whose children neeeds to be returned. * @return {@link NodeList} < @Node > which are all the grandChildren. NULL if child doesnot exist or has no children. */ public static NodeList<Node> getGrandChildren(Node grandParent, int childNumber) { NodeList<Node> grandChildren = null; if (grandParent != null) { Node childNode = null; if (childNumber > 0) { childNode = grandParent.getChild(childNumber - 1); } else { int totalChildren = grandParent.getChildCount(); childNode = totalChildren > 0 ? grandParent.getChild(totalChildren - 1) : null; } grandChildren = childNode == null ? null : childNode.getChildNodes(); } return grandChildren; }
From source file:cz.cas.lib.proarc.webapp.client.ClientUtils.java
License:Open Source License
/** * Dumps Element content and traverse its children. * <p/><b>WARNING:</b> it is com.google.gwt.dom.client.Element not com.google.gwt.xml.client.Element!!! * /* ww w . j a v a2s. co m*/ * @param elm an element to dump * @param indent row indentation for current level * @param indentIncrement increment for next level * @param sb dumped content * @return dumped content */ public static StringBuilder dump(Element elm, String indent, String indentIncrement, StringBuilder sb) { int childCount = elm.getChildCount(); String innerText = elm.getInnerText(); String lang = elm.getLang(); String nodeName = elm.getNodeName(); short nodeType = elm.getNodeType(); String getString = elm.getString(); String tagNameWithNS = elm.getTagName(); String xmlLang = elm.getAttribute("xml:lang"); sb.append(ClientUtils.format( "%sElement {nodeName: %s, nodeType: %s, tagNameWithNS: %s, lang: %s," + " childCount: %s, getString: %s, xmlLang: %s}\n", indent, nodeName, nodeType, tagNameWithNS, lang, childCount, getString, xmlLang)); NodeList<Node> childNodes = elm.getChildNodes(); indent += indentIncrement; for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.getItem(i); if (Element.is(child)) { dump(Element.as(child), indent, indentIncrement, sb); } else { sb.append(ClientUtils.format("%sNode: nodeType: %s, nodeName: %s, childCount: %s, nodeValue: %s\n", indent, child.getNodeType(), child.getNodeName(), child.getChildCount(), child.getNodeValue())); } } return sb; }
From source file:de.catma.ui.client.ui.tagger.AffectedNodesFinder.java
License:Open Source License
/** * Recursively walks the tree depth first and creates a list of affected nodes. * @param curNode the (relative) root node to start with *///from www . j a v a 2 s. c om private void walk(Node curNode) { // check if we're still within the affected subtree // and the current node has any taggable content if (!this.outOfAffectedSubtree && ((curNode.getNodeValue() == null) || !curNode.getNodeValue().trim().isEmpty())) { // all text nodes gets added, in case we get into the affected subtree with this // node or one of its children if (curNode.getNodeType() == Node.TEXT_NODE) { affectedNodes.push(curNode); } // we check for children and go down the subtrees if (curNode.hasChildNodes()) { for (int i = 0; i < curNode.getChildCount(); i++) { walk(curNode.getChild(i)); } } // if we reach the outer left node // we're in the affacted subtree -> all parent nodes can stay on the stack else if (curNode.equals(outerLeftNode)) { this.inAffectedSubtree = true; } // if we reach the outer right node // we reject all the rest of the upcoming nodes else if (curNode.equals(outerRightNode)) { this.outOfAffectedSubtree = true; } // if the current node is a text node it has already been pushed onto the stack // and if we're not within the affected subtree, we're removing the current node from the stack // (not being in the affected subtree means neither the current node nor one of its // children is the outer left node) if (!inAffectedSubtree && (curNode.getNodeType() == Node.TEXT_NODE)) { affectedNodes.pop(); } } }
From source file:de.catma.ui.client.ui.tagger.AffectedNodesFinder.java
License:Open Source License
/** * @param parent the parent node /*ww w. j a va2 s . c o m*/ * @param child the child node * @return the position of the child node within the array of children * or -1 if there is no parent child relationship */ public static int indexOf(Node parent, Node child) { for (int i = 0; i < parent.getChildCount(); i++) { if (child.equals(parent.getChild(i))) { return i; } } return -1; }