本文整理汇总了Java中net.sf.saxon.om.Item.getStringValue方法的典型用法代码示例。如果您正苦于以下问题:Java Item.getStringValue方法的具体用法?Java Item.getStringValue怎么用?Java Item.getStringValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.om.Item
的用法示例。
在下文中一共展示了Item.getStringValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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 + "]");
}
};
}
示例2: 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;
}
示例3: getValue
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
public static Object getValue(Class<?> type,
Item colItem, Configuration config, CommandContext context) throws XPathException,
ValidationException, TransformationException {
Object value = colItem;
if (value instanceof AtomicValue) {
value = getValue((AtomicValue)colItem, context);
} else if (value instanceof Item) {
Item i = (Item)value;
if (XMLSystemFunctions.isNull(i)) {
return null;
}
BuiltInAtomicType bat = typeMapping.get(type);
if (bat != null) {
AtomicValue av = new StringValue(i.getStringValueCS());
ConversionResult cr = Converter.convert(av, bat, config.getConversionRules());
value = cr.asAtomic();
value = getValue((AtomicValue)value, context);
if (value instanceof Item) {
value = ((Item)value).getStringValue();
}
} else {
value = i.getStringValue();
}
}
return FunctionDescriptor.importValue(value, type);
}
示例4: call
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
final String titleString = arguments[TITLE].head().getStringValue();
final String iconString = arguments[ICON].head().getStringValue();
String textString = "";
SequenceIterator iterator = arguments[TEXT].iterate();
Item item = iterator.next();
while (item != null) {
textString += item.getStringValue();
item = iterator.next();
}
JOptionPane.showMessageDialog(
(Frame)PluginWorkspaceProvider.getPluginWorkspace().getParentFrame(),
textString,
titleString,
getMessageType(iconString));
return EmptySequence.getInstance();
}
示例5: getSize
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
private Dimension getSize(Sequence[] arguments) throws XPathException {
//logger.info("getSize: " + arguments[SIZE].toString());
if (arguments[SIZE].head().getStringValue().isEmpty()) {
return null;
}
SequenceIterator iterator = arguments[SIZE].iterate();
ArrayList<Integer> sizeList = new ArrayList<Integer>();
Item item = iterator.next();
while (item != null) {
if (!(item instanceof IntegerValue)) {
throw new XPathException("The size attribute must contain only integer values ('" + item.getStringValue() + "').");
}
sizeList.add((int)(((IntegerValue)item).longValue()));
item = iterator.next();
}
if (sizeList.size() != 2) {
throw new XPathException("The size attribute must be empty or contain a sequence of 2 items.");
}
return new Dimension(sizeList.get(0), sizeList.get(1));
}
示例6: generateHtml
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
private String generateHtml(Sequence[] arguments) throws XPathException {
//logger.info("generateHTML");
String htmlString = "";
try {
SequenceIterator iterator = arguments[HTML].iterate();
Item item = iterator.next();
while (item != null) {
if (item instanceof StringValue) {
htmlString += item.getStringValue();
} else if (item instanceof NodeInfo) {
htmlString += QueryResult.serialize((NodeInfo)item);
} else {
throw new XPathException("Can't serialize item: " + item.getClass());
}
item = iterator.next();
}
} catch (Exception e) {
logger.error(e);
}
//logger.info("generated HTML: " + htmlString);
return htmlString;
}
示例7: sequence2Properties
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
public static Properties sequence2Properties(Sequence sq) throws XPathException {
Properties props = new Properties();
Item head = sq.head();
if (head instanceof MapItem) {
props.putAll(itemToMap((MapItem) head));
} else {
SequenceIterator itr = sq.iterate();
do {
Item item = itr.next();
if (item != null) {
String prop = item.getStringValue();
int pos = prop.indexOf("=");
if (pos > 0) {
props.setProperty(prop.substring(0, pos), prop.substring(pos + 1));
}
} else {
break;
}
} while (true);
}
return props;
}
示例8: sequence2Params
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
public static Map<String, Object> sequence2Params(Sequence sq) throws XPathException {
SequenceIterator itr = sq.iterate();
Map<String, Object> params = new HashMap<>();
do {
Item item = itr.next();
if (item != null) {
String name = item.getStringValue();
Object value = null;
item = itr.next();
if (item != null) {
value = SequenceTool.convertToJava(item);
}
params.put(name, value);
} else {
break;
}
} while (true);
return params;
}
示例9: testPersonQuery
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
@Test
public void testPersonQuery() throws XPathException, XQException {
Configuration config = Configuration.newConfiguration();
StaticQueryContext sqc = config.newStaticQueryContext();
DynamicQueryContext dqc = new DynamicQueryContext(config);
dqc.setApplyFunctionConversionRulesToExternalVariables(false);
String query = "declare base-uri \"../../etc/samples/xmark/\";\n" +
"let $auction := fn:doc(\"auction.xml\") return\n" +
"for $b in $auction/site/people/person[@id = 'person0'] return $b/name/text()";
//dqc.setParameter(new StructuredQName("", "", "v"), objectToItem(Boolean.TRUE, config));
XQueryExpression xqExp = sqc.compileQuery(query);
SequenceIterator itr = xqExp.iterator(dqc);
Item item = itr.next();
assertNotNull(item);
String val = item.getStringValue();
assertEquals("Huei Demke", val);
assertNull(itr.next());
}
示例10: serializeItem
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
/**
* Serializes item after XPath or XQuery processor execution using Saxon.
*/
public static String serializeItem(Item item) throws XPathException {
if (item instanceof NodeInfo) {
int type = ((NodeInfo)item).getNodeKind();
if (type == Type.DOCUMENT || type == Type.ELEMENT) {
Properties props = new Properties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
props.setProperty(OutputKeys.INDENT, "yes");
StringWriter stringWriter = new java.io.StringWriter();
QueryResult.serialize((NodeInfo)item, new StreamResult(stringWriter), props);
stringWriter.flush();
return stringWriter.toString().replaceAll(" xmlns=\"http\\://www.w3.org/1999/xhtml\"", "");
}
}
return item.getStringValue();
}
示例11: SequenceValue
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
public SequenceValue(Item value, SequenceIterator it, ItemType type) throws XPathException {
String s = "(" + value.getStringValue() + ", " + it.current().getStringValue();
while (it.next() != null) {
s += ", " + it.current().getStringValue();
}
s += ")";
myValue = s;
myItemType = type;
}
示例12: getHref
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
private String getHref(SequenceIterator param) throws XPathException {
Item item = param.next();
if (item == null) {
return null;
}
if (!(item instanceof StringValue)) {
throw new XPathException("The href param is not a string");
}
return item.getStringValue();
}
示例13: xpathValue
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
public static String xpathValue(Object doc, String xpath) throws XPathException, TeiidProcessingException {
Source s = null;
try {
s = convertToSource(doc);
XPathEvaluator eval = new XPathEvaluator();
// Wrap the string() function to force a string return
XPathExpression expr = eval.createExpression(xpath);
Object o = expr.evaluateSingle(s);
if(o == null) {
return null;
}
// Return string value of node type
if(o instanceof Item) {
Item i = (Item)o;
if (isNull(i)) {
return null;
}
return i.getStringValue();
}
// Return string representation of non-node value
return o.toString();
} finally {
Util.closeSource(s);
}
}
示例14: testMapQuery
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
@Test
public void testMapQuery() throws XPathException {
Configuration config = Configuration.newConfiguration();
config.setDefaultCollection("");
StaticQueryContext sqc = config.newStaticQueryContext();
DynamicQueryContext dqc = new DynamicQueryContext(config);
dqc.setApplyFunctionConversionRulesToExternalVariables(false);
//String xml = "<map>\n" +
// " <boolProp>false</boolProp>\n" +
// " <strProp>XYZ</strProp>\n" +
// " <intProp>1</intProp>\n" +
// "</map>";
//String baseURI = sqc.getBaseURI();
//StringReader sr = new StringReader(xml);
//InputSource is = new InputSource(sr);
//is.setSystemId(baseURI);
//Source source = new SAXSource(is);
//source.setSystemId(baseURI);
//config.getGlobalDocumentPool().add(config.buildDocumentTree(source), "map.xml");
String query = "declare base-uri \"../../etc/samples/xdm/\";\n" +
"declare variable $value external;\n" +
"for $doc in fn:collection()/map\n" +
"where $doc/intProp = $value\n" +
//"where $doc[intProp = $value]\n" +
"return $doc/strProp/text()";
XQueryExpression xqExp = sqc.compileQuery(query);
dqc.setParameter(new StructuredQName("", "", "value"), objectToItem(1, config));
SequenceIterator itr = xqExp.iterator(dqc);
Item item = itr.next();
assertNotNull(item);
String val = item.getStringValue();
assertEquals("XYZ", val);
assertNull(itr.next());
}
示例15: testJsonQuery
import net.sf.saxon.om.Item; //导入方法依赖的package包/类
@Test
@Ignore
public void testJsonQuery() throws XPathException {
Configuration config = Configuration.newConfiguration();
config.setDefaultCollection("");
StaticQueryContext sqc = config.newStaticQueryContext();
sqc.setLanguageVersion(saxon_xquery_version);
DynamicQueryContext dqc = new DynamicQueryContext(config);
dqc.setApplyFunctionConversionRulesToExternalVariables(false);
String query = "declare base-uri \"../../etc/samples/json/\";\n" +
//"declare base-uri \"C:/Work/Bagri/git/bagri/etc/samples/json/\";\n" +
"declare namespace map=\"http://www.w3.org/2005/xpath-functions/map\";\n" +
//"declare variable $value external;\n" +
"for $map in fn:collection()\n" +
//"where $map?Security?Symbol = $value\n" +
"let $v := map:get($map, 'Security')\n" +
//"where get($map, '-id') = '5621'\n" +
"where map:get($v, 'Symbol') = 'IBM'\n" +
"return $v?Name";
XQueryExpression xqExp = sqc.compileQuery(query);
//dqc.setParameter(new StructuredQName("", "", "value"), objectToItem("IBM", config));
SequenceIterator itr = xqExp.iterator(dqc);
Item item = itr.next();
assertNotNull(item);
String val = item.getStringValue();
assertEquals("Internatinal Business Machines Corporation", val);
assertNull(itr.next());
}