Package org.apache.xmlbeans

Examples of org.apache.xmlbeans.XmlCursor


   
  }
 
  private SubHandling getSubHandling(ExtensibleType actions)
  {
    XmlCursor cursor = actions.newCursor();
    cursor.toChild(PRES_RULES, "sub-handling");
    SubHandlingDocument.SubHandling subHandling = (SubHandlingDocument.SubHandling) cursor.getObject();
   
    if (subHandling.enumValue().equals(SubHandlingDocument.SubHandling.ALLOW))
      return SubHandling.ALLOW;
    else if (subHandling.enumValue().equals(SubHandlingDocument.SubHandling.CONFIRM))
      return SubHandling.CONFIRM;
View Full Code Here


 
  private boolean matchOma(ConditionsType conditions, String subscriberAor)
  {
    try
    {
      XmlCursor cursor = conditions.newCursor();
      cursor.push();
      if (cursor.toChild(OMA_COMMON_POLICY, "external-list"))
      {
        ExternalList list = (ExternalList) cursor.getObject();
        for (int i = 0; i < list.getEntryArray().length; i++)
        {
          String anchor = list.getEntryArray(i).getAnc();
          if (match(anchor, subscriberAor))
            return true;
        }
      }
      cursor.pop();
      if (cursor.toChild(OMA_COMMON_POLICY, "anonymous-request"))
      {
        return subscriberAor.equals("sip:anonymous@anonymous.invalid");
        // TODO add better support to anonymous-request
      }
     
View Full Code Here

  }
 
 
  private boolean matchOmaOtherIdentity(ConditionsType conditions)
  {
    XmlCursor cursor = conditions.newCursor();
    return cursor.toChild(OMA_COMMON_POLICY, "other-identity");
  }
View Full Code Here

      if (_states.size() == 0)
        return null;
      if (_states.size() == 1)
        return _states.get(0);
     
      XmlCursor cursor = null;
      String contentType = null;
      Map<String, String> namespaces = new HashMap<String, String>();
      for (State state : _states)
      {
        XmlObject o = (XmlObject) state.getContent();
        if (cursor == null)
        {
          cursor = o.copy().newCursor();
          cursor.push();
          cursor.toFirstChild();
          cursor.toEndToken();
          contentType = state.getContentType();
        }
        else
        {
          XmlCursor cursor2 = o.newCursor();
          cursor2.toFirstChild(); // Presence
          cursor2.toFirstChild(); // tuple
          cursor2.getAllNamespaces(namespaces);
          do
          {
            add(cursor2, cursor);
          }
          while (cursor2.toNextSibling());
          cursor2.dispose();
        }
      }
      cursor.toParent();
      cursor.toLastAttribute();
      for (String name : namespaces.keySet())
View Full Code Here

    protected WebAppDocument convertToServletSchema(XmlObject xmlObject) throws XmlException {

        String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
        String version = "2.5";
        XmlCursor cursor = xmlObject.newCursor();
        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(WebAppDocument.type);
                XmlBeansUtil.validateDD(result);
                return (WebAppDocument) result;
            }

            if ("http://java.sun.com/xml/ns/javaee".equals(cursor.getName().getNamespaceURI())) {
                SchemaConversionUtils.convertSchemaVersion(cursor, SchemaConversionUtils.JAVAEE_NAMESPACE, schemaLocationURL, version);
                XmlObject result = xmlObject.changeType(WebAppDocument.type);
                XmlBeansUtil.validateDD(result);
                return (WebAppDocument) result;
            }

            //otherwise assume DTD
            XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
            String publicId = xmlDocumentProperties.getDoctypePublicId();
            boolean is22 = "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN".equals(publicId);
            if ("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN".equals(publicId) ||
                    is22) {
                XmlCursor moveable = xmlObject.newCursor();
                try {
                    moveable.toStartDoc();
                    moveable.toFirstChild();

                    SchemaConversionUtils.convertToSchema(cursor, SchemaConversionUtils.JAVAEE_NAMESPACE, schemaLocationURL, version);
                    cursor.toStartDoc();
                    cursor.toChild(SchemaConversionUtils.JAVAEE_NAMESPACE, "web-app");
                    cursor.toFirstChild();
                    SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.JAVAEE_NAMESPACE, cursor, moveable);
                    SchemaConversionUtils.convertToJNDIEnvironmentRefsGroup(SchemaConversionUtils.JAVAEE_NAMESPACE, cursor, moveable);
                    cursor.push();
                    if (cursor.toNextSibling(TAGLIB)) {
                        cursor.toPrevSibling();
                        moveable.toCursor(cursor);
                        cursor.beginElement("jsp-config", SchemaConversionUtils.JAVAEE_NAMESPACE);
                        while (moveable.toNextSibling(TAGLIB)) {
                            moveable.moveXml(cursor);
                        }
                    }
                    cursor.pop();
                    do {
                        String name = cursor.getName().getLocalPart();
                        if ("filter".equals(name) || "servlet".equals(name) || "context-param".equals(name)) {
                            cursor.push();
                            cursor.toFirstChild();
                            SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.JAVAEE_NAMESPACE, cursor, moveable);
                            while (cursor.toNextSibling(SchemaConversionUtils.JAVAEE_NAMESPACE, "init-param")) {
                                cursor.push();
                                cursor.toFirstChild();
                                SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.JAVAEE_NAMESPACE, cursor, moveable);
                                cursor.pop();
                            }
                            cursor.pop();
                            cursor.push();
                            if (cursor.toChild(SchemaConversionUtils.JAVAEE_NAMESPACE, "jsp-file")) {
                                String jspFile = cursor.getTextValue();
                                if (!jspFile.startsWith("/")){
                                    if (is22) {
                                        cursor.setTextValue("/" + jspFile);
                                    } else {
                                        throw new XmlException("jsp-file does not start with / and this is not a 2.2 web app: " + jspFile);
                                    }
                                }
                            }
                            cursor.pop();
                        }
                    } while (cursor.toNextSibling());
                } finally {
                    moveable.dispose();
                }
            }
        } finally {
            cursor.dispose();
        }
