Package org.apache.xmlbeans

Examples of org.apache.xmlbeans.XmlCursor$TokenType


    static ApplicationClientDocument convertToApplicationClientSchema(XmlObject xmlObject) throws XmlException {
        if (ApplicationClientDocument.type.equals(xmlObject.schemaType())) {
            XmlBeansUtil.validateDD(xmlObject);
            return (ApplicationClientDocument) xmlObject;
        }
        XmlCursor cursor = xmlObject.newCursor();
        XmlCursor moveable = xmlObject.newCursor();
        String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/application-client_5.xsd";
        String version = "5";
        try {
            cursor.toStartDoc();
            cursor.toFirstChild();
            if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
                SchemaConversionUtils.convertSchemaVersion(cursor, SchemaConversionUtils.JAVAEE_NAMESPACE, schemaLocationURL, version);
                XmlObject result = xmlObject.changeType(ApplicationClientDocument.type);
                XmlBeansUtil.validateDD(result);
                return (ApplicationClientDocument) result;
            }
           
            // otherwise assume DTD
            SchemaConversionUtils.convertToSchema(cursor, SchemaConversionUtils.JAVAEE_NAMESPACE, schemaLocationURL, version);
            cursor.toStartDoc();
            cursor.toChild(SchemaConversionUtils.JAVAEE_NAMESPACE, "application-client");
            cursor.toFirstChild();
            SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.JAVAEE_NAMESPACE, cursor, moveable);
        } finally {
            cursor.dispose();
            moveable.dispose();
        }
        XmlObject result = xmlObject.changeType(ApplicationClientDocument.type);
        if (result != null) {
            XmlBeansUtil.validateDD(result);
            return (ApplicationClientDocument) result;
View Full Code Here


        }
        try {
            filter(sourceFile, filteredPlanFile);

            XmlObject doc = XmlObject.Factory.parse(filteredPlanFile);
            XmlCursor xmlCursor = doc.newCursor();
            LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> dependencies = toKernelDependencies(this.dependencies, useMavenDependencies);
            Artifact configId = new Artifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "car");

            try {
                mergeEnvironment(xmlCursor, configId, dependencies);

                if (targetDir.exists()) {
                    if (!targetDir.isDirectory()) {
                        throw new RuntimeException("TargetDir: " + this.targetDir + " exists and is not a directory");
                    }
                } else {
                    targetDir.mkdirs();
                }

                XmlOptions xmlOptions = new XmlOptions();
                xmlOptions.setSavePrettyPrint();
                doc.save(targetFile, xmlOptions);

                if (getLog() != null) {
                    getLog().info("Generated: " + targetFile);
                }
            }
            finally {
                xmlCursor.dispose();
            }
        } catch (Exception e) {
            throw new MojoExecutionException("Could not process plan", e);
        }
    }
View Full Code Here

        EnvironmentBuilder.mergeEnvironments(oldEnvironment, newEnvironment);
        EnvironmentType environmentType = EnvironmentBuilder.buildEnvironmentType(oldEnvironment);

        xmlCursor.beginElement(ENVIRONMENT_QNAME);
        XmlCursor element = environmentType.newCursor();

        try {
            element.copyXmlContents(xmlCursor);
        }
        finally {
            element.dispose();
        }
    }
View Full Code Here

        }
    }

    private void convertElement(final XmlCursor cursor, final String namespace) {
        cursor.push();
        XmlCursor end = cursor.newCursor();

        try {
            end.toCursor(cursor);
            end.toEndToken();

            while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
                if (cursor.isStart()) {
                    if (!namespace.equals(cursor.getName().getNamespaceURI())) {
                        cursor.setName(new QName(namespace, cursor.getName().getLocalPart()));
                    }
                }

                cursor.toNextToken();
            }

            cursor.pop();
        }
        finally {
            end.dispose();
        }
    }
View Full Code Here

 
  public XWPFHeader(XWPFDocument doc, CTHdrFtr hdrFtr) throws IOException {
    super(doc, hdrFtr);
    paragraphs = new ArrayList<XWPFParagraph>();
    tables = new ArrayList<XWPFTable>();
    XmlCursor cursor = headerFooter.newCursor();
    cursor.selectPath("./*");
    while (cursor.toNextSelection()) {
      XmlObject o = cursor.getObject();
      if (o instanceof CTP) {
        XWPFParagraph p = new XWPFParagraph((CTP) o, this);
        paragraphs.add(p);
      }
      if (o instanceof CTTbl) {
        XWPFTable t = new XWPFTable((CTTbl) o, this);
        tables.add(t);
      }
    }
        cursor.dispose();
    getAllPictures();
  }
