当前位置: 首页>>代码示例>>Java>>正文


Java Sequence类代码示例

本文整理汇总了Java中net.sf.saxon.om.Sequence的典型用法代码示例。如果您正苦于以下问题:Java Sequence类的具体用法?Java Sequence怎么用?Java Sequence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Sequence类属于net.sf.saxon.om包,在下文中一共展示了Sequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeCallExpression

import net.sf.saxon.om.Sequence; //导入依赖的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));
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:MyExtensionFunction2.java

示例2: makeCallExpression

import net.sf.saxon.om.Sequence; //导入依赖的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));
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:MyExtensionFunction1.java

示例3: makeCallExpression

import net.sf.saxon.om.Sequence; //导入依赖的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 + "]");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XQueryWithExtensionTest.java

示例4: getStringValue

import net.sf.saxon.om.Sequence; //导入依赖的package包/类
@Nullable
public static String getStringValue(@Nullable Sequence seq) {
    if (seq == null) {
        return null;
    }

    if (seq instanceof AtomicValue) {
        return ((AtomicValue) seq).getStringValue();
    } else if (seq instanceof Item) {
        return ((Item) seq).getStringValue();
    } else {
        try {
            SequenceIterator seqIterator = seq.iterate();
            StrBuilder builder = new StrBuilder();
            Item seqItem;

            while ((seqItem = seqIterator.next()) != null) {
                Optional.ofNullable(getStringValue(seqItem)).ifPresent(builder::append);
            }

            return builder.build();
        } catch (XPathException e) {
            throw new SaxonApiUncheckedException(e);
        }
    }
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:27,代码来源:SdcctXdmUtils.java

示例5: getStringValueOrNull

import net.sf.saxon.om.Sequence; //导入依赖的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;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:16,代码来源:FunctionUtils.java

示例6: getBooleanValue

import net.sf.saxon.om.Sequence; //导入依赖的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;
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:30,代码来源:FunctionUtils.java

示例7: getIntegerValueOrNull

import net.sf.saxon.om.Sequence; //导入依赖的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;
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:26,代码来源:FunctionUtils.java

示例8: getPath

import net.sf.saxon.om.Sequence; //导入依赖的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();
	}
}
 
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:18,代码来源:AncestorPathCall.java

示例9: call2

import net.sf.saxon.om.Sequence; //导入依赖的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();
}
 
开发者ID:dita-semia,项目名称:XsltGui,代码行数:17,代码来源:GuiTest.java

示例10: call

import net.sf.saxon.om.Sequence; //导入依赖的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);
	}
}
 
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:21,代码来源:GetKeyRefDisplaySuffixCall.java

示例11: call

import net.sf.saxon.om.Sequence; //导入依赖的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);
  }
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:22,代码来源:RegisterTempFile.java

示例12: generateHtml

import net.sf.saxon.om.Sequence; //导入依赖的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;
}
 
开发者ID:dita-semia,项目名称:XsltGui,代码行数:24,代码来源:GuiHtmlDialog.java

示例13: call

import net.sf.saxon.om.Sequence; //导入依赖的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);
  }

}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:25,代码来源:Zip.java

示例14: serialize

import net.sf.saxon.om.Sequence; //导入依赖的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);
  }
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:20,代码来源:ExtensionFunctionCall.java

示例15: sequenceToAttributeCollection

import net.sf.saxon.om.Sequence; //导入依赖的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;
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:23,代码来源:ExtensionFunctionCall.java


注:本文中的net.sf.saxon.om.Sequence类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。