View Full Code Here

    }
   
    static XmlObject getWebservicesType(URL wsDDUrl) throws DeploymentException {
        try {
            XmlObject webservicesDocumentUntyped = XmlObject.Factory.parse(wsDDUrl);
            XmlCursor cursor = webservicesDocumentUntyped.newCursor();
            try {
                if (cursor.currentTokenType() != XmlCursor.TokenType.START) {
                    while(cursor.toNextToken()  != XmlCursor.TokenType.START) {}
                }
                QName qname = cursor.getName();
                if (WebservicesDocument.type.getDocumentElementName().equals(qname)) {
                    return getJ2EEWebServices(webservicesDocumentUntyped);
                } else if (org.apache.geronimo.xbeans.javaee.WebservicesDocument.type.getDocumentElementName().equals(qname)) {
                    return getJavaEEWebServices(webservicesDocumentUntyped);
                } else {
                    return null;
                }
            } finally {
                cursor.dispose();
            }
        } catch (XmlException e) {
            throw new DeploymentException("Could not read descriptor document", e);
        } catch (IOException e) {
            return null;
View Full Code Here

   * </pre>
   */
  private void appendChartElement(CTGraphicalObjectData data, String id) {
    String r_namespaceUri = STRelationshipId.type.getName().getNamespaceURI();
    String c_namespaceUri = XSSFDrawing.NAMESPACE_C;
    XmlCursor cursor = data.newCursor();
    cursor.toNextToken();
    cursor.beginElement(new QName(c_namespaceUri, "chart", "c"));
    cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id);
    cursor.dispose();
    data.setUri(c_namespaceUri);
  }
View Full Code Here

      assertEquals(3, doc.getPosOfParagraph(p));

     CTP ctp = p.getCTP();
     XWPFParagraph newP = doc.getParagraph(ctp);
     assertSame(p, newP);
     XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
     XWPFParagraph cP = doc.insertNewParagraph(cursor);
     assertSame(cP, doc.getParagraphs().get(0));
     assertEquals(5, doc.getParagraphs().size());
  }
