Example usage for javax.xml.transform SourceLocator getPublicId

List of usage examples for javax.xml.transform SourceLocator getPublicId

Introduction

In this page you can find the example usage for javax.xml.transform SourceLocator getPublicId.

Prototype

public String getPublicId();

Source Link

Document

Return the public identifier for the current document event.

Usage

From source file:Main.java

public static void xsl(String inFilename, String outFilename, String xslFilename) {
    try {/*from   www  .  jav a 2 s  .  c  om*/
        TransformerFactory factory = TransformerFactory.newInstance();
        Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
        Transformer xformer = template.newTransformer();
        Source source = new StreamSource(new FileInputStream(inFilename));
        Result result = new StreamResult(new FileOutputStream(outFilename));
        xformer.transform(source, result);
    } catch (FileNotFoundException e) {
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
        SourceLocator locator = e.getLocator();
        int col = locator.getColumnNumber();
        int line = locator.getLineNumber();
        String publicId = locator.getPublicId();
        String systemId = locator.getSystemId();
    }
}

From source file:org.apache.cocoon.util.TraxErrorHandler.java

private String getMessage(TransformerException exception) {
    SourceLocator locator = exception.getLocator();
    if (locator != null) {
        String id = (!locator.getPublicId().equals(locator.getPublicId())) ? locator.getPublicId()
                : (null != locator.getSystemId()) ? locator.getSystemId() : "SystemId Unknown";
        return "File " + id + "; Line " + locator.getLineNumber() + "; Column " + locator.getColumnNumber()
                + "; " + exception.getMessage();
    }/*from  w w w.  ja va  2s. com*/
    return exception.getMessage();
}

From source file:org.directwebremoting.drapgen.generate.gi.GiType.java

/**
 * @param preprocXslt The preprocessor XSLT
 *
 *//* w  ww .ja  va2s  .  c  o m*/
public void cloneForOverloading(String preprocXslt) {
    try {
        // Read the XSLT
        if (preprocessTemplate == null) {
            Source xslSource = new StreamSource(new File(preprocXslt));
            preprocessTemplate = factory.newTemplates(xslSource);
        }

        Source xmlSource = new DOMSource(document);

        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Document newDocument = builder.newDocument();
        Result result = new DOMResult(newDocument);

        Transformer preprocessor = preprocessTemplate.newTransformer();
        preprocessor.transform(xmlSource, result);
        document = newDocument;
    } catch (TransformerException ex) {
        SourceLocator locator = ex.getLocator();
        log.warn("Line: " + locator.getLineNumber() + ", Column: " + locator.getColumnNumber());
        log.warn("PublicId: " + locator.getPublicId());
        log.warn("SystemId: " + locator.getSystemId());
        log.error("Failed to transform", ex);
    } catch (Exception ex) {
        log.warn("Processing Error for " + xmlFile.getAbsolutePath(), ex);
    }
}

From source file:org.directwebremoting.drapgen.generate.gi.GiType.java

/**
 * @param templateDir The base directory for the templates
 * @param defaultTemplate The extra path (from templateDir) to the default
 *
 *///from w  w w  .j  a v  a  2s. c o m
public void transform(String templateDir, String defaultTemplate) {
    try {
        File templateFile = new File(templateDir + xmlClassName.replaceFirst("\\.xml$", ".xslt"));
        if (!templateFile.canRead()) {
            templateFile = new File(templateDir + defaultTemplate);
        }

        // Read the XSLT
        Source xslSource = new StreamSource(templateFile);

        Templates template = templatesCache.get(templateFile);
        if (template == null) {
            template = factory.newTemplates(xslSource);
            templatesCache.put(templateFile, template);
        }

        Source xmlSource = new DOMSource(document);
        Transformer javaTransformer = template.newTransformer();
        javaTransformer.transform(xmlSource, new StreamResult(output));
    } catch (TransformerException ex) {
        SourceLocator locator = ex.getLocator();
        log.fatal("Failed to transform", ex);
        log.warn("Line: " + locator.getLineNumber() + ", Column: " + locator.getColumnNumber());
        log.warn("PublicId: " + locator.getPublicId());
        log.warn("SystemId: " + locator.getSystemId());
    } catch (Exception ex) {
        log.warn("Processing Error for " + xmlFile.getAbsolutePath(), ex);
    }
}

From source file:org.directwebremoting.drapgen.generate.gi.GiType.java

/**
 * @param directory Where to write the xml
 * @throws java.io.IOException If writing fails
 *//*from w w w.  j a v  a  2  s  .c  o m*/
public void writeDOM(String directory) throws IOException {
    FileWriter out = null;

    try {
        Transformer transformer = factory.newTransformer();
        Source source = new DOMSource(document);

        StringWriter xml = new StringWriter();
        StreamResult result = new StreamResult(xml);

        transformer.transform(source, result);

        xml.flush();

        String domName = xmlClassName.replaceAll("/", ".");
        File domFile = new File(directory + "org.directwebremoting.proxy." + domName);
        out = new FileWriter(domFile);
        out.append(xml.toString());
    } catch (TransformerException ex) {
        SourceLocator locator = ex.getLocator();
        log.fatal("Failed to transform", ex);
        log.warn("Line: " + locator.getLineNumber() + ", Column: " + locator.getColumnNumber());
        log.warn("PublicId: " + locator.getPublicId());
        log.warn("SystemId: " + locator.getSystemId());
    } finally {
        if (out != null) {
            out.close();
        }
    }
}