use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method insertChild.
/**
*
* @param childToMatch
* @param xmlToInsert
* @param addToType
*/
private void insertChild(XML childToMatch, Object xmlToInsert, int addToType) {
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
XmlCursor xmlChildCursor = childToMatch.newCursor();
if (tt.isStartdoc()) {
tt = curs.toFirstContentToken();
}
if (tt.isContainer()) {
tt = curs.toNextToken();
while (!tt.isEnd()) {
if (tt.isStart()) {
// See if this child is the same as the one thep passed in
if (curs.comparePosition(xmlChildCursor) == 0) {
// Found it
if (addToType == APPEND_CHILD) {
// Move the cursor to just past the end of this element
curs.toEndToken();
curs.toNextToken();
}
insertChild(curs, xmlToInsert);
break;
}
}
// Skip over child elements
if (tt.isStart()) {
tt = curs.toEndToken();
}
tt = curs.toNextToken();
}
}
xmlChildCursor.dispose();
curs.dispose();
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XMLLibImpl method escapeAttributeValue.
/**
* Escapes the reserved characters in a value of an attribute
*
* @param value Unescaped text
* @return The escaped text
*/
public String escapeAttributeValue(Object value) {
String text = ScriptRuntime.toString(value);
if (text.length() == 0)
return "";
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor cursor = xo.newCursor();
cursor.toNextToken();
cursor.beginElement("a");
cursor.insertAttributeWithValue("a", text);
cursor.dispose();
String elementText = xo.toString();
int begin = elementText.indexOf('"');
int end = elementText.lastIndexOf('"');
return elementText.substring(begin + 1, end);
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method namespaceDeclarations.
/**
*
* @return
*/
Object[] namespaceDeclarations() {
XmlCursor cursor = newCursor();
Object[] namespaces = NamespaceHelper.namespaceDeclarations(lib, cursor);
cursor.dispose();
return namespaces;
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method deleteXMLProperty.
/**
*
* @param name
*/
void deleteXMLProperty(XMLName name) {
if (!name.isDescendants() && name.isAttributeName()) {
XmlCursor curs = newCursor();
// TODO: Cover the case *::name
if (name.localName().equals("*")) {
// Delete all attributes.
if (curs.toFirstAttribute()) {
while (curs.currentTokenType().isAttr()) {
curs.removeXml();
}
}
} else {
// Delete an attribute.
javax.xml.namespace.QName qname = new javax.xml.namespace.QName(name.uri(), name.localName());
curs.removeAttribute(qname);
}
curs.dispose();
} else {
XMLList matches = getPropertyList(name);
matches.remove();
}
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method replaceAll.
/**
*
* @param value
*/
void replaceAll(XML value) {
XmlCursor curs = newCursor();
replace(curs, value);
_anno = value._anno;
curs.dispose();
}
Aggregations