Search in sources :

Example 21 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XML method moveSrcToDest.

/**
     *
     * @param srcCurs
     * @param destCurs
     * @param fDontMoveIfSame
     * @return
     */
private boolean moveSrcToDest(XmlCursor srcCurs, XmlCursor destCurs, boolean fDontMoveIfSame) {
    boolean fMovedSomething = true;
    TokenType tt;
    do {
        if (fDontMoveIfSame && srcCurs.isInSameDocument(destCurs) && (srcCurs.comparePosition(destCurs) == 0)) {
            // If the source and destination are pointing at the same place then there's nothing to move.
            fMovedSomething = false;
            break;
        }
        // todo ***TLL*** Use replaceContents (when added) and eliminate children removes (see above todo).
        if (destCurs.currentTokenType().isStartdoc()) {
            destCurs.toNextToken();
        }
        // todo ***TLL*** Can Eric support notion of copy instead of me copying then moving???
        XmlCursor copyCurs = copy(srcCurs);
        copyCurs.moveXml(destCurs);
        copyCurs.dispose();
        tt = srcCurs.currentTokenType();
    } while (!tt.isStart() && !tt.isEnd() && !tt.isEnddoc());
    return fMovedSomething;
}
Also used : TokenType(org.apache.xmlbeans.XmlCursor.TokenType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 22 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XMLLibImpl method escapeTextValue.

/**
     * Escapes the reserved characters in a value of a text node
     *
     * @param value Unescaped text
     * @return The escaped text
     */
public String escapeTextValue(Object value) {
    if (value instanceof XMLObjectImpl) {
        return ((XMLObjectImpl) value).toXMLString(0);
    }
    String text = ScriptRuntime.toString(value);
    if (text.length() == 0)
        return text;
    XmlObject xo = XmlObject.Factory.newInstance();
    XmlCursor cursor = xo.newCursor();
    cursor.toNextToken();
    cursor.beginElement("a");
    cursor.insertChars(text);
    cursor.dispose();
    String elementText = xo.toString();
    int begin = elementText.indexOf('>') + 1;
    int end = elementText.lastIndexOf('<');
    return (begin < end) ? elementText.substring(begin, end) : "";
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 23 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project poi by apache.

the class XSLFShape method selectPaint.

protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) {
    if (fillRef == null)
        return null;
    // The idx attribute refers to the index of a fill style or
    // background fill style within the presentation's style matrix, defined by the fmtScheme element.
    // value of 0 or 1000 indicates no background,
    // values 1-999 refer to the index of a fill style within the fillStyleLst element
    // values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
    int idx = (int) fillRef.getIdx();
    CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
    final XmlObject styleLst;
    int childIdx;
    if (idx >= 1 && idx <= 999) {
        childIdx = idx - 1;
        styleLst = (isLineStyle) ? matrix.getLnStyleLst() : matrix.getFillStyleLst();
    } else if (idx >= 1001) {
        childIdx = idx - 1001;
        styleLst = matrix.getBgFillStyleLst();
    } else {
        return null;
    }
    XmlCursor cur = styleLst.newCursor();
    XSLFFillProperties fp = null;
    if (cur.toChild(childIdx)) {
        fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
    }
    cur.dispose();
    CTSchemeColor phClr = fillRef.getSchemeClr();
    PaintStyle res = selectPaint(fp, phClr, theme.getPackagePart(), theme, hasPlaceholder);
    // see http://officeopenxml.com/prSlide-color.php - "Color Placeholders within Themes"
    if (res != null || hasPlaceholder) {
        return res;
    }
    XSLFColor col = new XSLFColor(fillRef, theme, phClr);
    return DrawPaint.createSolidPaint(col.getColorStyle());
}
Also used : CTStyleMatrix(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) XmlObject(org.apache.xmlbeans.XmlObject) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 24 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project poi by apache.

the class RelationshipTransformService method transform.

public Data transform(Data data, XMLCryptoContext context) throws TransformException {
    LOG.log(POILogger.DEBUG, "transform(data,context)");
    LOG.log(POILogger.DEBUG, "data java type: " + data.getClass().getName());
    OctetStreamData octetStreamData = (OctetStreamData) data;
    LOG.log(POILogger.DEBUG, "URI: " + octetStreamData.getURI());
    InputStream octetStream = octetStreamData.getOctetStream();
    RelationshipsDocument relDoc;
    try {
        relDoc = RelationshipsDocument.Factory.parse(octetStream, DEFAULT_XML_OPTIONS);
    } catch (Exception e) {
        throw new TransformException(e.getMessage(), e);
    }
    LOG.log(POILogger.DEBUG, "relationships document", relDoc);
    CTRelationships rels = relDoc.getRelationships();
    List<CTRelationship> relList = rels.getRelationshipList();
    Iterator<CTRelationship> relIter = rels.getRelationshipList().iterator();
    while (relIter.hasNext()) {
        CTRelationship rel = relIter.next();
        /*
             * See: ISO/IEC 29500-2:2008(E) - 13.2.4.24 Relationships Transform
             * Algorithm.
             */
        if (!this.sourceIds.contains(rel.getId())) {
            LOG.log(POILogger.DEBUG, "removing element: " + rel.getId());
            relIter.remove();
        } else {
            if (!rel.isSetTargetMode()) {
                rel.setTargetMode(STTargetMode.INTERNAL);
            }
        }
    }
    // TODO: remove non element nodes ???
    LOG.log(POILogger.DEBUG, "# Relationship elements", relList.size());
    XmlSort.sort(rels, new Comparator<XmlCursor>() {

        public int compare(XmlCursor c1, XmlCursor c2) {
            String id1 = ((CTRelationship) c1.getObject()).getId();
            String id2 = ((CTRelationship) c2.getObject()).getId();
            return id1.compareTo(id2);
        }
    });
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XmlOptions xo = new XmlOptions();
        xo.setSaveNoXmlDecl();
        relDoc.save(bos, xo);
        return new OctetStreamData(new ByteArrayInputStream(bos.toByteArray()));
    } catch (IOException e) {
        throw new TransformException(e.getMessage(), e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlOptions(org.apache.xmlbeans.XmlOptions) TransformException(javax.xml.crypto.dsig.TransformException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MarshalException(javax.xml.crypto.MarshalException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) TransformException(javax.xml.crypto.dsig.TransformException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) XmlCursor(org.apache.xmlbeans.XmlCursor) CTRelationship(org.openxmlformats.schemas.xpackage.x2006.relationships.CTRelationship) RelationshipsDocument(org.openxmlformats.schemas.xpackage.x2006.relationships.RelationshipsDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) CTRelationships(org.openxmlformats.schemas.xpackage.x2006.relationships.CTRelationships) OctetStreamData(javax.xml.crypto.OctetStreamData)

Example 25 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project poi by apache.

the class XAdESSignatureFacet method insertXChild.

protected static void insertXChild(XmlObject root, XmlObject child) {
    XmlCursor rootCursor = root.newCursor();
    rootCursor.toEndToken();
    XmlCursor childCursor = child.newCursor();
    childCursor.toNextToken();
    childCursor.moveXml(rootCursor);
    childCursor.dispose();
    rootCursor.dispose();
}
Also used : XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

XmlCursor (org.apache.xmlbeans.XmlCursor)160 XmlObject (org.apache.xmlbeans.XmlObject)68 QName (javax.xml.namespace.QName)21 XmlException (org.apache.xmlbeans.XmlException)16 TokenType (org.apache.xmlbeans.XmlCursor.TokenType)14 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)14 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)10 ArrayList (java.util.ArrayList)9 POSIXApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationType)8 HPCProfileApplicationType (org.ggf.schemas.jsdl.x2006.x07.jsdlHpcpa.HPCProfileApplicationType)8 SPMDApplicationType (org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.SPMDApplicationType)8 IOException (java.io.IOException)5 POIXMLException (org.apache.poi.POIXMLException)5 InputStream (java.io.InputStream)4 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 ArrayType (org.dmg.pmml.ArrayType)3 ApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType)3 LineString (org.locationtech.jts.geom.LineString)3 CTRow (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow)3 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3