List of usage examples for com.google.gwt.dom.client Node DOCUMENT_NODE
short DOCUMENT_NODE
To view the source code for com.google.gwt.dom.client Node DOCUMENT_NODE.
Click Source Link
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./*w ww.j a 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.HTMLWriter.java
License:Mozilla Public License
public void setNode(Node node) { if (node == null) { return;//from w w w . j av a 2 s . c o m } currentNode = node; if (node.getNodeType() == Node.DOCUMENT_NODE) { document = (Document) node; } else { document = currentNode.getOwnerDocument(); } if (mode == WriteMode.NONE) { Controller.APIcommand cmd = pipe.getController().getApiCommand(); mode = (cmd == APIcommand.TRANSFORM_TO_DOCUMENT || cmd == APIcommand.TRANSFORM_TO_FRAGMENT) ? WriteMode.XML : WriteMode.HTML; } }
From source file:client.net.sf.saxon.ce.Xslt20ProcessorImpl.java
License:Mozilla Public License
public Node renderXML(JavaScriptObject inSourceDoc, DocumentInfo styleDoc, com.google.gwt.dom.client.Node target) { try {/*from w w w. jav a 2 s . co m*/ if (styleDoc == null) { throw new Exception("Stylesheet for transform is null"); } docFetchRequired = inSourceDoc != null; CompilerInfo info = config.getDefaultXsltCompilerInfo(); info.setErrorListener(new StandardErrorListener()); String asyncSourceURI = null; // for now - don't use aync when using the JavaScript API calls that return a result if (docFetchRequired && (localController.getApiCommand() == APIcommand.UPDATE_HTML || (successCallback != null))) { asyncSourceURI = SaxonceApi.getAsyncUri(inSourceDoc); if (asyncSourceURI != null && asyncSourceURI.toLowerCase().startsWith("file:")) { asyncSourceURI = null; // force synchronous fetch if using file-system protocol } } // ----------- Start async code ------------- fetchedSourceDoc = null; transformInvoked = false; if (asyncSourceURI != null) { final String URI = asyncSourceURI; final Node transformTarget = target; logger.log(Level.FINE, "Aynchronous GET for: " + asyncSourceURI); final HTTPHandler hr = new HTTPHandler(); hr.doGet(asyncSourceURI, new RequestCallback() { public void onError(Request request, Throwable exception) { //hr.setErrorMessage(exception.getMessage()); String msg = "HTTP Error " + exception.getMessage() + " for URI " + URI; handleException(new RuntimeException(msg), "onError"); } public void onResponseReceived(Request request, Response response) { int statusCode = response.getStatusCode(); if (statusCode == 200) { Logger.getLogger("ResponseReceived").fine("GET Ok for: " + URI); Node responseNode; try { responseNode = (Node) XMLDOM.parseXML(response.getText()); } catch (Exception e) { handleException(new RuntimeException(e.getMessage()), "onResponseReceived"); return; } DocumentInfo responseDoc = config.wrapXMLDocument(responseNode, URI); // now document is here, we can transform it Node result = invokeTransform(responseDoc, transformTarget); hr.setResultNode(result); // TODO: This isn't used yet // handle OK response from the server } else if (statusCode < 400) { // transient } else { String msg = "HTTP Error " + statusCode + " " + response.getStatusText() + " for URI " + URI; handleException(new RuntimeException(msg), "onResponseReceived"); //hr.setErrorMessage(statusCode + " " + response.getStatusText()); } } // ends inner method }// ends inner class ); // ends doGet method call } // -------------- End async code /// we can compile - even while sourcedoc is being fetched asynchronously if (stylesheet == null) { if (LogConfiguration.loggingIsEnabled()) { LogController.InitializeTraceListener(); } logger.log(Level.FINE, "Compiling Stylesheet..."); PreparedStylesheet sheet = new PreparedStylesheet(config, info); sheet.prepare(styleDoc); stylesheet = sheet; logger.log(Level.FINE, "Stylesheet compiled OK"); } // for async operation - this is called within the callback - so don't call here if (asyncSourceURI == null && inSourceDoc != null) { int nodeType = (Node.is(inSourceDoc)) ? ((Node) inSourceDoc).getNodeType() : 0; if (nodeType > 0 && nodeType != Node.DOCUMENT_NODE) { // add a document node wrapper Node sourceNode = (Node) inSourceDoc; Document sourceDoc = sourceNode.getOwnerDocument(); HTMLDocumentWrapper htmlDoc = new HTMLDocumentWrapper(sourceDoc, sourceDoc.getURL(), config, DocType.UNKNOWN); fetchedSourceDoc = htmlDoc.wrap(sourceNode); } else { fetchedSourceDoc = SaxonceApi.getDocSynchronously(inSourceDoc, config); } } // this method only runs if transformInvoked == false - need to get sourceDoc reference if not invoked return invokeTransform(fetchedSourceDoc, target); //method ends - allowing onResponceReceived handler to call invokeTransform for async operation } catch (Exception e) { handleException(e, "renderXML"); return null; } }
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/>/*ww w . j a v a 2s.com*/ * 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.cgxlib.xq.client.impl.SelectorEngine.java
License:Apache License
public static NodeList<Element> veryQuickId(String id, Node ctx) { Document d = ctx.getNodeType() == Node.DOCUMENT_NODE ? ctx.<Document>cast() : ctx.getOwnerDocument(); return JsNodeArray.create(d.getElementById(id)); }
From source file:com.cgxlib.xq.client.js.JsUtils.java
License:Apache License
/** * Returns the owner document element of an element. *///from w w w. j a v a 2 s .c om public static Document getOwnerDocument(Node n) { return n == null || !isElement(n) ? null : n.getNodeType() == Node.DOCUMENT_NODE ? n.<Document>cast() : n.getOwnerDocument(); }
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| *///from w w w .j a v a 2 s. com 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.DomToSaxVisitor.java
License:Open Source License
@Override public boolean visit(Node n) { switch (n.getNodeType()) { case Node.TEXT_NODE: handler.textNode(Text.as(n)); return false; case Node.ELEMENT_NODE: Element e = Element.as(n); handler.startElement(e);/* w w w .ja va2 s. c om*/ return true; case Node.DOCUMENT_NODE: // Don't recurse into sub-documents. default: // This case is for comment nodes. return false; } }
From source file:com.dom_distiller.client.NodeListExpander.java
License:Open Source License
private static Node getTopNode(Node n) { for (Node next = n.getParentNode(); next != null && next.getNodeType() != Node.DOCUMENT_NODE; n = next, next = n.getParentNode()) { }/* w w w .j a v a2s. co m*/ return n; }
From source file:org.chromium.distiller.DomUtil.java
License:Open Source License
/** * Get a list of relevant nodes from a subtree. * @param root The root of the subtree.// w w w. j a v a 2 s . c o m * @return A list of relevant nodes. */ public static List<Node> getOutputNodes(Node root) { final List<Node> nodes = new ArrayList<>(); new DomWalker(new DomWalker.Visitor() { @Override public boolean visit(Node n) { switch (n.getNodeType()) { case Node.TEXT_NODE: nodes.add(n); return false; case Node.ELEMENT_NODE: if (!DomUtil.isVisible(Element.as(n))) return false; nodes.add(n); return true; case Node.DOCUMENT_NODE: default: return false; } } @Override public void exit(Node n) { } @Override public void skip(Element e) { } }).walk(root); return nodes; }