Package org.w3c.dom

Examples of org.w3c.dom.DocumentFragment


    public Object unmarshal(Object obj, IUnmarshallingContext ictx)
        throws JiBXException {
       
        // verify the entry conditions
        boolean created = false;
        DocumentFragment frag = null;
        if (obj == null) {
            frag = m_document.createDocumentFragment();
            created = true;
        } else if (obj instanceof DocumentFragment) {
            frag = (DocumentFragment)obj;
        } else {
            throw new JiBXException
                ("Supplied object is not an org.w3c.dom.DocumentFragment");
        }
        if (!(ictx instanceof UnmarshallingContext)) {
            throw new JiBXException
                ("Unmarshalling context not of expected type");
        }
       
        // unmarshal content to document model
        m_unmarshalContext = (UnmarshallingContext)ictx;
        try {
            Node node;
            while ((node = unmarshalNode()) != null) {
                frag.appendChild(node);
            }
            if (created && !frag.hasChildNodes()) {
                return null;
            } else {
                return frag;
            }
    } catch (IOException e) {
View Full Code Here


        if (logger.isLoggable(java.util.logging.Level.FINE))                                     logger.log(java.util.logging.Level.FINE, "Decrypted octets:\n" + octets);

        Node sourceParent =  element.getParentNode();

        DocumentFragment decryptedFragment =
      _serializer.deserialize(octets, sourceParent);


    // The de-serialiser returns a fragment whose children we need to
    // take on.
View Full Code Here

         * @return
         * @throws XMLEncryptionException
         *
         */
        DocumentFragment deserialize(String source, Node ctx) throws XMLEncryptionException {
      DocumentFragment result;
            final String tagname = "fragment";

      // Create the context to parse the document against
      StringBuffer sb;
     
      sb = new StringBuffer();
      sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><"+tagname);
     
      // Run through each node up to the document node and find any
      // xmlns: nodes

      Node wk = ctx;
     
      while (wk != null) {

        NamedNodeMap atts = wk.getAttributes();
        int length;
        if (atts != null)
          length = atts.getLength();
        else
          length = 0;

        for (int i = 0 ; i < length ; ++i) {
          Node att = atts.item(i);
          if (att.getNodeName().startsWith("xmlns:") ||
            att.getNodeName().equals("xmlns")) {
         
            // Check to see if this node has already been found
            Node p = ctx;
            boolean found = false;
            while (p != wk) {
              NamedNodeMap tstAtts = p.getAttributes();
              if (tstAtts != null &&
                tstAtts.getNamedItem(att.getNodeName()) != null) {
                found = true;
                break;
              }
              p = p.getParentNode();
            }
            if (found == false) {
             
              // This is an attribute node
              sb.append(" " + att.getNodeName() + "=\"" +
                    att.getNodeValue() + "\"");
            }
          }
        }
        wk = wk.getParentNode();
      }
      sb.append(">" + source + "</" + tagname + ">");
      String fragment = sb.toString();

            try {
                DocumentBuilderFactory dbf =
                    DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document d = db.parse(
            new InputSource(new StringReader(fragment)));

        Element fragElt = (Element) _contextDocument.importNode(
             d.getDocumentElement(), true);
        result = _contextDocument.createDocumentFragment();
        Node child = fragElt.getFirstChild();
        while (child != null) {
          fragElt.removeChild(child);
          result.appendChild(child);
          child = fragElt.getFirstChild();
        }
        // String outp = serialize(d);

            } catch (SAXException se) {
View Full Code Here

   *
   * @return the objec as a result tree fragment.
   */
  public DocumentFragment rtree(XPathContext support)
  {
    DocumentFragment docFrag = null;
    int result = rtf();

    if (DTM.NULL == result)
    {
      DTM frag = support.createDocumentFragment();
View Full Code Here

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document myDoc = db.newDocument();
       
        Text textNode = myDoc.createTextNode(textNodeValue);
        DocumentFragment docFrag = myDoc.createDocumentFragment();
 
        docFrag.appendChild(textNode);
 
        return new NodeSet(docFrag);
      }
      catch(ParserConfigurationException pce)
      {
View Full Code Here

    }

    // [WSTX-259]
    public void testEmptyFragment() throws Exception
    {
        DocumentFragment fragment = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument().createDocumentFragment();
   
        XMLStreamReader sr = XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(fragment));
        assertTokenType(START_DOCUMENT, sr.getEventType());
        assertTokenType(END_DOCUMENT, sr.next());
        assertFalse(sr.hasNext());
View Full Code Here

public class TestFragments extends BaseStax2Test
{
    // [WSTX-257]
    public void testFragmentIssue257() throws Exception
    {
        DocumentFragment fragment = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument().createDocumentFragment();
        XMLStreamWriter xmlWriter = getOutputFactory().createXMLStreamWriter(new DOMResult(fragment));
        // create equivalent of "<a>value1</a><b>value2</b>"
        xmlWriter.writeStartElement("a");
        xmlWriter.writeCharacters("value1");
        xmlWriter.writeEndElement();
View Full Code Here

             throw new RangeExceptionImpl(
        RangeException.BAD_BOUNDARYPOINTS_ERR,
                DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "BAD_BOUNDARYPOINTS_ERR", null));
        }

      DocumentFragment frag = extractContents();
      insertNode(newParent);
      newParent.appendChild(frag);
      selectNode(newParent);
    }
View Full Code Here

     *         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
View Full Code Here

     *         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.
View Full Code Here

TOP

Related Classes of org.w3c.dom.DocumentFragment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.