本文整理了Java中javax.xml.transform.Transformer.setParameter()
方法的一些代码示例,展示了Transformer.setParameter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transformer.setParameter()
方法的具体详情如下:
包路径:javax.xml.transform.Transformer
类名称:Transformer
方法名:setParameter
[英]Add a parameter for the transformation.
Pass a qualified name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.
For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.
[中]为转换添加一个参数。
将限定名称作为两部分字符串传递,名称空间URI用大括号({})括起来,后跟本地名称。如果名称的URL为空,则字符串仅包含本地名称。应用程序可以通过测试名称的第一个字符是否为“{”字符来安全地检查非空URI。
例如,如果从使用<xyz:foo xmlns:xyz=”定义的元素中获取URI和本地名称http://xyz.foo.com/yada/baz.html“/>,则限定名为”{http://xyz.foo.com/yada/baz.html}注意,没有使用前缀。
代码示例来源:origin: org.apache.ant/ant
/**
* Sets the parameters for the transformer.
*/
private void setTransformationParameters() {
params.forEach((key, value) -> transformer.setParameter(key, value));
}
代码示例来源:origin: kiegroup/jbpm
public static void transform(String stylesheet,
Source src,
Result res,
HashMap<String, String> params) throws Exception {
Transformer transformer = getTransformer( stylesheet );
transformer.clearParameters();
if ( params != null && params.size() > 0 ) {
Iterator<String> itKeys = params.keySet().iterator();
while ( itKeys.hasNext() ) {
String key = itKeys.next();
String value = params.get( key );
transformer.setParameter( key,
value );
}
}
transformer.transform( src,
res );
}
代码示例来源:origin: apache/nifi
@Override
public void process(final InputStream rawIn, final OutputStream out) throws IOException {
try (final InputStream in = new BufferedInputStream(rawIn)) {
final Templates templates;
if (cache != null) {
templates = cache.get(path);
} else {
templates = newTemplates(context, path);
}
final Transformer transformer = templates.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, (indentOutput ? "yes" : "no"));
// pass all dynamic properties to the transformer
for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
if (entry.getKey().isDynamic()) {
String value = context.newPropertyValue(entry.getValue()).evaluateAttributeExpressions(original).getValue();
transformer.setParameter(entry.getKey().getName(), value);
}
}
// use a StreamSource with Saxon
StreamSource source = new StreamSource(in);
StreamResult result = new StreamResult(out);
transformer.transform(source, result);
} catch (final Exception e) {
throw new IOException(e);
}
}
});
代码示例来源:origin: xalan/xalan
Object key = entry.getKey();
Object expression = entry.getValue();
transformer.setParameter((String) key, expression);
代码示例来源:origin: plutext/docx4j
log.warn("parameter '" + pairs.getKey() + "' was null.");
} else {
xformer.setParameter((String) pairs.getKey(), pairs
.getValue());
代码示例来源:origin: marytts/marytts
transformer.setParameter("voice", d.getDefaultVoice().getName());
代码示例来源:origin: marytts/marytts
transformer.setParameter("voice", d.getDefaultVoice().getName());
代码示例来源:origin: xalan/xalan
transformer.setParameter((String) params.elementAt(i),
(String) params.elementAt(i + 1));
代码示例来源:origin: xalan/xalan
avt = ((ElemLiteralResult)paramNode).getLiteralResultAttribute("value");
String pValue = avt.evaluate(xctxt,xt, elem);
trans.setParameter(pName, pValue);
代码示例来源:origin: pentaho/pentaho-kettle
xformer.setParameter( nameOfParams[i], valueOfParams[i] );
代码示例来源:origin: pentaho/pentaho-kettle
transformer.setParameter( data.nameOfParams[i], row[data.indexOfParams[i]] );
代码示例来源:origin: spring-projects/spring-integration
try {
Object value = expression.getValue(this.evaluationContext, message);
transformer.setParameter(parameterName, value);
String headerName = entry.getKey();
if (PatternMatchUtils.simpleMatch(this.xsltParamHeaders, headerName)) {
transformer.setParameter(headerName, entry.getValue());
代码示例来源:origin: jamesagnew/hapi-fhir
public static void saxonTransform(String xsltDir, String source, String xslt, String dest, URIResolver alt, Map<String, String> params) throws FileNotFoundException, TransformerException {
TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl();
f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE);
StreamSource xsrc = new StreamSource(new FileInputStream(xslt));
f.setURIResolver(new MyURIResolver(xsltDir, alt));
Transformer t = f.newTransformer(xsrc);
if (params != null) {
for (Map.Entry<String, String> entry : params.entrySet()) {
t.setParameter(entry.getKey(), entry.getValue());
}
}
t.setURIResolver(new MyURIResolver(xsltDir, alt));
StreamSource src = new StreamSource(new FileInputStream(source));
StreamResult res = new StreamResult(new FileOutputStream(dest));
t.transform(src, res);
}
代码示例来源:origin: pentaho/mondrian
String value = namevalueParameters[i][1];
transformer.setParameter(name, value);
代码示例来源:origin: pentaho/mondrian
/**
* This can be extened to have a map from publicId/systemId
* to InputSource.
*/
public static class Resolver implements EntityResolver {
private InputSource source;
protected Resolver() {
this((InputSource) null);
}
public Resolver(Document doc) {
this(XmlUtil.toString(doc, false));
}
public Resolver(String str) {
this(new InputSource(new StringReader(str)));
}
public Resolver(InputSource source) {
this.source = source;
}
public InputSource resolveEntity(
String publicId,
String systemId)
throws SAXException, IOException
{
return source;
}
}
代码示例来源:origin: org.jboss.spec.javax.servlet.jstl/jboss-jstl-api_1.2_spec
/**
* Sets (adds) a transformation parameter on our transformer.
*/
public void addParameter(String name, Object value) {
t.setParameter(name, value);
}
代码示例来源:origin: stackoverflow.com
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
Result xmlResult = new StreamResult(resultFile);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
// Load Parameters if we have any
if (ParameterMap != null) {
for (Entry<String, String> curParam : ParameterMap.entrySet()) {
trans.setParameter(curParam.getKey(), curParam.getValue());
}
}
trans.transform(xmlSource, xmlResult);
代码示例来源:origin: apache/cxf
public Transformer newTransformer() throws TransformerConfigurationException {
Transformer tr = templates.newTransformer();
tr.setURIResolver(resolver);
for (Map.Entry<String, Object> entry : transformParameters.entrySet()) {
tr.setParameter(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : outProps.entrySet()) {
tr.setOutputProperty(entry.getKey(), entry.getValue());
}
return tr;
}
代码示例来源:origin: apache/cxf
private String transformLocally(Message m, UriInfo ui, Source source) throws Exception {
InputStream is = ResourceUtils.getResourceStream(stylesheetReference, m.getExchange().getBus());
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer t = transformerFactory.newTemplates(new StreamSource(is)).newTransformer();
t.setParameter("base.path", m.get("http.base.path"));
StringWriter stringWriter = new StringWriter();
t.transform(source, new StreamResult(stringWriter));
return stringWriter.toString();
}
代码示例来源:origin: org.apache.cxf/cxf-rt-rs-service-description
private String transformLocally(Message m, UriInfo ui, Source source) throws Exception {
InputStream is = ResourceUtils.getResourceStream(stylesheetReference, m.getExchange().getBus());
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer t = transformerFactory.newTemplates(new StreamSource(is)).newTransformer();
t.setParameter("base.path", m.get("http.base.path"));
StringWriter stringWriter = new StringWriter();
t.transform(source, new StreamResult(stringWriter));
return stringWriter.toString();
}
内容来源于网络,如有侵权,请联系作者删除!