本文整理汇总了Java中net.sf.saxon.om.Item类的典型用法代码示例。如果您正苦于以下问题:Java Item类的具体用法?Java Item怎么用?Java Item使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Item类属于net.sf.saxon.om包,在下文中一共展示了Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isXpathQueryMatching
import net.sf.saxon.om.Item; //导入依赖的package包/类
/**
* Is matching by xpath query.
* @param event event
* @return true is matching
*/
private boolean isXpathQueryMatching(TreeWalkerAuditEvent event) {
boolean isMatching;
if (xpathExpression == null) {
isMatching = true;
}
else {
isMatching = false;
final List<Item> items = getItems(event);
for (Item item : items) {
final AbstractNode abstractNode = (AbstractNode) item;
isMatching = abstractNode.getTokenType() == event.getTokenType()
&& abstractNode.getLineNumber() == event.getLine()
&& abstractNode.getColumnNumber() == event.getColumnCharIndex();
if (isMatching) {
break;
}
}
}
return isMatching;
}
示例2: getItems
import net.sf.saxon.om.Item; //导入依赖的package包/类
/**
* Returns list of nodes matching xpath expression given event.
* @param event {@code TreeWalkerAuditEvent} object
* @return list of nodes matching xpath expression given event
*/
private List<Item> getItems(TreeWalkerAuditEvent event) {
final RootNode rootNode;
if (event.getRootAst() == null) {
rootNode = null;
}
else {
rootNode = new RootNode(event.getRootAst());
}
final List<Item> items;
try {
final XPathDynamicContext xpathDynamicContext =
xpathExpression.createDynamicContext(rootNode);
items = xpathExpression.evaluate(xpathDynamicContext);
}
catch (XPathException ex) {
throw new IllegalStateException("Cannot initialize context and evaluate query: "
+ xpathQuery, ex);
}
return items;
}
示例3: testQueryAllMethodDefinitionsInContext
import net.sf.saxon.om.Item; //导入依赖的package包/类
@Test
public void testQueryAllMethodDefinitionsInContext() throws Exception {
final String objectXpath = "/CLASS_DEF[@text='InputXpathMapperAst']//OBJBLOCK";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
final List<Item> objectNodes = getXpathItems(objectXpath, rootNode);
assertEquals("Invalid number of nodes", 1, objectNodes.size());
final AbstractNode objNode = (AbstractNode) objectNodes.get(0);
final String methodsXpath = "METHOD_DEF";
final List<Item> methodsNodes = getXpathItems(methodsXpath, objNode);
assertEquals("Invalid number of nodes", 2, methodsNodes.size());
final DetailAST[] actual = convertToArray(methodsNodes);
final DetailAST expectedMethodDefNode = getSiblingByType(rootNode.getUnderlyingNode(),
TokenTypes.CLASS_DEF)
.findFirstToken(TokenTypes.OBJBLOCK)
.findFirstToken(TokenTypes.METHOD_DEF);
final DetailAST[] expected = {expectedMethodDefNode,
expectedMethodDefNode.getNextSibling()};
assertArrayEquals("Result nodes differ from expected", expected, actual);
}
示例4: iterate
import net.sf.saxon.om.Item; //导入依赖的package包/类
public SequenceIterator iterate(XPathContext context) throws XPathException {
final SequenceIterator iterator = myVariable.iterate(context);
if (iterator instanceof EmptyIterator) {
final ValueRepresentation value = myVariable.evaluateVariable(context);
if (value instanceof Item) {
return SingletonIterator.makeIterator((Item)value);
} else if (value instanceof net.sf.saxon.value.Value) {
return ((net.sf.saxon.value.Value)value).iterate();
} else {
return iterator;
}
} else {
return iterator;
}
}
示例5: makeCallExpression
import net.sf.saxon.om.Item; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
private static final long serialVersionUID = 1L;
@Override
public Sequence call(XPathContext xPathContext, Sequence[] arguments) throws XPathException {
// 1st argument (mandatory, index 0)
StringValue arg1 = (StringValue) arguments[0].iterate().next();
String arg1Str = arg1.getStringValue();
// 2nd argument (optional, index 1)
String arg2Str = "";
if (arguments.length > 1) {
StringValue arg2 = (StringValue) arguments[1].iterate().next();
arg2Str = arg2.getStringValue();
}
// Functionality goes here
String resultStr = arg1Str + arg2Str;
Item result = new StringValue(resultStr);
return SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
}
};
}
示例6: makeCallExpression
import net.sf.saxon.om.Item; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
private static final long serialVersionUID = 1L;
@Override
public Sequence call(XPathContext xPathContext, Sequence[] arguments) throws XPathException {
// 1st argument (mandatory, index 0)
Int64Value arg1 = (Int64Value) arguments[0].iterate().next();
int arg1Int = arg1.getDecimalValue().toBigInteger().intValue();
// 2nd argument (mandatory, index 1)
Int64Value arg2 = (Int64Value) arguments[1].iterate().next();
int arg2Int = arg2.getDecimalValue().toBigInteger().intValue();
// Functionality goes here
int resultInt = arg1Int + arg2Int;
Item result = new Int64Value(resultInt);
return SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
}
};
}
示例7: makeCallExpression
import net.sf.saxon.om.Item; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
private static final long serialVersionUID = 1L;
@Override
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
// get value of first arg passed to the function
Item arg1 = sequences[0].head();
String arg1Val = arg1.getStringValue();
// return a altered version of the first arg
return new StringValue("arg1[" + arg1Val + "]");
}
};
}
示例8: getStringValueOrNull
import net.sf.saxon.om.Item; //导入依赖的package包/类
static String getStringValueOrNull(Sequence[] pArguments, int pIndex, String pFunctionName, boolean pStrict)
throws XPathException {
String lResult = null;
if(pArguments.length > pIndex) {
Item lItem = pArguments[pIndex].head();
if(!(lItem instanceof StringValue) && pStrict) {
throw new ExInternal("Argument " + (pIndex+1) + " to " + pFunctionName + " function must be a string.");
}
if(lItem != null) {
lResult = lItem.getStringValue();
}
}
return lResult;
}
示例9: getBooleanValue
import net.sf.saxon.om.Item; //导入依赖的package包/类
/**
* Gets a boolean value from the given index of the argument array. Atomic values are asked for their effective boolean
* value; node values are assumed to be true. Empty sequences return false.
* @param pArguments Function arguments.
* @param pIndex Index of the array to inspect.
* @return Boolean value of the argument.
* @throws XPathException
*/
static boolean getBooleanValue(Sequence[] pArguments, int pIndex)
throws XPathException {
if(pArguments.length > pIndex) {
Item lItem = pArguments[pIndex].head();
if(lItem == null) {
return false;
}
if(lItem instanceof AtomicValue) {
return ((AtomicValue) lItem).effectiveBooleanValue();
}
else {
//Assume a node which exists and is therefore true
return true;
}
}
else {
return false;
}
}
示例10: getIntegerValueOrNull
import net.sf.saxon.om.Item; //导入依赖的package包/类
/**
* Gets an integer value from the given index of the argument array. If no item is found, null is returned. Otherwise
* the item is assumed to be a NumericValue and is converted to an integer (decimal values are rounded to the nearest
* integer).
* @param pArguments Function arguments.
* @param pIndex Index of the array to inspect.
* @return Integer value at the given index, or null.
* @throws XPathException
*/
static Integer getIntegerValueOrNull(Sequence[] pArguments, int pIndex)
throws XPathException {
if(pArguments.length > pIndex) {
Item lItem = pArguments[pIndex].head();
if(lItem == null) {
return null;
}
else {
return (int) ((NumericValue) lItem).round(0).getDoubleValue();
}
}
else {
return null;
}
}
示例11: getPath
import net.sf.saxon.om.Item; //导入依赖的package包/类
public static Sequence getPath(KeyDefInterface keyDef) {
if (keyDef != null) {
List<String> path = keyDef.getNamespaceList();
List<Item> list = new LinkedList<>();
if (path != null) {
for (String element : path) {
list.add(new StringValue(element));
}
}
list.add(new StringValue(keyDef.getKey()));
//logger.info("result: " + keyDef.getNamespace() + " " + keyDef.getKey());
return new SequenceExtent(list);
} else {
//logger.info("result: ()");
return EmptySequence.getInstance();
}
}
示例12: call
import net.sf.saxon.om.Item; //导入依赖的package包/类
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
final Item contextItem = context.getContextItem();
if (!(contextItem instanceof NodeInfo)) {
throw new XPathException("Context item '" + contextItem.getClass() + "'needs to be an instance of NodeInfo.");
}
final String xPath = arguments[0].head().getStringValue();
final SaxonNodeWrapper contextNode = new SaxonNodeWrapper((NodeInfo)contextItem, otResolver.getXPathCache());
final String resolvedXPath = EmbeddedXPathResolver.resolve(xPath, contextNode);
return new StringValue(resolvedXPath);
}
示例13: call
import net.sf.saxon.om.Item; //导入依赖的package包/类
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
final SaxonNodeWrapper keyRefNode = new SaxonNodeWrapper((NodeInfo)arguments[0].head(), otResolver.getXPathCache());
final KeyRef keyRef = KeyRef.fromNode(keyRefNode);
final Item keyDefItem = arguments[1].head();
if ((keyRef == null) || (keyDefItem == null)) {
return EmptySequence.getInstance();
} else {
final KeyDefInterface keyDef = DitaSemiaOtResolver.getKeyDefFromItem(arguments[1].head());
final DisplaySuffix displaySuffix = keyRef.getDisplaySuffix(keyDef, false);
final List<Item> list = new LinkedList<>();
list.add(new StringValue(displaySuffix.keySuffix));
list.add(new StringValue(displaySuffix.nameSuffix));
return new SequenceExtent(list);
}
}
示例14: serialize
import net.sf.saxon.om.Item; //导入依赖的package包/类
protected void serialize(Sequence seq, OutputStream os, Properties outputProperties) throws XPathException {
String encoding = "UTF-8";
if (outputProperties != null) {
encoding = outputProperties.getProperty("encoding", encoding);
}
try {
SequenceIterator iter = seq.iterate();
Item item;
while ((item = iter.next()) != null) {
if (item instanceof NodeInfo) {
serialize((NodeInfo) item, new StreamResult(os), outputProperties);
} else {
new OutputStreamWriter(os, encoding).append(item.getStringValue());
}
}
} catch (Exception e) {
throw new XPathException(e);
}
}
示例15: sequenceToAttributeCollection
import net.sf.saxon.om.Item; //导入依赖的package包/类
protected Collection<Attribute> sequenceToAttributeCollection(Sequence seq) throws XPathException {
ArrayList<Attribute> attrs = new ArrayList<Attribute>();
Item item;
SequenceIterator iter = seq.iterate();
while ((item = iter.next()) != null) {
Object value;
String type;
boolean isSerialized;
if (item instanceof NodeInfo) {
value = serialize((NodeInfo) item);
type = "node()";
isSerialized = true;
} else {
value = SequenceTool.convertToJava(item);
ItemType itemType = Type.getItemType(item, null);
type = itemType.toString();
isSerialized = false;
}
attrs.add(new Attribute(value, type, isSerialized));
}
return attrs;
}