Java 类org.apache.tools.ant.util.JAXPUtils 实例源码

项目:ant    文件:AggregateTransformer.java   
/**
 * Get the systemid of the appropriate stylesheet based on its
 * name and styledir. If no styledir is defined it will load
 * it as a java resource in the xsl child package, otherwise it
 * will get it from the given directory.
 * @return system ID of the stylesheet.
 * @throws IOException thrown if the requested stylesheet does
 * not exist.
 */
protected String getStylesheetSystemId() throws IOException {
    String xslname = "junit-frames.xsl";
    if (NOFRAMES.equals(format)) {
        xslname = "junit-noframes.xsl";
    }
    if (styleDir == null) {
        URL url = getClass().getResource("xsl/" + xslname);
        if (url == null) {
            throw new FileNotFoundException("Could not find jar resource " + xslname);
        }
        return url.toExternalForm();
    }
    File file = new File(styleDir, xslname);
    if (!file.exists()) {
        throw new FileNotFoundException("Could not find file '" + file + "'");
    }
    return JAXPUtils.getSystemId(file);
}
项目:ant    文件:TraXLiaison.java   
/**
 * Get the source instance from the stream and id of the file.
 * @param is the stream containing the stylesheet data.
 * @param infile the file that will be used for the systemid.
 * @return the configured source instance matching the stylesheet.
 * @throws ParserConfigurationException if a parser cannot be created which
 * satisfies the requested configuration.
 * @throws SAXException in case of problem detected by the SAX parser.
 */
private Source getSource(final InputStream is, final File infile)
    throws ParserConfigurationException, SAXException {
    // todo: is this comment still relevant ??
    // FIXME: need to use a SAXSource as the source for the transform
    // so we can plug in our own entity resolver
    Source src = null;
    if (entityResolver != null) {
        if (getFactory().getFeature(SAXSource.FEATURE)) {
            final SAXParserFactory spFactory = SAXParserFactory.newInstance();
            spFactory.setNamespaceAware(true);
            final XMLReader reader = spFactory.newSAXParser().getXMLReader();
            reader.setEntityResolver(entityResolver);
            src = new SAXSource(reader, new InputSource(is));
        } else {
            throw new IllegalStateException("xcatalog specified, but "
                + "parser doesn't support SAX");
        }
    } else {
        // WARN: Don't use the StreamSource(File) ctor. It won't work with
        // xalan prior to 2.2 because of systemid bugs.
        src = new StreamSource(is);
    }
    src.setSystemId(JAXPUtils.getSystemId(infile));
    return src;
}
项目:ant    文件:ChangeLogWriterTest.java   
@Test
public void testNonUTF8Characters() throws Exception {
    CVSEntry entry = new CVSEntry(new Date(), "Se\u00f1orita", "2003 < 2004 && 3 > 5");
    entry.addFile("Medicare & review.doc", "1.1");
    entry.addFile("El\u00e8ments de style", "1.2");
    CVSEntry[] entries = {entry};

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintWriter pwriter = new PrintWriter(new OutputStreamWriter(output, "UTF-8"));
    writer.printChangeLog(pwriter, entries);

    // make sure that the parsing does not break
    XMLReader xmlReader = JAXPUtils.getXMLReader();
    InputStream input = new ByteArrayInputStream(output.toByteArray());
    xmlReader.setContentHandler(new NullContentHandler());
    xmlReader.parse(new InputSource(input));
}
项目:Push2Display    文件:RasterizerTask.java   
/**
 * Returns name of an XML parser.
 * Magic string {@link #JAXP_PARSER} is also accepted.
 *
 * @param className Name of the XML parser class or a magic string.
 *
 * @return Name of an XML parser.
 *
 * @throws BuildException Unable to get the name of JAXP parser.
 */
private String getParserClassName(final String className) {
    String name = className;
    if ((className == null) || className.equals(JAXP_PARSER)) {
        // Set first JAXP parser.
        // Throws BuildException.
        XMLReader reader = JAXPUtils.getXMLReader();
        name = reader.getClass().getName();
    }

    log("Using class '" + name + "' to parse SVG documents.", Project.MSG_VERBOSE);
    return name;
}
项目:Push2Display    文件:RasterizerTask.java   
/**
 * Returns name of an XML parser.
 * Magic string {@link #JAXP_PARSER} is also accepted.
 *
 * @param className Name of the XML parser class or a magic string.
 *
 * @return Name of an XML parser.
 *
 * @throws BuildException Unable to get the name of JAXP parser.
 */