View Full Code Here

     * @param xs    the string to check
     */
    protected static void preserveSpaces(STXstring xs) {
        String text = xs.getStringValue();
        if (text != null && (text.startsWith(" ") || text.endsWith(" "))) {
            XmlCursor c = xs.newCursor();
            c.toNextToken();
            c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve");
            c.dispose();
        }
    }
View Full Code Here

        is = getPackagePart().getInputStream();
        hdrDocument = HdrDocument.Factory.parse(is);
        headerFooter = hdrDocument.getHdr();
            // parse the document with cursor and add
            // the XmlObject to its lists
        XmlCursor cursor = headerFooter.newCursor();
            cursor.selectPath("./*");
            while (cursor.toNextSelection()) {
                XmlObject o = cursor.getObject();
                if (o instanceof CTP) {
                  XWPFParagraph p = new XWPFParagraph((CTP)o, this);
                  paragraphs.add(p);
                  bodyElements.add(p);
                }
                if (o instanceof CTTbl) {
                  XWPFTable t = new XWPFTable((CTTbl)o, this);
                  tables.add(t);
                  bodyElements.add(t);
                }
            }
                cursor.dispose();
            getAllPictures();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (XmlException e) {
View Full Code Here

     * @param xs    the string to check
     */
    static void preserveSpaces(XmlString xs) {
        String text = xs.getStringValue();
        if (text != null && (text.startsWith(" ") || text.endsWith(" "))) {
            XmlCursor c = xs.newCursor();
            c.toNextToken();
            c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve");
            c.dispose();
        }
    }
View Full Code Here

    public String toString() {
       StringBuffer text = new StringBuffer();
      
       // Grab the text and tabs of the text run
       // Do so in a way that preserves the ordering
       XmlCursor c = run.newCursor();
       c.selectPath("./*");
       while (c.toNextSelection()) {
           XmlObject o = c.getObject();
           if (o instanceof CTText) {
               String tagName = o.getDomNode().getNodeName();
               // Field Codes (w:instrText, defined in spec sec. 17.16.23)
               //  come up as instances of CTText, but we don't want them
               //  in the normal text output
               if (!"w:instrText".equals(tagName)) {
                  text.append(((CTText) o).getStringValue());
               }
           }
           if (o instanceof CTPTab) {
               text.append("\t");
           }
           if (o instanceof CTEmpty) {
              // Some inline text elements get returned not as
              //  themselves, but as CTEmpty, owing to some odd
              //  definitions around line 5642 of the XSDs
              String tagName = o.getDomNode().getNodeName();
              if ("w:tab".equals(tagName)) {
                 text.append("\t");
              }
              if ("w:br".equals(tagName)) {
                 text.append("\n");
              }
              if ("w:cr".equals(tagName)) {
                 text.append("\n");
              }
           }
       }

       c.dispose();
      
       // Any picture text?
       if(pictureText != null && pictureText.length() > 0) {
          text.append("\n").append(pictureText);
       }
View Full Code Here

                    }
                }
            }
        }
        // Copy the content into the XmlAttributeType
        XmlCursor loginCursor = lcDoc.newCursor();
        loginCursor.toFirstContentToken();
        XmlCursor destination = config.newCursor();
        destination.toNextToken();
        loginCursor.moveXml(destination);
        loginCursor.dispose();
        destination.dispose();
        config.setName("LoginModuleConfiguration");
        root.setServiceArray(new AbstractServiceType[]{realm});


        //Above code inserts gbean using xsi:type=dep:GBeanType.  We also need to account for the substitution group
        //by changing the qname:
        XmlCursor gbeanCursor = root.newCursor();
        try {
            if (!gbeanCursor.toChild(ServiceDocument.type.getDocumentElementName())) {
                throw new RuntimeException("Could not find service element");
            }
            gbeanCursor.setName(GBEAN_QNAME);
        } finally {
            gbeanCursor.dispose();
        }

        return doc;
    }
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.XmlCursor$TokenType

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.