Package org.dom4j

Examples of org.dom4j.DocumentFactory


    protected DocumentFactory getDocumentFactory() {
        QName qName = getQName();

        // QName might be null as we might not have been constructed yet
        if (qName != null) {
            DocumentFactory factory = qName.getDocumentFactory();

            if (factory != null) {
                return factory;
            }
        }
View Full Code Here


   

    // Implementation methods
    // -------------------------------------------------------------------------
    protected DocumentFactory getDocumentFactory() {
        DocumentFactory factory = getQName().getDocumentFactory();

        return (factory != null) ? factory : DOCUMENT_FACTORY;
    }
View Full Code Here

/*     */   }
/*     */
/*     */   protected Document parseDocument()
/*     */     throws DocumentException, IOException, XmlPullParserException
/*     */   {
/* 362 */     DocumentFactory df = getDocumentFactory();
/* 363 */     Document document = df.createDocument();
/* 364 */     Element parent = null;
/* 365 */     XmlPullParser pp = getXPPParser();
/* 366 */     pp.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true);
/*     */     while (true)
/*     */     {
/* 369 */       int type = pp.nextToken();
/*     */
/* 371 */       switch (type) {
/*     */       case 8:
/* 373 */         String text = pp.getText();
/* 374 */         int loc = text.indexOf(" ");
/*     */
/* 376 */         if (loc >= 0) {
/* 377 */           String target = text.substring(0, loc);
/* 378 */           String txt = text.substring(loc + 1);
/* 379 */           document.addProcessingInstruction(target, txt);
/*     */         } else {
/* 381 */           document.addProcessingInstruction(text, "");
/*     */         }
/*     */
/* 384 */         break;
/*     */       case 9:
/* 388 */         if (parent != null)
/* 389 */           parent.addComment(pp.getText());
/*     */         else {
/* 391 */           document.addComment(pp.getText());
/*     */         }
/*     */
/* 394 */         break;
/*     */       case 5:
/* 398 */         if (parent != null) {
/* 399 */           parent.addCDATA(pp.getText());
/*     */         } else {
/* 401 */           String msg = "Cannot have text content outside of the root document";
/*     */
/* 403 */           throw new DocumentException(msg);
/*     */         }
/*     */
/*     */       case 6:
/* 410 */         break;
/*     */       case 1:
/* 413 */         return document;
/*     */       case 2:
/* 416 */         QName qname = pp.getPrefix() == null ? df.createQName(pp.getName(), pp.getNamespace()) : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace());
/*     */
/* 419 */         Element newElement = df.createElement(qname);
/* 420 */         int nsStart = pp.getNamespaceCount(pp.getDepth() - 1);
/* 421 */         int nsEnd = pp.getNamespaceCount(pp.getDepth());
/*     */
/* 423 */         for (int i = nsStart; i < nsEnd; i++) {
/* 424 */           if (pp.getNamespacePrefix(i) != null) {
/* 425 */             newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i));
/*     */           }
/*     */
/*     */         }
/*     */
/* 430 */         for (int i = 0; i < pp.getAttributeCount(); i++) {
/* 431 */           QName qa = pp.getAttributePrefix(i) == null ? df.createQName(pp.getAttributeName(i)) : df.createQName(pp.getAttributeName(i), pp.getAttributePrefix(i), pp.getAttributeNamespace(i));
/*     */
/* 436 */           newElement.addAttribute(qa, pp.getAttributeValue(i));
/*     */         }
/*     */
/* 439 */         if (parent != null)
View Full Code Here

/* 328 */     return attribute(namespaceURI, localName) != null;
/*     */   }
/*     */
/*     */   protected DocumentFactory getDocumentFactory()
/*     */   {
/* 334 */     DocumentFactory factory = getQName().getDocumentFactory();
/*     */
/* 336 */     return factory != null ? factory : DOCUMENT_FACTORY;
/*     */   }
View Full Code Here

