Example usage for org.xml.sax SAXException SAXException

List of usage examples for org.xml.sax SAXException SAXException

Introduction

In this page you can find the example usage for org.xml.sax SAXException SAXException.

Prototype

public SAXException(Exception e) 

Source Link

Document

Create a new SAXException wrapping an existing exception.

Usage

From source file:org.apache.jasper.xmlparser.ParserUtils.java

public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
    for (int i = 0; i < Constants.CACHED_DTD_PUBLIC_IDS.length; i++) {
        String cachedDtdPublicId = Constants.CACHED_DTD_PUBLIC_IDS[i];
        if (cachedDtdPublicId.equals(publicId)) {
            String resourcePath = Constants.CACHED_DTD_RESOURCE_PATHS[i];
            InputStream input = this.getClass().getResourceAsStream(resourcePath);
            if (input == null) {
                throw new SAXException(Localizer.getMessage("jsp.error.internal.filenotfound", resourcePath));
            }// www  .  j  a  va 2  s . co m
            InputSource isrc = new InputSource(input);
            return isrc;
        }
    }
    System.out.println("Resolve entity failed" + publicId + " " + systemId);
    ParserUtils.log.error(Localizer.getMessage("jsp.error.parse.xml.invalidPublicId", publicId));
    return null;
}

From source file:org.apache.ode.bpel.compiler.bom.BpelObjectFactory.java

/**
 * Parse a BPEL process found at the input source.
 * @param isrc input source.//w  ww .j av  a 2s . c  o  m
 * @return
 * @throws SAXException
 */
public Process parse(InputSource isrc, URI systemURI) throws IOException, SAXException {
    XMLReader _xr = XMLParserUtils.getXMLReader();
    LocalEntityResolver resolver = new LocalEntityResolver();
    resolver.register(Bpel11QNames.NS_BPEL4WS_2003_03, getClass().getResource("/bpel4ws_1_1-fivesight.xsd"));
    resolver.register(Bpel20QNames.NS_WSBPEL2_0, getClass().getResource("/wsbpel_main-draft-Apr-29-2006.xsd"));
    resolver.register(Bpel20QNames.NS_WSBPEL2_0_FINAL_ABSTRACT,
            getClass().getResource("/ws-bpel_abstract_common_base.xsd"));
    resolver.register(Bpel20QNames.NS_WSBPEL2_0_FINAL_EXEC, getClass().getResource("/ws-bpel_executable.xsd"));
    resolver.register(Bpel20QNames.NS_WSBPEL2_0_FINAL_PLINK, getClass().getResource("/ws-bpel_plnktype.xsd"));
    resolver.register(Bpel20QNames.NS_WSBPEL2_0_FINAL_SERVREF,
            getClass().getResource("/ws-bpel_serviceref.xsd"));
    resolver.register(Bpel20QNames.NS_WSBPEL2_0_FINAL_VARPROP, getClass().getResource("/ws-bpel_varprop.xsd"));
    resolver.register(XML, getClass().getResource("/xml.xsd"));
    resolver.register(WSDL, getClass().getResource("/wsdl.xsd"));
    resolver.register(Bpel20QNames.NS_WSBPEL_PARTNERLINK_2004_03,
            getClass().getResource("/wsbpel_plinkType-draft-Apr-29-2006.xsd"));
    _xr.setEntityResolver(resolver);
    Document doc = DOMUtils.newDocument();
    _xr.setContentHandler(new DOMBuilderContentHandler(doc));
    _xr.setFeature("http://xml.org/sax/features/namespaces", true);
    _xr.setFeature("http://xml.org/sax/features/namespace-prefixes", true);

    _xr.setFeature("http://xml.org/sax/features/validation", true);
    XMLParserUtils.addExternalSchemaURL(_xr, Bpel11QNames.NS_BPEL4WS_2003_03, Bpel11QNames.NS_BPEL4WS_2003_03);
    XMLParserUtils.addExternalSchemaURL(_xr, Bpel20QNames.NS_WSBPEL2_0, Bpel20QNames.NS_WSBPEL2_0);
    XMLParserUtils.addExternalSchemaURL(_xr, Bpel20QNames.NS_WSBPEL2_0_FINAL_EXEC,
            Bpel20QNames.NS_WSBPEL2_0_FINAL_EXEC);
    XMLParserUtils.addExternalSchemaURL(_xr, Bpel20QNames.NS_WSBPEL2_0_FINAL_ABSTRACT,
            Bpel20QNames.NS_WSBPEL2_0_FINAL_ABSTRACT);

    boolean strict = Boolean
            .parseBoolean(System.getProperty("org.apache.ode.compiler.failOnValidationErrors", "false"));
    BOMSAXErrorHandler errorHandler = new BOMSAXErrorHandler(strict);
    _xr.setErrorHandler(errorHandler);
    _xr.parse(isrc);
    if (strict) {
        if (!errorHandler.wasOK()) {
            throw new SAXException("Validation errors during parsing");
        }
    } else {
        if (!errorHandler.wasOK()) {
            __log.warn(
                    "Validation errors during parsing, continuing due to -Dorg.apache.ode.compiler.failOnValidationErrors=false switch");
        }
    }
    return (Process) createBpelObject(doc.getDocumentElement(), systemURI);
}

