本文整理汇总了Java中net.sf.saxon.expr.XPathContext类的典型用法代码示例。如果您正苦于以下问题:Java XPathContext类的具体用法?Java XPathContext怎么用?Java XPathContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XPathContext类属于net.sf.saxon.expr包,在下文中一共展示了XPathContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的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));
}
};
}
示例2: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的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));
}
};
}
示例3: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的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 + "]");
}
};
}
示例4: call2
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
public Sequence call2(XPathContext context, Sequence[] arguments) throws XPathException {
final SequenceOutputter out = context.getController().allocateSequenceOutputter(50);
out.startElement(new NoNamespaceName("test1"), Untyped.getInstance(), locationId, 0);
out.startContent();
out.characters("text1", locationId, 0);
out.endElement();
out.startElement(new NoNamespaceName("test2"), Untyped.getInstance(), locationId, 0);
out.startContent();
out.characters("text2", locationId, 0);
out.endElement();
return out.getSequence();
}
示例5: call
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String path = ((StringValue) arguments[0].head()).getStringValue();
File file;
if ((file = XSLWebUtils.getSafeTempFile(path)) == null) {
throw new XPathException("Could not register temporary file. Path is not a valid temporary path.");
}
HttpServletRequest request = getRequest(context);
List<File> tempFiles = (List<File>) request.getAttribute(Definitions.ATTRNAME_TEMPFILES);
if (tempFiles == null) {
tempFiles = new ArrayList<File>();
request.setAttribute(Definitions.ATTRNAME_TEMPFILES, tempFiles);
}
tempFiles.add(file);
return EmptySequence.getInstance();
} catch (Exception e) {
throw new XPathException("Could not register temporary file", e);
}
}
示例6: call
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
ResultSet rset = ((ObjectValue<ResultSet>) arguments[0].head()).getObject();
if (!rset.next()) {
return EmptySequence.getInstance();
}
ArrayList<AtomicValue> values = new ArrayList<AtomicValue>();
ResultSetMetaData metaData = rset.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
AtomicValue value = convertJavaObjectToAtomicValue(rset.getObject(i));
values.add(value);
}
return new OneOrMore<AtomicValue>(values.toArray(new AtomicValue[values.size()]));
} catch (Exception e) {
throw new XPathException("Could not get row", e);
}
}
示例7: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
public SequenceIterator call(SequenceIterator[] arguments,
XPathContext context) throws XPathException {
// grijpt nummer uit string en plakt eventuele toevoeging eraan vast
String streetName = "";
try {
streetName = ((StringValue) arguments[0].next()).getStringValue();
streetName = sanitizeStreetName(streetName);
} catch (Exception e) {
return Value.asIterator(EmptySequence.getInstance());
}
if (streetName.length() == 0) {
return Value.asIterator(EmptySequence.getInstance());
}
return Value.asIterator(StringValue.makeStringValue(streetName));
}
};
}
示例8: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
public SequenceIterator call(SequenceIterator[] arguments,
XPathContext context) throws XPathException {
String postalCode = "";
String number = "";
String addition = "";
try {
postalCode = ((StringValue) arguments[0].next()).getStringValue();
number = ((StringValue) arguments[1].next()).getStringValue();
if (arguments.length == 3) {
addition = ((StringValue) arguments[2].next()).getStringValue();
}
} catch (Exception e) {
return Value.asIterator(EmptySequence.getInstance());
}
if (postalCode.length() > 0 && number.length() > 0) {
//addition may be empty sequence
String address = postalCode + number + addition;
address = address
.replaceAll("\\s+","")
.replaceAll("\\/+", "-")
.replaceAll("\\\\+", "-");
return Value.asIterator(StringValue.makeStringValue(address));
} else {
return Value.asIterator(EmptySequence.getInstance());
}
}
};
}
示例9: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
public SequenceIterator call(SequenceIterator[] arguments,
XPathContext context) throws XPathException {
boolean result = false;
try {
String str = ((StringValue) arguments[0].next()).getStringValue();
// TODO: are values > 1 also true?
result = (str.equals("1") || str.toLowerCase().equals("true")) ? true : false;
} catch (Exception e) {
return Value.asIterator(EmptySequence.getInstance());
}
return Value.asIterator(StringValue.makeStringValue(Boolean.toString(result)));
}
};
}
示例10: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
public SequenceIterator call(SequenceIterator[] arguments,
XPathContext context) throws XPathException {
String text = "";
try {
text = ((StringValue) arguments[0].next()).getStringValue();
if (text.length() == 1) {
text = text.toUpperCase();
} else {
text = text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase();
}
} catch (Exception e) {
return Value.asIterator(EmptySequence.getInstance());
}
return Value.asIterator(StringValue.makeStringValue(text));
}
};
}
示例11: makeCallExpression
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
public SequenceIterator call(SequenceIterator[] arguments,
XPathContext context) throws XPathException {
float number = 0;
try {
number = ((FloatValue) arguments[0].next()).getFloatValue();
} catch (NullPointerException e) {}
if (number == 0) {
return Value.asIterator(EmptySequence.getInstance());
} else {
return Value.asIterator(StringValue.makeStringValue(Float.toString(number)));
}
}
};
}
示例12: call
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
logger.info("call");
try{
final URL url = getURL(context, arguments[URL].head().getStringValue());
logger.info("url: " + url.toExternalForm());
final String viewString = arguments[VIEW].head().getStringValue();
logger.info("view: " + viewString);
if (viewString.equals("author")) {
workspace.open(url, EditorPageConstants.PAGE_AUTHOR);
} else if (viewString.equals("text")) {
workspace.open(url, EditorPageConstants.PAGE_TEXT);
} else {
throw new XPathException("The given view ('" + viewString + "') is invalid. It must be either 'author' or 'text'.");
}
} catch (Exception e) {
logger.error(e, e);
}
return EmptySequence.getInstance();
}
示例13: call
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
String sql = null;
try {
Connection con = ((ObjectValue<Connection>) arguments[0].head()).getObject();
sql = ((StringValue) arguments[1].head()).getStringValue();
Statement stmt = null;
ResultSet rset = null;
try {
stmt = con.createStatement();
rset = stmt.executeQuery(sql);
} catch (SQLException se) {
if (stmt != null) {
stmt.close();
}
throw se;
}
addCloseable(new CloseableAutoCloseableWrapper(stmt), context);
addCloseable(new CloseableAutoCloseableWrapper(rset), context);
return new ObjectValue<ResultSet>(rset);
} catch (Exception e) {
throw new XPathException("Error executing query \"" + sql + "\"", e);
}
}
示例14: call
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
String source = ((StringValue) arguments[0].head()).getStringValue();
String target = ((StringValue) arguments[1].head()).getStringValue();
try {
File sourceDir = new File(source);
if (!sourceDir.isDirectory()) {
throw new IOException("Source directory \"" + sourceDir.getAbsolutePath() + "\" not found");
}
File targetFile = new File(target);
if (targetFile.isDirectory()) {
throw new IOException("Output file \"" + targetFile.getAbsolutePath() + "\" already exists as directory");
} else if (targetFile.isFile() && FileUtils.deleteQuietly(targetFile)) {
throw new IOException("Could not delete existing output file \"" + targetFile.getAbsolutePath() + "\"");
} else if (!targetFile.getParentFile().isDirectory() && !targetFile.getParentFile().mkdirs()) {
throw new IOException("Could not create output directory \"" + targetFile.getParentFile().getAbsolutePath() + "\"");
}
ZipUtils.zipDirectory(sourceDir, targetFile);
return EmptySequence.getInstance();
} catch (IOException ioe) {
throw new XPathException("Error zipping \"" + source + "\" to \"" + target + "\"", ioe);
}
}
示例15: call
import net.sf.saxon.expr.XPathContext; //导入依赖的package包/类
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
final Processor processor = new Processor(context.getConfiguration());
final DocumentBuilder builder = processor.newDocumentBuilder();
try {
BuildingStreamWriterImpl writer = builder.newBuildingStreamWriter();
writer.writeStartElement("test1");
writer.writeCharacters("text1");
writer.writeEndElement();
writer.writeStartElement("test2");
writer.writeCharacters("text2");
writer.writeEndElement();
return writer.getDocumentNode().getUnderlyingValue();
} catch (SaxonApiException | XMLStreamException e) {
logger.error(e, e);
throw new XPathException("Failed to create return value: " + e.getMessage());
}
}