/*      */   public void setAttributes(Attributes attributes, NamespaceStack namespaceStack, boolean noNamespaceAttributes)
/*      */   {
/*  505 */     int size = attributes.getLength();
/*      */
/*  507 */     if (size > 0) {
/*  508 */       DocumentFactory factory = getDocumentFactory();
/*      */
/*  510 */       if (size == 1)
/*      */       {
/*  512 */         String name = attributes.getQName(0);
/*      */
/*  514 */         if ((noNamespaceAttributes) || (!name.startsWith("xmlns"))) {
/*  515 */           String attributeURI = attributes.getURI(0);
/*      */
/*  517 */           String attributeLocalName = attributes.getLocalName(0);
/*      */
/*  519 */           String attributeValue = attributes.getValue(0);
/*      */
/*  521 */           QName attributeQName = namespaceStack.getAttributeQName(attributeURI, attributeLocalName, name);
/*      */
/*  524 */           add(factory.createAttribute(this, attributeQName, attributeValue));
/*      */         }
/*      */       }
/*      */       else {
/*  528 */         List list = attributeList(size);
/*      */
/*  530 */         list.clear();
/*      */
/*  532 */         for (int i = 0; i < size; i++)
/*      */         {
/*  535 */           String attributeName = attributes.getQName(i);
/*      */
/*  537 */           if ((!noNamespaceAttributes) && (attributeName.startsWith("xmlns")))
/*      */             continue;
/*  539 */           String attributeURI = attributes.getURI(i);
/*      */
/*  541 */           String attributeLocalName = attributes.getLocalName(i);
/*      */
/*  543 */           String attributeValue = attributes.getValue(i);
/*      */
/*  545 */           QName attributeQName = namespaceStack.getAttributeQName(attributeURI, attributeLocalName, attributeName);
/*      */
/*  549 */           Attribute attribute = factory.createAttribute(this, attributeQName, attributeValue);
/*      */
/*  552 */           list.add(attribute);
/*      */
/*  554 */           childAdded(attribute);
/*      */         }
View Full Code Here

/*      */
/*  819 */     return this;
/*      */   }
/*      */
/*      */   public Element addElement(String name) {
/*  823 */     DocumentFactory factory = getDocumentFactory();
/*      */
/*  825 */     int index = name.indexOf(":");
/*      */
/*  827 */     String prefix = "";
/*      */
/*  829 */     String localName = name;
/*      */
/*  831 */     Namespace namespace = null;
/*      */
/*  833 */     if (index > 0) {
/*  834 */       prefix = name.substring(0, index);
/*      */
/*  836 */       localName = name.substring(index + 1);
/*      */
/*  838 */       namespace = getNamespaceForPrefix(prefix);
/*      */
/*  840 */       if (namespace == null) {
/*  841 */         throw new IllegalAddException("No such namespace prefix: " + prefix + " is in scope on: " + this + " so cannot add element: " + name);
/*      */       }
/*      */     }
/*      */     else
/*      */     {
/*  846 */       namespace = getNamespaceForPrefix("");
/*      */     }
/*      */     Element node;
/*      */     Element node;
/*  851 */     if (namespace != null) {
/*  852 */       QName qname = factory.createQName(localName, namespace);
/*      */
/*  854 */       node = factory.createElement(qname);
/*      */     } else {
/*  856 */       node = factory.createElement(name);
/*      */     }
/*      */
/*  859 */     addNewNode(node);
/*      */
/*  861 */     return node;
View Full Code Here

/*      */   protected DocumentFactory getDocumentFactory()
/*      */   {
/* 1607 */     QName qName = getQName();
/*      */
/* 1610 */     if (qName != null) {
/* 1611 */       DocumentFactory factory = qName.getDocumentFactory();
/*      */
/* 1613 */       if (factory != null) {
/* 1614 */         return factory;
/*      */       }
/*      */     }
View Full Code Here

/*      */   {
/* 1010 */     this.attributes = attributeList;
/*      */   }
/*      */
/*      */   protected DocumentFactory getDocumentFactory() {
/* 1014 */     DocumentFactory factory = this.qname.getDocumentFactory();
/*      */
/* 1016 */     return factory != null ? factory : DOCUMENT_FACTORY;
/*      */   }
View Full Code Here

/* 61 */       Element element = (Element)iterator.next();
/* 62 */       QName elementQName = getQNameOfSchemaElement(element);
/* 63 */       QName type = (QName)this.typedElementMap.get(element);
/*    */
/* 65 */       if (this.complexTypeMap.containsKey(type)) {
/* 66 */         DocumentFactory factory = (DocumentFactory)this.complexTypeMap.get(type);
/*    */
/* 68 */         elementQName.setDocumentFactory(factory);
/* 69 */       } else if (this.simpleTypeMap.containsKey(type)) {
/* 70 */         XSDatatype datatype = (XSDatatype)this.simpleTypeMap.get(type);
/* 71 */         DocumentFactory factory = (DocumentFactory)this.elementFactoryMap.get(element);
/*    */
/* 74 */         if ((factory instanceof DatatypeElementFactory))
/* 75 */           ((DatatypeElementFactory)factory).setChildElementXSDatatype(elementQName, datatype);
/*    */       }
/*    */     }
View Full Code Here

/*     */
/*     */   public DatatypeElementFactory getElementFactory(QName elementQName)
/*     */   {
/*  97 */     DatatypeElementFactory result = null;
/*     */
/* 103 */     DocumentFactory factory = elementQName.getDocumentFactory();
/* 104 */     if ((factory instanceof DatatypeElementFactory)) {
/* 105 */       result = (DatatypeElementFactory)factory;
/*     */     }
/*     */
/* 108 */     return result;
View Full Code Here

TOP

Related Classes of org.dom4j.DocumentFactory

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.