From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java

private Class<?> parseTypeStr(String typeStr) throws SAXException {
    Class<?> typeCls = null;
    try {//from  w w  w. ja v a2  s  . c  om
        if (typeStr.equalsIgnoreCase("int")) {
            typeCls = int.class;
        } else if (typeStr.equalsIgnoreCase("byte")) {
            typeCls = byte.class;
        } else if (typeStr.equalsIgnoreCase("short")) {
            typeCls = short.class;
        } else if (typeStr.equalsIgnoreCase("long")) {
            typeCls = long.class;
        } else if (typeStr.equalsIgnoreCase("float")) {
            typeCls = float.class;
        } else if (typeStr.equalsIgnoreCase("double")) {
            typeCls = double.class;
        } else if (typeStr.equalsIgnoreCase("boolean")) {
            typeCls = boolean.class;
        } else if (typeStr.equalsIgnoreCase("char")) {
            typeCls = char.class;
        } else {
            typeCls = Class.forName(typeStr);
        }
    } catch (ClassNotFoundException e) {
        throw new SAXException(e);
    }

    return typeCls;
}

From source file:org.apache.tika.parser.microsoft.ooxml.xps.XPSExtractorDecorator.java

@Override
protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, IOException {

    PackageRelationshipCollection prc = pkg.getRelationshipsByType(XPS_DOCUMENT);
    for (int i = 0; i < prc.size(); i++) {
        PackageRelationship pr = prc.getRelationship(i);

        //there should only be one.
        //in the test file, this points to FixedDocSeq.fdseq
        try {/*from   w  w w. j a  va 2 s .co  m*/
            handleDocuments(pr, xhtml);
        } catch (TikaException e) {
            throw new SAXException(e);
        }
    }

    //now handle embedded images
    if (embeddedImages.size() > 0) {
        EmbeddedDocumentUtil embeddedDocumentUtil = new EmbeddedDocumentUtil(context);
        for (Map.Entry<String, Metadata> embeddedImage : embeddedImages.entrySet()) {
            String zipPath = embeddedImage.getKey();
            Metadata metadata = embeddedImage.getValue();
            if (embeddedDocumentUtil.shouldParseEmbedded(metadata)) {
                handleEmbeddedImage(zipPath, metadata, embeddedDocumentUtil, xhtml);
            }
        }
    }

}

From source file:org.apache.tika.sax.CTAKESContentHandler.java

/**
 * Serializes metadata to output file./*from  www  . ja v a 2 s  . c  o m*/
 * @param outputFile to output metadata.
 * @param inputFileName of input file 
 * @param jcas {@see jCas} object used to keep the jcas from XML file.
 */