View Full Code Here

        runs = new ArrayList<XWPFRun>();

       // Get all our child nodes in order, and process them
       //  into XWPFRuns where we can
       XmlCursor c = paragraph.newCursor();
       c.selectPath("child::*");
       while (c.toNextSelection()) {
          XmlObject o = c.getObject();
          if(o instanceof CTR) {
             runs.add(new XWPFRun((CTR)o, this));
          }
          if(o instanceof CTHyperlink) {
             CTHyperlink link = (CTHyperlink)o;
             for(CTR r : link.getRList()) {
                runs.add(new XWPFHyperlinkRun(link, r, this));
             }
          }
          if(o instanceof CTSdtRun) {
             CTSdtContentRun run = ((CTSdtRun)o).getSdtContent();
             for(CTR r : run.getRList()) {
                runs.add(new XWPFRun(r, this));
             }
          }
          if(o instanceof CTRunTrackChange) {
             for(CTR r : ((CTRunTrackChange)o).getRList()) {
                runs.add(new XWPFRun(r, this));
             }
          }
          if(o instanceof CTSimpleField) {
             for(CTR r : ((CTSimpleField)o).getRList()) {
                runs.add(new XWPFRun(r, this));
             }
          }
       }

       c.dispose();
      
       // Look for bits associated with the runs
       for(XWPFRun run : runs) {
          CTR r = run.getCTR();
         
          // Check for bits that only apply when
          //  attached to a core document
          // TODO Make this nicer by tracking the XWPFFootnotes directly
          if(document != null) {
             c = r.newCursor();
             c.selectPath("child::*");
             while (c.toNextSelection()) {
                XmlObject o = c.getObject();
                if(o instanceof CTFtnEdnRef) {
                   CTFtnEdnRef ftn = (CTFtnEdnRef)o;
                   footnoteText.append("[").append(ftn.getId()).append(": ");
                   XWPFFootnote footnote =
                      ftn.getDomNode().getLocalName().equals("footnoteReference") ?
                            document.getFootnoteByID(ftn.getId().intValue()) :
                            document.getEndnoteByID(ftn.getId().intValue());
  
                   boolean first = true;
                   for (XWPFParagraph p : footnote.getParagraphs()) {
                      if (!first) {
                         footnoteText.append("\n");
                         first = false;
                      }
                      footnoteText.append(p.getText());
                   }
  
                   footnoteText.append("]");
                }
             }
             c.dispose();
          }
      }
    }
View Full Code Here

      int beginRunPos = 0, candCharPos = 0;
      boolean newList = false;
      for (int runPos=startRun; runPos<paragraph.getRList().size(); runPos++) {
        int beginTextPos = 0,beginCharPos = 0, textPos = 0,  charPos = 0
        CTR ctRun = paragraph.getRArray(runPos);
        XmlCursor c = ctRun.newCursor();
        c.selectPath("./*");
        while(c.toNextSelection()){
          XmlObject o = c.getObject();
          if(o instanceof CTText){
            if(textPos>=startText){
              String candidate = ((CTText)o).getStringValue();
              if(runPos==startRun)
                charPos= startChar;
              else
                charPos = 0
              for(; charPos<candidate.length(); charPos++){
                if((candidate.charAt(charPos)==searched.charAt(0))&&(candCharPos==0)){
                  beginTextPos = textPos;
                  beginCharPos = charPos;
                  beginRunPos = runPos;
                  newList = true;
                }
                if(candidate.charAt(charPos)==searched.charAt(candCharPos)){
                  if(candCharPos+1<searched.length())
                    candCharPos++;
                  else if(newList){
                    TextSegement segement = new TextSegement();
                    segement.setBeginRun(beginRunPos);
                    segement.setBeginText(beginTextPos);
                    segement.setBeginChar(beginCharPos);
                    segement.setEndRun(runPos);
                    segement.setEndText(textPos);
                    segement.setEndChar(charPos);
                    return segement;
                  }
                }
                else
                  candCharPos=0;
              }
            }
            textPos++;
          }
          else if(o instanceof CTProofErr){
            c.removeXml();
          }
          else if(o instanceof CTRPr);
            //do nothing
          else
            candCharPos=0;
        }

            c.dispose();
      }
      return null;
    }
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.XmlCursor

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.