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;
}
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) : "";
}
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());
}
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);
}
}
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();
}
Aggregations