本文整理汇总了Java中net.sf.saxon.value.StringValue.makeStringValue方法的典型用法代码示例。如果您正苦于以下问题:Java StringValue.makeStringValue方法的具体用法?Java StringValue.makeStringValue怎么用?Java StringValue.makeStringValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.value.StringValue
的用法示例。
在下文中一共展示了StringValue.makeStringValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
StringWriter sw = new StringWriter();
JsonXMLConfig config = new JsonXMLConfigBuilder().
prettyPrint(true).
build();
XMLOutputFactory jFactory = new JsonXMLOutputFactory(config);
TransformerFactory tFactory = new TransformerFactoryImpl();
try {
SequenceIterator iter = arguments[0].iterate();
Item item;
while ((item = iter.next()) != null) {
if (item instanceof NodeInfo) {
Transformer transformer = tFactory.newTransformer();
XMLStreamWriter xsw = jFactory.createXMLStreamWriter(sw);
transformer.transform((NodeInfo) item, new StAXResult(xsw));
} else {
sw.append(item.getStringValue());
}
}
} catch (Exception e) {
throw new XPathException("Error serializing sequence to JSON", e);
}
return StringValue.makeStringValue(sw.toString());
}
示例2: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String queueName = ((StringValue) arguments[0].head()).getStringValue();
String path = ((StringValue) arguments[1].head()).getStringValue();
String extraInfo = arguments.length > 2 ? serialize((NodeInfo) arguments[2].head()) : null;
WebApp webApp = getWebApp(context);
ExecutorService service = webApp.getExecutorService(queueName);
String ticket = UUID.randomUUID().toString();
File queueDir = Context.getInstance().getQueueDir();
if (!queueDir.isDirectory() && !queueDir.mkdirs())
throw new IOException("Could not create queue directory \"" + queueDir.getAbsolutePath() + "\"");
File lockFile = new File(queueDir, ticket + ".lck");
FileUtils.touch(lockFile);
try {
service.execute(new QueuedRequest(ticket, webApp.getPath() + "/" + path, extraInfo));
} catch (RejectedExecutionException ree) {
FileUtils.deleteQuietly(lockFile);
return StringValue.makeStringValue("rejected");
}
return StringValue.makeStringValue(ticket);
} catch (IOException e) {
throw new XPathException("Error adding asynchronous request", e);
}
}
示例3: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String str = ((StringValue) arguments[0].head()).getStringValue();
return StringValue.makeStringValue(Base64.encodeBase64String(str.getBytes("UTF-8")));
} catch (Exception e) {
throw new XPathException("Could not base64 encode string", e);
}
}
示例4: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String str = ((StringValue) arguments[0].head()).getStringValue();
return StringValue.makeStringValue(new String(Base64.decodeBase64(str), "UTF-8"));
} catch (Exception e) {
throw new XPathException("Could not base64 decode string", e);
}
}
示例5: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
Properties props = null;
if (arguments.length == 2) {
props = getOutputProperties((NodeInfo) arguments[1].head());
}
StringWriter sw = new StringWriter();
serialize(arguments[0], sw, props);
return StringValue.makeStringValue(sw.toString());
}
示例6: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String prefix = ((StringValue) arguments[0].head()).getStringValue();
String suffix = ((StringValue) arguments[1].head()).getStringValue();
File dir = null;
if (arguments.length == 3) {
dir = getFile(((StringValue) arguments[2].head()).getStringValue());
}
File temp;
if (dir == null) {
temp = File.createTempFile(prefix, suffix);
} else {
if (dir.exists() || dir.isFile()) {
throw new FileException(String.format("Specified directory \"%s\" does not exist or points to a file",
dir.getAbsolutePath()), FileException.ERROR_PATH_NOT_DIRECTORY);
}
temp = File.createTempFile(prefix, suffix, dir);
}
temp.deleteOnExit();
return StringValue.makeStringValue(temp.getCanonicalPath());
} catch (FileException fe) {
throw fe;
} catch (Exception e) {
throw new FileException("Other file error", e, FileException.ERROR_IO);
}
}
示例7: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String prefix = ((StringValue) arguments[0].head()).getStringValue();
String suffix = ((StringValue) arguments[1].head()).getStringValue();
File dir = null;
if (arguments.length == 3) {
dir = getFile(((StringValue) arguments[2].head()).getStringValue());
}
File test;
if (dir == null) {
test = File.createTempFile(prefix, suffix);
} else {
if (dir.isFile()) {
throw new FileException(String.format("Specified directory \"%s\" points to an existing file",
dir.getAbsolutePath()), FileException.ERROR_PATH_EXISTS);
}
test = File.createTempFile(prefix, suffix, dir);
}
String path = test.getCanonicalPath();
test.delete();
File temp = new File(path);
temp.mkdirs();
temp.deleteOnExit();
return StringValue.makeStringValue(temp.getCanonicalPath());
} catch (FileException fe) {
throw fe;
} catch (Exception e) {
throw new FileException("Other file error", e, FileException.ERROR_IO);
}
}
示例8: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String path = ((StringValue) arguments[0].head()).getStringValue();
if ((path.equals("/")) || (path.equals(""))) {
return StringValue.makeStringValue("");
}
File file = getFile(path);
return StringValue.makeStringValue(file.getName());
} catch (FileException fe) {
throw fe;
} catch (Exception e) {
throw new FileException("Other file error", e, FileException.ERROR_IO);
}
}
示例9: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
String ticket = ((StringValue) arguments[0].head()).getStringValue();
File queueDir = Context.getInstance().getQueueDir();
String status = "notfound";
if (StringUtils.equals("rejected", ticket))
status = "rejected";
else if (new File(queueDir, ticket + ".lck").isFile())
status = "processing";
else if (new File(queueDir, ticket + ".err").isFile())
status = "error";
else if (new File(queueDir, ticket + ".bin").isFile())
status = "available";
return StringValue.makeStringValue(status);
}
示例10: makeCallExpression
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
@Override
public Sequence call(XPathContext context, Sequence[] pArguments)
throws XPathException {
try {
String lValueToEncode = FunctionUtils.getStringValueOrNull(pArguments, 0, FUNCTION_NAME);
if(XFUtil.isNull(lValueToEncode)) {
throw new ExInternal("Value to encode cannot be null or empty");
}
//Padding is on by default
boolean lPad = true;
if(pArguments.length > 1) {
lPad = FunctionUtils.getBooleanValue(pArguments, 1);
}
//Separator gap size and character sequence
int lSeparateEvery = 0;
if(pArguments.length > 2) {
Integer lIntValue = FunctionUtils.getIntegerValueOrNull(pArguments, 2);
lSeparateEvery = lIntValue == null ? 0 : lIntValue;
}
String lSeparator = " ";
if(pArguments.length > 3) {
lSeparator = XFUtil.nvl(FunctionUtils.getStringValueOrNull(pArguments, 3, FUNCTION_NAME, false));
}
//Set up Guava encoder
BaseEncoding lEncoder = BaseEncoding.base32();
if (!lPad) {
lEncoder = lEncoder.omitPadding();
}
if (lSeparateEvery > 0) {
lEncoder = lEncoder.withSeparator(lSeparator, lSeparateEvery);
}
//Encode UTF-8 string bytes
String lResult;
try {
lResult = lEncoder.encode(lValueToEncode.getBytes("UTF-8"));
}
catch (UnsupportedEncodingException e) {
throw new ExInternal("Failed to get bytes to encode", e);
}
return StringValue.makeStringValue(lResult);
}
catch (Throwable th) {
throw new ExInternal("Error executing encode-base32 function", th);
}
}
};
}
示例11: makeCallExpression
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
@Override
public Sequence call(XPathContext pXPathContext, Sequence[] pArguments)
throws XPathException {
try {
//First argument is plugin name (mandatory string)
String lPluginName = FunctionUtils.getStringValueOrNull(pArguments, 0, FUNCTION_NAME, true);
if(XFUtil.isNull(lPluginName)) {
throw new ExInternal("First parameter must be a non-empty string.");
}
//Second argument is endpoint name (mandatory string)
String lEndPointName = FunctionUtils.getStringValueOrNull(pArguments, 1, FUNCTION_NAME, true);
if(XFUtil.isNull(lEndPointName)) {
throw new ExInternal("Second parameter must be a non-empty string.");
}
//Construct URI param map (linked to preserve order)
Map<String, String> lParams = new LinkedHashMap<>();
if(pArguments.length > 2) {
if(pArguments.length % 2 != 0) {
throw new ExInternal("Parameter list length mismatch. " + paramDebugMessage(pArguments));
}
for(int i = 2; i < pArguments.length; i = i+2) {
String lParamName = FunctionUtils.getStringValueOrNull(pArguments, i, FUNCTION_NAME, true);
String lParamValue = FunctionUtils.getStringValueOrNull(pArguments, i + 1, FUNCTION_NAME, false);
//Basic validation
if(XFUtil.isNull(lParamName)) {
throw new ExInternal("Parameter names cannot be null (index " + i + "). " + paramDebugMessage(pArguments));
}
else if(XFUtil.isNull(lParamValue)) {
//Don't fail but warn
Track.alert("PluginURIFunction", "Value for parameter " + lParamName + " was null, parameter will be excluded from URI");
}
lParams.put(lParamName, lParamValue);
}
}
//Build URI
RequestURIBuilder lURIBuilder = SaxonEnvironment.getThreadLocalRequestContext().createURIBuilder();
lURIBuilder.setParams(lParams);
String lURI = lURIBuilder.buildWebServiceURI(PluginWebServiceCategory.CATEGORY_NAME, lPluginName, lEndPointName);
return StringValue.makeStringValue(lURI);
}
catch (Throwable th) {
throw new ExInternal("Error running fox:plugin-uri function", th);
}
}
};
}
示例12: makeCallExpression
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
@Override
public Sequence call(XPathContext pXPathContext, Sequence[] pArguments)
throws XPathException {
ActionRequestContext lRequestContext = SaxonEnvironment.getThreadLocalRequestContext();
Item lItemNodeOrStringParam = pArguments[0].head();
//First argument can be a string or node - work out which.
DOM lItemDOM = null;
String lItemMapSetName = null;
String lItemMapSetAttach = null;
String lDataString = null;
if(lItemNodeOrStringParam instanceof StringValue) {
lDataString = lItemNodeOrStringParam.getStringValue();
}
else if(lItemNodeOrStringParam instanceof XOMNodeWrapper) {
//For nodes we can attempt to look up the mapset attribute on the NodeInfo
lItemDOM = FunctionUtils.unwrapNode((XOMNodeWrapper) lItemNodeOrStringParam);
if(lItemDOM != null) {
lItemMapSetName = lRequestContext.getCurrentModule().getNodeInfoDefaultAttribute(lItemDOM, NodeAttribute.MAPSET);
lItemMapSetAttach = lRequestContext.getCurrentModule().getNodeInfoDefaultAttribute(lItemDOM, NodeAttribute.MAPSET_ATTACH);
}
}
else {
throw new ExInternal("First argument to fox:mapset-key must be a node or string.");
}
//The mapset name could have been explicitly passed in as an argument
String lMapSetNameParam = FunctionUtils.getStringValueOrNull(pArguments, 1, "fox:mapset-key");
//Work out which mapset name to use - give precedence to the explicit argument, falling back to the value on the NodeInfo (if available)
String lUseMapSetName = XFUtil.nvl(lMapSetNameParam, lItemMapSetName);
if(XFUtil.isNull(lUseMapSetName)) {
throw new ExInternal("fox:mapset-key function failed to determine mapset name - explicitly specify a name as the second argument of this function," +
"or ensure an element with a corresponding schema definition is supplied as the first argument.");
}
//Resolve the attach node if specified
DOM lMapSetAttachDOM = FunctionUtils.getDOMNodeOrNull(pArguments, 2, "fox:mapset-key");
//Resolve the mapset from the current module call and look up the key
MapSet lMapSet;
if(lMapSetAttachDOM != null) {
//Use the attach DOM variant if an attach DOM was explicitly specified as an argument
lMapSet = lRequestContext.resolveMapSet(lUseMapSetName, lItemDOM, lMapSetAttachDOM);
}
else {
//Otherwise use the attach XPath string variant
lMapSet = lRequestContext.resolveMapSet(lUseMapSetName, lItemDOM, lItemMapSetAttach);
}
String lKey;
if(lItemDOM != null) {
//If we have a data DOM reference use that for the mapset lookup (required for complex mapsets)
lKey = lMapSet.getKey(lRequestContext, lItemDOM);
}
else {
//If we just have a string use that
lKey = lMapSet.getKeyForDataString(lRequestContext, lMapSetAttachDOM, lDataString);
}
//Wrap result and return
return StringValue.makeStringValue(lKey);
}
};
}
示例13: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
return StringValue.makeStringValue(java.util.UUID.randomUUID().toString());
}
示例14: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
String url = ((StringValue) arguments[0].head()).getStringValue();
return StringValue.makeStringValue(getResponse(context).encodeURL(url));
}
示例15: call
import net.sf.saxon.value.StringValue; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
String url = ((StringValue) arguments[0].head()).getStringValue();
return StringValue.makeStringValue(getResponse(context).encodeRedirectURL(url));
}