public static void serializeAsMetadata(File outputFile, String inputFileName, JCas jcas) throws SAXException {
    try {
        // Add annotations to metadata
        metadata.add(CTAKES_META_PREFIX + "schema", config.getAnnotationPropsAsString());
        CTAKESAnnotationProperty[] annotationPros = config.getAnnotationProps();
        Collection<IdentifiedAnnotation> collection = JCasUtil.select(jcas, IdentifiedAnnotation.class);
        Iterator<IdentifiedAnnotation> iterator = collection.iterator();
        while (iterator.hasNext()) {
            IdentifiedAnnotation annotation = iterator.next();
            StringBuilder annotationBuilder = new StringBuilder();
            annotationBuilder.append(annotation.getCoveredText());
            if (annotationPros != null) {
                for (CTAKESAnnotationProperty property : annotationPros) {
                    annotationBuilder.append(config.getSeparatorChar());
                    annotationBuilder.append(CTAKESUtils.getAnnotationProperty(annotation, property));
                }
            }
            metadata.add(CTAKES_META_PREFIX + annotation.getType().getShortName(),
                    annotationBuilder.toString());
        }
        // For the missing file content and title
        metadata.add("X-TIKA:content", jcas.getSofa().getLocalStringData());
        metadata.add("title", inputFileName.substring(inputFileName.lastIndexOf('/') + 1));

        List<Metadata> metadataList = new LinkedList<Metadata>();
        metadataList.add(metadata);
        StringWriter writer = new StringWriter();
        JsonMetadataList.toJson(metadataList, writer);

        FileUtils.writeStringToFile(outputFile, writer.toString());
    } catch (Exception e) {
        throw new SAXException(e.getMessage());
    } finally {
        CTAKESUtils.resetCAS(jcas);
    }
}

From source file:org.apache.torque.engine.database.transform.XmlToAppData.java

/**
 * EntityResolver implementation. Called by the XML parser
 *
 * @param publicId The public identifier of the external entity
 * @param systemId The system identifier of the external entity
 * @return an InputSource for the database.dtd file
 * @see DTDResolver#resolveEntity(String, String)
 *///from w  ww. j av  a  2  s . co m
public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
    try {
        return new DTDResolver().resolveEntity(publicId, systemId);
    } catch (Exception e) {
        throw new SAXException(e);
    }
}

From source file:org.apache.torque.engine.database.transform.XmlToAppData.java

/**
 * Handles opening elements of the xml file.
 *
 * @param uri/*w ww .ja  va  2 s .  c  o m*/
 * @param localName The local name (without prefix), or the empty string if
 *         Namespace processing is not being performed.
 * @param rawName The qualified name (with prefix), or the empty string if
 *         qualified names are not available.
 * @param attributes The specified or defaulted attributes
 */
