use of org.apache.xml.utils.QName in project robovm by robovm.
the class FuncKey method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
// TransformerImpl transformer = (TransformerImpl)xctxt;
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
XNodeSet nodes = null;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
if (DTM.NULL == docContext) {
// path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
}
String xkeyname = getArg0().execute(xctxt).str();
QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
XObject arg = getArg1().execute(xctxt);
boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
KeyManager kmgr = transformer.getKeyManager();
// Don't bother with nodeset logic if the thing is only one node.
if (argIsNodeSetDTM) {
XNodeSet ns = (XNodeSet) arg;
ns.setShouldCacheNodes(true);
int len = ns.getLength();
if (len <= 1)
argIsNodeSetDTM = false;
}
if (argIsNodeSetDTM) {
Hashtable usedrefs = null;
DTMIterator ni = arg.iter();
int pos;
UnionPathIterator upi = new UnionPathIterator();
upi.exprSetParent(this);
while (DTM.NULL != (pos = ni.nextNode())) {
dtm = xctxt.getDTM(pos);
XMLString ref = dtm.getStringValue(pos);
if (null == ref)
continue;
if (null == usedrefs)
usedrefs = new Hashtable();
if (usedrefs.get(ref) != null) {
// We already have 'em.
continue;
} else {
// ISTRUE being used as a dummy value.
usedrefs.put(ref, ISTRUE);
}
XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nl.setRoot(xctxt.getCurrentNode(), xctxt);
// try
// {
upi.addIterator(nl);
// }
// catch(CloneNotSupportedException cnse)
// {
// // will never happen.
// }
//mnodeset.addNodesInDocOrder(nl, xctxt); needed??
}
int current = xctxt.getCurrentNode();
upi.setRoot(current, xctxt);
nodes = new XNodeSet(upi);
} else {
XMLString ref = arg.xstr();
nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nodes.setRoot(xctxt.getCurrentNode(), xctxt);
}
return nodes;
}
use of org.apache.xml.utils.QName in project robovm by robovm.
the class OutputProperties method getQNameProperties.
/**
* Searches for the list of qname properties with the specified key in
* the property list.
* If the key is not found in this property list, the default property list,
* and its defaults, recursively, are then checked. The method returns
* <code>null</code> if the property is not found.
*
* @param key the property key.
* @param props the list of properties to search in.
* @return the value in this property list as a vector of QNames, or false
* if null or not "yes".
*/
public static Vector getQNameProperties(String key, Properties props) {
String s = props.getProperty(key);
if (null != s) {
Vector v = new Vector();
int l = s.length();
boolean inCurly = false;
FastStringBuffer buf = new FastStringBuffer();
// which theoretically shouldn't happen if they contain legal URLs.
for (int i = 0; i < l; i++) {
char c = s.charAt(i);
if (Character.isWhitespace(c)) {
if (!inCurly) {
if (buf.length() > 0) {
QName qname = QName.getQNameFromString(buf.toString());
v.addElement(qname);
buf.reset();
}
continue;
}
} else if ('{' == c)
inCurly = true;
else if ('}' == c)
inCurly = false;
buf.append(c);
}
if (buf.length() > 0) {
QName qname = QName.getQNameFromString(buf.toString());
v.addElement(qname);
buf.reset();
}
return v;
} else
return null;
}
use of org.apache.xml.utils.QName in project robovm by robovm.
the class XSLTAttributeDef method processQNAMES.
/**
* Process an attribute string of type T_QNAMES into a vector of QNames where
* the specification requires that non-prefixed elements not be placed in a
* namespace. (See section 2.4 of XSLT 1.0.)
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
* @param uri The Namespace URI, or an empty string.
* @param name The local name (without prefix), or empty string if not namespace processing.
* @param rawName The qualified name (with prefix).
* @param value A whitespace delimited list of qualified names.
*
* @return a Vector of QName objects.
*
* @throws org.xml.sax.SAXException if the one of the qualified name strings
* contains a prefix that can not be
* resolved, or a qualified name contains syntax that is invalid for a qualified name.
*/
Vector processQNAMES(StylesheetHandler handler, String uri, String name, String rawName, String value) throws org.xml.sax.SAXException {
StringTokenizer tokenizer = new StringTokenizer(value, " \t\n\r\f");
int nQNames = tokenizer.countTokens();
Vector qnames = new Vector(nQNames);
for (int i = 0; i < nQNames; i++) {
// Fix from Alexander Rudnev
qnames.addElement(new QName(tokenizer.nextToken(), handler));
}
return qnames;
}
use of org.apache.xml.utils.QName in project robovm by robovm.
the class Variable method fixupVariables.
/**
* This function is used to fixup variables from QNames to stack frame
* indexes at stylesheet build time.
* @param vars List of QNames that correspond to variables. This list
* should be searched backwards for the first qualified name that
* corresponds to the variable reference qname. The position of the
* QName in the vector from the start of the vector will be its position
* in the stack frame (but variables above the globalsTop value will need
* to be offset to the current stack frame).
*/
public void fixupVariables(java.util.Vector vars, int globalsSize) {
m_fixUpWasCalled = true;
int sz = vars.size();
for (int i = vars.size() - 1; i >= 0; i--) {
QName qn = (QName) vars.elementAt(i);
// System.out.println("qn: "+qn);
if (qn.equals(m_qname)) {
if (i < globalsSize) {
m_isGlobal = true;
m_index = i;
} else {
m_index = i - globalsSize;
}
return;
}
}
java.lang.String msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_COULD_NOT_FIND_VAR, new Object[] { m_qname.toString() });
TransformerException te = new TransformerException(msg, this);
throw new org.apache.xml.utils.WrappedRuntimeException(te);
}
use of org.apache.xml.utils.QName in project robovm by robovm.
the class FuncExtElementAvailable method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
String prefix;
String namespace;
String methName;
String fullName = m_arg0.execute(xctxt).str();
int indexOfNSSep = fullName.indexOf(':');
if (indexOfNSSep < 0) {
prefix = "";
namespace = Constants.S_XSLNAMESPACEURL;
methName = fullName;
} else {
prefix = fullName.substring(0, indexOfNSSep);
namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
if (null == namespace)
return XBoolean.S_FALSE;
methName = fullName.substring(indexOfNSSep + 1);
}
if (namespace.equals(Constants.S_XSLNAMESPACEURL) || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) {
try {
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
return transformer.getStylesheet().getAvailableElements().containsKey(new QName(namespace, methName)) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
} catch (Exception e) {
return XBoolean.S_FALSE;
}
} else {
//dml
ExtensionsProvider extProvider = (ExtensionsProvider) xctxt.getOwnerObject();
return extProvider.elementAvailable(namespace, methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
}
Aggregations