private String getParserClassName(final String className) {
    String name = className;
    if ((className == null) || className.equals(JAXP_PARSER)) {
        // Set first JAXP parser.
        // Throws BuildException.
        XMLReader reader = JAXPUtils.getXMLReader();
        name = reader.getClass().getName();
    }

    log("Using class '" + name + "' to parse SVG documents.", Project.MSG_VERBOSE);
    return name;
}
项目:ant    文件:Diagnostics.java   
private static String getNamespaceParserName() {
    try {
        XMLReader reader = JAXPUtils.getNamespaceXMLReader();
        return reader.getClass().getName();
    } catch (BuildException e) {
        //ignore
        ignoreThrowable(e);
        return null;
    }
}
项目:ant    文件:Diagnostics.java   
private static String getNamespaceParserLocation() {
    try {
        XMLReader reader = JAXPUtils.getNamespaceXMLReader();
        URL location = getClassLocation(reader.getClass());
        return location != null ? location.toString() : null;
    } catch (BuildException e) {
        //ignore
        ignoreThrowable(e);
        return null;
    }
}
项目:ant    文件:XMLValidateTask.java   
/**
 * Returns a SAX-based XMLReader or a SAX-based Parser.
 * @return reader or parser
 */
private Object createDefaultReaderOrParser() {
    Object reader;
    try {
        reader = createDefaultReader();
    } catch (BuildException exc) {
        reader = JAXPUtils.getParser();
    }
    return reader;
}
项目:ant    文件:TraXLiaison.java   
/**
 * Transform an input file.
 * @param infile the file to transform
 * @param outfile the result file
 * @throws Exception on error
 */
public void transform(final File infile, final File outfile) throws Exception {
    if (transformer == null) {
        createTransformer();
    }

    InputStream fis = null;
    OutputStream fos = null;
    try {
        fis = new BufferedInputStream(Files.newInputStream(infile.toPath()));
        fos = new BufferedOutputStream(Files.newOutputStream(outfile.toPath()));
        final StreamResult res = new StreamResult(fos);
        // not sure what could be the need of this...
        res.setSystemId(JAXPUtils.getSystemId(outfile));
        final Source src = getSource(fis, infile);

        // set parameters on each transformation, maybe something has changed
        //(e.g. value of file name parameter)
        setTransformationParameters();

        transformer.transform(src, res);
    } finally {
        // make sure to close all handles, otherwise the garbage
        // collector will close them...whenever possible and
        // Windows may complain about not being able to delete files.
        FileUtils.close(fis);
        FileUtils.close(fos);
    }
}
项目:ant    文件:DOMUtilTest.java   
@Test
public void testListChildNodes() throws SAXException, IOException {
    DocumentBuilder db = JAXPUtils.getDocumentBuilder();
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("taskdefs/optional/junit/matches.xml");
    Document doc = db.parse(is);
    NodeList nl = DOMUtil.listChildNodes(doc.getDocumentElement(), new FooNodeFilter(), true);
    assertEquals("expecting 3", 3, nl.getLength());
}
项目:ant    文件:TraXLiaisonTest.java   
@Test
public void testSystemId() {
    File file = null;
    if (File.separatorChar == '\\') {
        file = new File("d:\\jdk");
    } else {
        file = new File("/user/local/bin");
    }
    String systemid = JAXPUtils.getSystemId(file);
    assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/"));
    assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////"));
}
项目:ant    文件:ParserSupports.java   
/**
 * Get our reader
 * @return a reader
 */
private XMLReader getReader() {
    JAXPUtils.getParser();
    return JAXPUtils.getXMLReader();
}
项目:ant    文件:XMLCatalogTest.java   
private static String toURLString(File file) throws MalformedURLException {
    return JAXPUtils.getSystemId(file);
}
项目:ant    文件:XMLValidateTask.java   
/**
 * Create a reader if the use of the class did not specify another one.
 * If a BuildException is thrown, the caller may revert to an alternate
 * reader.
 * @return a new reader.
 * @throws BuildException if something went wrong
 */
protected XMLReader createDefaultReader() {
    return JAXPUtils.getXMLReader();
}
项目:ant    文件:TraXLiaison.java   
/**
 * @param file the filename to use for the systemid
 * @return the systemid
 * @deprecated since 1.5.x.
 *             Use org.apache.tools.ant.util.JAXPUtils#getSystemId instead.
 */
@Deprecated
protected String getSystemId(final File file) {
    return JAXPUtils.getSystemId(file);
}