public void startElement(String uri, String localName, String rawName, Attributes attributes)
        throws SAXException {
    try {
        if (rawName.equals("database")) {
            if (isExternalSchema) {
                currentPackage = attributes.getValue("package");
                if (currentPackage == null) {
                    currentPackage = defaultPackage;
                }
            } else {
                database.loadFromXML(attributes);
                if (database.getPackage() == null) {
                    database.setPackage(defaultPackage);
                }
            }
        } else if (rawName.equals("external-schema")) {
            String xmlFile = attributes.getValue("filename");
            if (xmlFile.charAt(0) != '/') {
                File f = new File(currentXmlFile);
                xmlFile = new File(f.getParent(), xmlFile).getPath();
            }

            // put current state onto the stack
            ParseStackElement.pushState(this);

            isExternalSchema = true;

            parseFile(xmlFile);
            // get the last state from the stack
            ParseStackElement.popState(this);
        } else if (rawName.equals("domain")) {
            Domain domain = new Domain();
            domain.loadFromXML(attributes, database.getPlatform());
            database.addDomain(domain);
        } else if (rawName.equals("table")) {
            currTable = database.addTable(attributes);
            if (isExternalSchema) {
                currTable.setForReferenceOnly(true);
                currTable.setPackage(currentPackage);
            }
        } else if (rawName.equals("column")) {
            currColumn = currTable.addColumn(attributes);
        } else if (rawName.equals("inheritance")) {
            currColumn.addInheritance(attributes);
        } else if (rawName.equals("foreign-key")) {
            currFK = currTable.addForeignKey(attributes);
        } else if (rawName.equals("reference")) {
            currFK.addReference(attributes);
        } else if (rawName.equals("index")) {
            currIndex = currTable.addIndex(attributes);
        } else if (rawName.equals("index-column")) {
            currIndex.addColumn(attributes);
        } else if (rawName.equals("unique")) {
            currUnique = currTable.addUnique(attributes);
        } else if (rawName.equals("unique-column")) {
            currUnique.addColumn(attributes);
        } else if (rawName.equals("id-method-parameter")) {
            currTable.addIdMethodParameter(attributes);
        } else if (rawName.equals("option")) {
            setOption(attributes);
        }
    } catch (Exception e) {
        throw new SAXException(e);
    }
}

From source file:org.apache.torque.engine.database.transform.XmlToAppData.java

/**
 * Handles closing elements of the xml file.
 *
 * @param uri/*from w w w  . ja  va2s  .c o m*/
 * @param localName The local name (without prefix), or the empty string if
 *         Namespace processing is not being performed.
 * @param rawName The qualified name (with prefix), or the empty string if
 *         qualified names are not available.
 */
public void endElement(String uri, String localName, String rawName) throws SAXException {
    if (log.isDebugEnabled()) {
        log.debug("endElement(" + uri + ", " + localName + ", " + rawName + ") called");
    }
    try {
        // Reset working objects to null to allow option to know
        // which element it is associated with.
        if (rawName.equals("table")) {
            currTable = null;
        } else if (rawName.equals("column")) {
            currColumn = null;
        } else if (rawName.equals("foreign-key")) {
            currFK = null;
        } else if (rawName.equals("index")) {
            currIndex = null;
        } else if (rawName.equals("unique")) {
            currUnique = null;
        }
    } catch (Exception e) {
        throw new SAXException(e);
    }
}

From source file:org.apache.torque.engine.database.transform.XmlToAppData.java

/**
 * Handles exception which occur when the xml file is parsed
 * @param e the exception which occured while parsing
 * @throws SAXException always/*  w  w w.  j  av a2  s .  c o m*/
 */
public void error(SAXParseException e) throws SAXException {
    log.error("Sax parser threw an Exception", e);
    throw new SAXException("Error while parsing " + currentXmlFile + " at line " + e.getLineNumber()
            + " column " + e.getColumnNumber() + " : " + e.getMessage());
}

From source file:org.apache.torque.engine.database.transform.XmlToData.java

/**
 * Handles opening elements of the xml file.
 *///from  ww  w .j  a va 2  s.  c  o m
public void startElement(String uri, String localName, String rawName, Attributes attributes)
        throws SAXException {
    try {
        if (rawName.equals("dataset")) {
            //ignore <dataset> for now.
        } else {
            Table table = database.getTableByJavaName(rawName);

            if (table == null) {
                throw new SAXException("Table '" + rawName + "' unknown");
            }
            List columnValues = new ArrayList();
            for (int i = 0; i < attributes.getLength(); i++) {
                Column col = table.getColumnByJavaName(attributes.getQName(i));

                if (col == null) {
                    throw new SAXException(
                            "Column " + attributes.getQName(i) + " in table " + rawName + " unknown.");
                }

                String value = attributes.getValue(i);
                columnValues.add(new ColumnValue(col, value));
            }
            data.add(new DataRow(table, columnValues));
        }
    } catch (Exception e) {
        throw new SAXException(e);
    }
}