Java Code Examples for org.w3c.dom.DocumentFragment#appendChild()
The following examples show how to use
org.w3c.dom.DocumentFragment#appendChild() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaxSerializer.java From cxf with Apache License 2.0 | 6 votes |
private Node appendNewChild(XMLStreamReader reader, boolean wrapped, Document contextDocument, XMLStreamWriter writer, Element element) throws XMLStreamException { StaxUtils.copy(reader, writer); DocumentFragment result = contextDocument.createDocumentFragment(); Node child = element.getFirstChild(); if (wrapped) { child = child.getFirstChild(); } if (child != null && child.getNextSibling() == null) { return child; } while (child != null) { Node nextChild = child.getNextSibling(); result.appendChild(child); child = nextChild; } return result; }
Example 2
Source File: DocumentFragmentTest.java From anno4j with Apache License 2.0 | 5 votes |
public void testAddSingleElement() throws Exception { ObjectFactory of = con.getObjectFactory(); Entity entity = con.addDesignation(of.createObject(), Entity.class); Document doc = parse("<element/>"); DocumentFragment frag = doc.createDocumentFragment(); frag.appendChild(doc.getDocumentElement()); entity.setXML(frag); RepositoryResult<Statement> results = con.getStatements(entity.getResource(), pred, null); String xml = results.next().getObject().stringValue(); results.close(); assertEquals("<element/>", xml); }
Example 3
Source File: DocumentFragmentTest.java From anno4j with Apache License 2.0 | 5 votes |
public void testAddNamespaceElement() throws Exception { String xml = "<a:Box xmlns:a=\"http://example.org/a#\" required=\"true\"><a:widget size=\"10\"> </a:widget><a:grommit id=\"23\"> text </a:grommit></a:Box>"; Document doc = parse(xml); ObjectFactory of = con.getObjectFactory(); Entity entity = con.addDesignation(of.createObject(), Entity.class); DocumentFragment frag = doc.createDocumentFragment(); frag.appendChild(doc.getDocumentElement()); entity.setXML(frag); RepositoryResult<Statement> resuts = con.getStatements(entity.getResource(), pred, null); String label = resuts.next().getObject().stringValue(); resuts.close(); assertEquals(xml, label); }
Example 4
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 5 votes |
public DocumentFragment asDocumentFragment() throws OpenRDFException, TransformerException, IOException, ParserConfigurationException { Document doc = asDocument(); DocumentFragment frag = doc.createDocumentFragment(); frag.appendChild(doc.getDocumentElement()); return frag; }
Example 5
Source File: DocumentFragmentTest.java From anno4j with Apache License 2.0 | 5 votes |
public void testReadNamespaceElement() throws Exception { String xml = "<a:Box xmlns:a=\"http://example.org/a#\" required=\"true\"><a:widget size=\"10\"> </a:widget><a:grommit id=\"23\"> text </a:grommit></a:Box>"; Document doc = parse(xml); ObjectFactory of = con.getObjectFactory(); Entity entity = con.addDesignation(of.createObject(), Entity.class); DocumentFragment frag = doc.createDocumentFragment(); frag.appendChild(doc.getDocumentElement()); String before = toString(frag); entity.setXML(frag); entity = (Entity) con.getObject(entity.getResource()); frag = entity.getXML(); assertEquals(before, toString(frag)); }
Example 6
Source File: Extensions.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * This method is an extension that implements as a Xalan extension * the node-set function also found in xt and saxon. * If the argument is a Result Tree Fragment, then <code>nodeset</code> * returns a node-set consisting of a single root node as described in * section 11.1 of the XSLT 1.0 Recommendation. If the argument is a * node-set, <code>nodeset</code> returns a node-set. If the argument * is a string, number, or boolean, then <code>nodeset</code> returns * a node-set consisting of a single root node with a single text node * child that is the result of calling the XPath string() function on the * passed parameter. If the argument is anything else, then a node-set * is returned consisting of a single root node with a single text node * child that is the result of calling the java <code>toString()</code> * method on the passed argument. * Most of the * actual work here is done in <code>MethodResolver</code> and * <code>XRTreeFrag</code>. * @param myProcessor Context passed by the extension processor * @param rtf Argument in the stylesheet to the nodeset extension function * * NEEDSDOC ($objectName$) @return */ public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf) { String textNodeValue; if (rtf instanceof NodeIterator) { return new NodeSet((NodeIterator) rtf); } else { if (rtf instanceof String) { textNodeValue = (String) rtf; } else if (rtf instanceof Boolean) { textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str(); } else if (rtf instanceof Double) { textNodeValue = new XNumber(((Double) rtf).doubleValue()).str(); } else { textNodeValue = rtf.toString(); } // This no longer will work right since the DTM. // Document myDoc = myProcessor.getContextNode().getOwnerDocument(); Document myDoc = JdkXmlUtils.getDOMDocument(); Text textNode = myDoc.createTextNode(textNodeValue); DocumentFragment docFrag = myDoc.createDocumentFragment(); docFrag.appendChild(textNode); return new NodeSet(docFrag); } }
Example 7
Source File: SymbolWriter.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
@Override public Node toNode(AbstractWmlConversionContext context, Object unmarshalledNode, Node modelContent, TransformState state, Document doc) throws TransformerException { R.Sym modelData = (R.Sym)unmarshalledNode; String fontName = modelData.getFont(); String textValue = modelData.getChar(); PhysicalFont pf = context.getWmlPackage().getFontMapper().get(fontName); char chValue = '\0'; Typeface typeface = null; if (pf != null) { typeface = pf.getTypeface(); if (typeface != null) { if (textValue.length() > 1) { try { chValue = (char)Integer.parseInt(textValue, 16); } catch (NumberFormatException nfe) { chValue = '\0'; } } else { chValue = textValue.charAt(0); } if (chValue != '\0') { if (chValue > 0xf000) { //let's check first the character in the lower ascii (Pre-process according to ECMA-376 2.3.3.29) chValue -= 0xf000; } if (typeface.mapChar(chValue) == 0) { chValue += 0xf000; if (typeface.mapChar(chValue) == 0) { chValue = '\0'; } } if (chValue != '\0') {//character was found textValue = Character.toString(chValue); } } } } Text theChar = doc.createTextNode(textValue); DocumentFragment docfrag = doc.createDocumentFragment(); if (pf==null) { log.warn("No physical font present for:" + fontName); docfrag.appendChild( theChar ); } else { Element foInline = doc.createElementNS("http://www.w3.org/1999/XSL/Format", "fo:inline"); docfrag.appendChild(foInline); foInline.setAttribute("font-family", pf.getName() ); foInline.appendChild(theChar); } return docfrag; }
Example 8
Source File: RangeImpl.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are the same. * This method is invoked by the generic <code>traverse</code> * method. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseSameContainer( int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); // If selection is empty, just return the fragment if ( fStartOffset==fEndOffset ) return frag; // Text node needs special case handling if ( fStartContainer.getNodeType()==Node.TEXT_NODE ) { // get the substring String s = fStartContainer.getNodeValue(); String sub = s.substring( fStartOffset, fEndOffset ); // set the original text node to its new value if ( how != CLONE_CONTENTS ) { ((TextImpl)fStartContainer).deleteData(fStartOffset, fEndOffset-fStartOffset) ; // Nothing is partially selected, so collapse to start point collapse( true ); } if ( how==DELETE_CONTENTS) return null; frag.appendChild( fDocument.createTextNode(sub) ); return frag; } // Copy nodes between the start/end offsets. Node n = getSelectedNode( fStartContainer, fStartOffset ); int cnt = fEndOffset - fStartOffset; while( cnt > 0 ) { Node sibling = n.getNextSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.appendChild( xferNode ); --cnt; n = sibling; } // Nothing is partially selected, so collapse to start point if ( how != CLONE_CONTENTS ) collapse( true ); return frag; }
Example 9
Source File: RangeImpl.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not the * same, but the start container is an ancestor of the * end container. This method is invoked by the generic * <code>traverse</code> method. * * @param endAncestor * The ancestor of the end container that is a direct child * of the start container. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonStartContainer( Node endAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseRightBoundary( endAncestor, how ); if ( frag!=null ) frag.appendChild( n ); int endIdx = indexOf( endAncestor, fStartContainer ); int cnt = endIdx - fStartOffset; if ( cnt <=0 ) { // Collapse to just before the endAncestor, which // is partially selected. if ( how != CLONE_CONTENTS ) { setEndBefore( endAncestor ); collapse( false ); } return frag; } n = endAncestor.getPreviousSibling(); while( cnt > 0 ) { Node sibling = n.getPreviousSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.insertBefore( xferNode, frag.getFirstChild() ); --cnt; n = sibling; } // Collapse to just before the endAncestor, which // is partially selected. if ( how != CLONE_CONTENTS ) { setEndBefore( endAncestor ); collapse( false ); } return frag; }
Example 10
Source File: Extensions.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * This method is an extension that implements as a Xalan extension * the node-set function also found in xt and saxon. * If the argument is a Result Tree Fragment, then <code>nodeset</code> * returns a node-set consisting of a single root node as described in * section 11.1 of the XSLT 1.0 Recommendation. If the argument is a * node-set, <code>nodeset</code> returns a node-set. If the argument * is a string, number, or boolean, then <code>nodeset</code> returns * a node-set consisting of a single root node with a single text node * child that is the result of calling the XPath string() function on the * passed parameter. If the argument is anything else, then a node-set * is returned consisting of a single root node with a single text node * child that is the result of calling the java <code>toString()</code> * method on the passed argument. * Most of the * actual work here is done in <code>MethodResolver</code> and * <code>XRTreeFrag</code>. * @param myProcessor Context passed by the extension processor * @param rtf Argument in the stylesheet to the nodeset extension function * * NEEDSDOC ($objectName$) @return */ public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf) { String textNodeValue; if (rtf instanceof NodeIterator) { return new NodeSet((NodeIterator) rtf); } else { if (rtf instanceof String) { textNodeValue = (String) rtf; } else if (rtf instanceof Boolean) { textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str(); } else if (rtf instanceof Double) { textNodeValue = new XNumber(((Double) rtf).doubleValue()).str(); } else { textNodeValue = rtf.toString(); } // This no longer will work right since the DTM. // Document myDoc = myProcessor.getContextNode().getOwnerDocument(); Document myDoc = getDocument(); Text textNode = myDoc.createTextNode(textNodeValue); DocumentFragment docFrag = myDoc.createDocumentFragment(); docFrag.appendChild(textNode); return new NodeSet(docFrag); } }
Example 11
Source File: Extensions.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * This method is an extension that implements as a Xalan extension * the node-set function also found in xt and saxon. * If the argument is a Result Tree Fragment, then <code>nodeset</code> * returns a node-set consisting of a single root node as described in * section 11.1 of the XSLT 1.0 Recommendation. If the argument is a * node-set, <code>nodeset</code> returns a node-set. If the argument * is a string, number, or boolean, then <code>nodeset</code> returns * a node-set consisting of a single root node with a single text node * child that is the result of calling the XPath string() function on the * passed parameter. If the argument is anything else, then a node-set * is returned consisting of a single root node with a single text node * child that is the result of calling the java <code>toString()</code> * method on the passed argument. * Most of the * actual work here is done in <code>MethodResolver</code> and * <code>XRTreeFrag</code>. * @param myProcessor Context passed by the extension processor * @param rtf Argument in the stylesheet to the nodeset extension function * * NEEDSDOC ($objectName$) @return */ public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf) { String textNodeValue; if (rtf instanceof NodeIterator) { return new NodeSet((NodeIterator) rtf); } else { if (rtf instanceof String) { textNodeValue = (String) rtf; } else if (rtf instanceof Boolean) { textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str(); } else if (rtf instanceof Double) { textNodeValue = new XNumber(((Double) rtf).doubleValue()).str(); } else { textNodeValue = rtf.toString(); } // This no longer will work right since the DTM. // Document myDoc = myProcessor.getContextNode().getOwnerDocument(); Document myDoc = JdkXmlUtils.getDOMDocument(); Text textNode = myDoc.createTextNode(textNodeValue); DocumentFragment docFrag = myDoc.createDocumentFragment(); docFrag.appendChild(textNode); return new NodeSet(docFrag); } }
Example 12
Source File: RangeImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not the * same, but the start container is an ancestor of the * end container. This method is invoked by the generic * <code>traverse</code> method. * * @param endAncestor * The ancestor of the end container that is a direct child * of the start container. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonStartContainer( Node endAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseRightBoundary( endAncestor, how ); if ( frag!=null ) frag.appendChild( n ); int endIdx = indexOf( endAncestor, fStartContainer ); int cnt = endIdx - fStartOffset; if ( cnt <=0 ) { // Collapse to just before the endAncestor, which // is partially selected. if ( how != CLONE_CONTENTS ) { setEndBefore( endAncestor ); collapse( false ); } return frag; } n = endAncestor.getPreviousSibling(); while( cnt > 0 ) { Node sibling = n.getPreviousSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.insertBefore( xferNode, frag.getFirstChild() ); --cnt; n = sibling; } // Collapse to just before the endAncestor, which // is partially selected. if ( how != CLONE_CONTENTS ) { setEndBefore( endAncestor ); collapse( false ); } return frag; }
Example 13
Source File: Extensions.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * This method is an extension that implements as a Xalan extension * the node-set function also found in xt and saxon. * If the argument is a Result Tree Fragment, then <code>nodeset</code> * returns a node-set consisting of a single root node as described in * section 11.1 of the XSLT 1.0 Recommendation. If the argument is a * node-set, <code>nodeset</code> returns a node-set. If the argument * is a string, number, or boolean, then <code>nodeset</code> returns * a node-set consisting of a single root node with a single text node * child that is the result of calling the XPath string() function on the * passed parameter. If the argument is anything else, then a node-set * is returned consisting of a single root node with a single text node * child that is the result of calling the java <code>toString()</code> * method on the passed argument. * Most of the * actual work here is done in <code>MethodResolver</code> and * <code>XRTreeFrag</code>. * @param myProcessor Context passed by the extension processor * @param rtf Argument in the stylesheet to the nodeset extension function * * NEEDSDOC ($objectName$) @return */ public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf) { String textNodeValue; if (rtf instanceof NodeIterator) { return new NodeSet((NodeIterator) rtf); } else { if (rtf instanceof String) { textNodeValue = (String) rtf; } else if (rtf instanceof Boolean) { textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str(); } else if (rtf instanceof Double) { textNodeValue = new XNumber(((Double) rtf).doubleValue()).str(); } else { textNodeValue = rtf.toString(); } // This no longer will work right since the DTM. // Document myDoc = myProcessor.getContextNode().getOwnerDocument(); Document myDoc = getDocument(); Text textNode = myDoc.createTextNode(textNodeValue); DocumentFragment docFrag = myDoc.createDocumentFragment(); docFrag.appendChild(textNode); return new NodeSet(docFrag); } }
Example 14
Source File: RangeImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are the same. * This method is invoked by the generic <code>traverse</code> * method. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseSameContainer( int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); // If selection is empty, just return the fragment if ( fStartOffset==fEndOffset ) return frag; // Text node needs special case handling if ( fStartContainer.getNodeType()==Node.TEXT_NODE ) { // get the substring String s = fStartContainer.getNodeValue(); String sub = s.substring( fStartOffset, fEndOffset ); // set the original text node to its new value if ( how != CLONE_CONTENTS ) { ((TextImpl)fStartContainer).deleteData(fStartOffset, fEndOffset-fStartOffset) ; // Nothing is partially selected, so collapse to start point collapse( true ); } if ( how==DELETE_CONTENTS) return null; frag.appendChild( fDocument.createTextNode(sub) ); return frag; } // Copy nodes between the start/end offsets. Node n = getSelectedNode( fStartContainer, fStartOffset ); int cnt = fEndOffset - fStartOffset; while( cnt > 0 ) { Node sibling = n.getNextSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.appendChild( xferNode ); --cnt; n = sibling; } // Nothing is partially selected, so collapse to start point if ( how != CLONE_CONTENTS ) collapse( true ); return frag; }
Example 15
Source File: RangeImpl.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not the * same, but the end container is an ancestor of the * start container. This method is invoked by the generic * <code>traverse</code> method. * * @param startAncestor * The ancestor of the start container that is a direct * child of the end container. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonEndContainer( Node startAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseLeftBoundary( startAncestor, how ); if ( frag!=null ) frag.appendChild( n ); int startIdx = indexOf( startAncestor, fEndContainer ); ++startIdx; // Because we already traversed it.... int cnt = fEndOffset - startIdx; n = startAncestor.getNextSibling(); while( cnt > 0 ) { Node sibling = n.getNextSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.appendChild( xferNode ); --cnt; n = sibling; } if ( how != CLONE_CONTENTS ) { setStartAfter( startAncestor ); collapse( true ); } return frag; }
Example 16
Source File: RangeImpl.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not the * same, but the end container is an ancestor of the * start container. This method is invoked by the generic * <code>traverse</code> method. * * @param startAncestor * The ancestor of the start container that is a direct * child of the end container. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonEndContainer( Node startAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseLeftBoundary( startAncestor, how ); if ( frag!=null ) frag.appendChild( n ); int startIdx = indexOf( startAncestor, fEndContainer ); ++startIdx; // Because we already traversed it.... int cnt = fEndOffset - startIdx; n = startAncestor.getNextSibling(); while( cnt > 0 ) { Node sibling = n.getNextSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.appendChild( xferNode ); --cnt; n = sibling; } if ( how != CLONE_CONTENTS ) { setStartAfter( startAncestor ); collapse( true ); } return frag; }
Example 17
Source File: RangeImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not the * same, but the end container is an ancestor of the * start container. This method is invoked by the generic * <code>traverse</code> method. * * @param startAncestor * The ancestor of the start container that is a direct * child of the end container. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonEndContainer( Node startAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseLeftBoundary( startAncestor, how ); if ( frag!=null ) frag.appendChild( n ); int startIdx = indexOf( startAncestor, fEndContainer ); ++startIdx; // Because we already traversed it.... int cnt = fEndOffset - startIdx; n = startAncestor.getNextSibling(); while( cnt > 0 ) { Node sibling = n.getNextSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.appendChild( xferNode ); --cnt; n = sibling; } if ( how != CLONE_CONTENTS ) { setStartAfter( startAncestor ); collapse( true ); } return frag; }
Example 18
Source File: RangeImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not the * same, but the end container is an ancestor of the * start container. This method is invoked by the generic * <code>traverse</code> method. * * @param startAncestor * The ancestor of the start container that is a direct * child of the end container. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonEndContainer( Node startAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseLeftBoundary( startAncestor, how ); if ( frag!=null ) frag.appendChild( n ); int startIdx = indexOf( startAncestor, fEndContainer ); ++startIdx; // Because we already traversed it.... int cnt = fEndOffset - startIdx; n = startAncestor.getNextSibling(); while( cnt > 0 ) { Node sibling = n.getNextSibling(); Node xferNode = traverseFullySelected( n, how ); if ( frag!=null ) frag.appendChild( xferNode ); --cnt; n = sibling; } if ( how != CLONE_CONTENTS ) { setStartAfter( startAncestor ); collapse( true ); } return frag; }
Example 19
Source File: RangeImpl.java From TencentKona-8 with GNU General Public License v2.0 | 2 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not * the same, and we also know that neither the start * nor end container is an ancestor of the other. * This method is invoked by * the generic <code>traverse</code> method. * * @param startAncestor * Given a common ancestor of the start and end containers, * this parameter is the ancestor (or self) of the start * container that is a direct child of the common ancestor. * * @param endAncestor * Given a common ancestor of the start and end containers, * this parameter is the ancestor (or self) of the end * container that is a direct child of the common ancestor. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonAncestors( Node startAncestor, Node endAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseLeftBoundary( startAncestor, how ); if ( frag!=null ) frag.appendChild( n ); Node commonParent = startAncestor.getParentNode(); int startOffset = indexOf( startAncestor, commonParent ); int endOffset = indexOf( endAncestor, commonParent ); ++startOffset; int cnt = endOffset - startOffset; Node sibling = startAncestor.getNextSibling(); while( cnt > 0 ) { Node nextSibling = sibling.getNextSibling(); n = traverseFullySelected( sibling, how ); if ( frag!=null ) frag.appendChild( n ); sibling = nextSibling; --cnt; } n = traverseRightBoundary( endAncestor, how ); if ( frag!=null ) frag.appendChild( n ); if ( how != CLONE_CONTENTS ) { setStartAfter( startAncestor ); collapse( true ); } return frag; }
Example 20
Source File: RangeImpl.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * Visits the nodes selected by this range when we know * a-priori that the start and end containers are not * the same, and we also know that neither the start * nor end container is an ancestor of the other. * This method is invoked by * the generic <code>traverse</code> method. * * @param startAncestor * Given a common ancestor of the start and end containers, * this parameter is the ancestor (or self) of the start * container that is a direct child of the common ancestor. * * @param endAncestor * Given a common ancestor of the start and end containers, * this parameter is the ancestor (or self) of the end * container that is a direct child of the common ancestor. * * @param how Specifies what type of traversal is being * requested (extract, clone, or delete). * Legal values for this argument are: * * <ol> * <li><code>EXTRACT_CONTENTS</code> - will produce * a document fragment containing the range's content. * Partially selected nodes are copied, but fully * selected nodes are moved. * * <li><code>CLONE_CONTENTS</code> - will leave the * context tree of the range undisturbed, but sill * produced cloned content in a document fragment * * <li><code>DELETE_CONTENTS</code> - will delete from * the context tree of the range, all fully selected * nodes. * </ol> * * @return Returns a document fragment containing any * copied or extracted nodes. If the <code>how</code> * parameter was <code>DELETE_CONTENTS</code>, the * return value is null. */ private DocumentFragment traverseCommonAncestors( Node startAncestor, Node endAncestor, int how ) { DocumentFragment frag = null; if ( how!=DELETE_CONTENTS) frag = fDocument.createDocumentFragment(); Node n = traverseLeftBoundary( startAncestor, how ); if ( frag!=null ) frag.appendChild( n ); Node commonParent = startAncestor.getParentNode(); int startOffset = indexOf( startAncestor, commonParent ); int endOffset = indexOf( endAncestor, commonParent ); ++startOffset; int cnt = endOffset - startOffset; Node sibling = startAncestor.getNextSibling(); while( cnt > 0 ) { Node nextSibling = sibling.getNextSibling(); n = traverseFullySelected( sibling, how ); if ( frag!=null ) frag.appendChild( n ); sibling = nextSibling; --cnt; } n = traverseRightBoundary( endAncestor, how ); if ( frag!=null ) frag.appendChild( n ); if ( how != CLONE_CONTENTS ) { setStartAfter( startAncestor ); collapse( true ); } return frag; }