本文整理匯總了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);
}