本文整理汇总了Java中javax.xml.transform.Source.setSystemId方法的典型用法代码示例。如果您正苦于以下问题:Java Source.setSystemId方法的具体用法?Java Source.setSystemId怎么用?Java Source.setSystemId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.transform.Source
的用法示例。
在下文中一共展示了Source.setSystemId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSchema
import javax.xml.transform.Source; //导入方法依赖的package包/类
@Override
protected Schema getSchema(Model model) {
if (! (model instanceof WSDLModel)) {
return null;
}
InputStream wsdlSchemaInputStream = WSDLSchemaValidator.class.getResourceAsStream(wsdlXSDUrl);
Source wsdlSource = new StreamSource(wsdlSchemaInputStream);
wsdlSource.setSystemId(WSDLSchemaValidator.class.getResource(wsdlXSDUrl).toString());
//combine all possible schemas through ElementFactoryProvider mechanism
Collection<ValidatorSchemaFactory> extSchemaFactories = ValidatorSchemaFactoryRegistry.getDefault().getAllValidatorSchemaFactories();
ArrayList<Source> isList = new ArrayList<Source>();
isList.add(wsdlSource);
for (ValidatorSchemaFactory factory : extSchemaFactories) {
Source is = factory.getSchemaSource();
if(is != null) {
isList.add(is);
} else {
//any validator should not return a null input stream
Logger.getLogger(getClass().getName()).severe("getSchema: " + factory.getClass() +" returned null input stream for its schema");
}
}
Schema schema = getCompiledSchema(isList.toArray(new Source[isList.size()]), new CentralLSResourceResolver(extSchemaFactories), new SchemaErrorHandler());
return schema;
}
示例2: validateDocument
import javax.xml.transform.Source; //导入方法依赖的package包/类
protected void validateDocument() throws Exception {
Source source = new DOMSource(fDocument);
source.setSystemId(fDocumentURL.toExternalForm());
Result result = new DOMResult(fDocument);
fValidator.validate(source, result);
}
示例3: testDOMSource
import javax.xml.transform.Source; //导入方法依赖的package包/类
@Test
public final void testDOMSource() {
String xml = getClass().getResource("SourceTest.xml").getFile();
xml = "file://" + xml;
File xsl = new File(getClass().getResource("SourceTest.xsl").getFile());
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
StreamSource source = new StreamSource(xsl);
transformer = tFactory.newTransformer(source);
// the xml result
StringWriter xmlResultString = new StringWriter();
StreamResult xmlResultStream = new StreamResult(xmlResultString);
Source xmlSource = new DOMSource();
xmlSource.setSystemId(xml);
transformer.transform(xmlSource, xmlResultStream);
System.out.println(xmlResultString.toString());
String temp = xmlResultString.toString();
int pos = temp.lastIndexOf("count");
if (temp.substring(pos + 8, pos + 9).equals("1")) {
Assert.fail("count=1");
} else if (temp.substring(pos + 8, pos + 9).equals("2")) {
// expected success
System.out.println("count=2");
}
} catch (Exception e) {
// unexpected failure
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例4: testSAXSource
import javax.xml.transform.Source; //导入方法依赖的package包/类
@Test
public final void testSAXSource() {
String xml = getClass().getResource("SourceTest.xml").getFile();
File xsl = new File(getClass().getResource("SourceTest.xsl").getFile());
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
StreamSource source = new StreamSource(xsl);
transformer = tFactory.newTransformer(source);
// the xml result
StringWriter xmlResultString = new StringWriter();
StreamResult xmlResultStream = new StreamResult(xmlResultString);
Source xmlSource = new SAXSource();
xmlSource.setSystemId(xml);
transformer.transform(xmlSource, xmlResultStream);
System.out.println(xmlResultString.toString());
String temp = xmlResultString.toString();
int pos = temp.lastIndexOf("count");
if (temp.substring(pos + 8, pos + 9).equals("1")) {
Assert.fail("count=1");
} else if (temp.substring(pos + 8, pos + 9).equals("2")) {
// expected success
System.out.println("count=2");
}
} catch (Exception e) {
// unexpected failure
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例5: testStreamSource
import javax.xml.transform.Source; //导入方法依赖的package包/类
@Test
public final void testStreamSource() {
String xml = getClass().getResource("SourceTest.xml").getFile();
File xsl = new File(getClass().getResource("SourceTest.xsl").getFile());
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
StreamSource source = new StreamSource(xsl);
transformer = tFactory.newTransformer(source);
// the xml result
StringWriter xmlResultString = new StringWriter();
StreamResult xmlResultStream = new StreamResult(xmlResultString);
Source xmlSource = new StreamSource();
xmlSource.setSystemId(xml);
transformer.transform(xmlSource, xmlResultStream);
System.out.println(xmlResultString.toString());
String temp = xmlResultString.toString();
int pos = temp.lastIndexOf("count");
if (temp.substring(pos + 8, pos + 9).equals("1")) {
Assert.fail("count=1");
} else if (temp.substring(pos + 8, pos + 9).equals("2")) {
// expected success
System.out.println("count=2");
}
} catch (Exception e) {
// unexpected failure
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例6: validateFragment
import javax.xml.transform.Source; //导入方法依赖的package包/类
protected void validateFragment() throws Exception {
Source source = new DOMSource((Node) fRootNode);
source.setSystemId(fDocumentURL.toExternalForm());
Result result = new DOMResult((Node) fRootNode);
fValidator.validate(source, result);
}