Search in sources :

Example 6 with ConfigException

use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.

the class AssemblingContentHandler method apply_xslt.

private void apply_xslt(InputSource xslt, String root) throws SAXException {
    String errMsg = String.format("Config Generation: '%s' - Could not create inner parser.", getSrcFileName());
    try {
        ContentHandler inner = new AssemblingContentHandler(parser, up, false, false, this);
        TransformerHandler transformer = transfactory.newTransformerHandler(new StreamSource(xslt.getByteStream()));
        transformer.setResult(new SAXResult(inner));
        delegated = transformer;
        delegated.startDocument();
        if (root != null) {
            delegated.startElement("", root, root, new AttributesImpl());
        }
        delegated_root = root;
        delegated_depth = 1;
    } catch (TransformerConfigurationException e) {
        throw new SAXException(errMsg, e);
    } catch (ConfigException e) {
        throw new SAXException(errMsg, e);
    } catch (IOException e) {
        throw new SAXException(errMsg, e);
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SAXResult(javax.xml.transform.sax.SAXResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StreamSource(javax.xml.transform.stream.StreamSource) ConfigException(org.collectionspace.chain.csp.config.ConfigException) IOException(java.io.IOException) ContentHandler(org.xml.sax.ContentHandler) SAXException(org.xml.sax.SAXException)

Example 7 with ConfigException

use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.

the class AssemblingParser method parse.

public void parse(Result out) throws ConfigException {
    String errMsg = String.format("Config Generation: '%s' - Exception raised during parsing.", this.getMain().getPublicId());
    try {
        String rootpath = AssemblingParser.class.getPackage().getName().replaceAll("\\.", "/") + "/" + root_file;
        // load the file at org/collectionspace/chain/csp/config/impl/parser/root.xml
        InputStream root = Thread.currentThread().getContextClassLoader().getResourceAsStream(rootpath);
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        TransformerHandler xform = transfactory.newTransformerHandler();
        xform.setResult(out);
        AssemblingContentHandler assemblingContentHandler = new AssemblingContentHandler(this, xform);
        logger.info(String.format("Temporary XMLMerge files will be written out to '%s'.", AssemblingContentHandler.getTempDirectory()));
        reader.setContentHandler(assemblingContentHandler);
        reader.parse(new InputSource(root));
    } catch (IOException e) {
        throw new ConfigException(errMsg, e);
    } catch (ParserConfigurationException e) {
        throw new ConfigException(errMsg, e);
    } catch (SAXException e) {
        throw new ConfigException(errMsg, e);
    } catch (TransformerConfigurationException e) {
        throw new ConfigException(errMsg, e);
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) InputSource(org.xml.sax.InputSource) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) InputStream(java.io.InputStream) SAXParser(javax.xml.parsers.SAXParser) ConfigException(org.collectionspace.chain.csp.config.ConfigException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Example 8 with ConfigException

use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.

the class ConfigErrorHandler method fail_if_necessary.

public void fail_if_necessary() throws ConfigException {
    if (errors.size() == 0)
        return;
    StringBuffer out = new StringBuffer();
    out.append("Error loading config. See messages for details: summary ");
    for (Throwable t : errors) {
        out.append(t.getMessage());
        if (t instanceof SAXParseException) {
            SAXParseException s = (SAXParseException) t;
            out.append("[" + s.getSystemId() + "/" + s.getLineNumber() + "]");
        }
        out.append(' ');
    }
    throw new ConfigException(out.toString());
}
Also used : SAXParseException(org.xml.sax.SAXParseException) ConfigException(org.collectionspace.chain.csp.config.ConfigException)

Aggregations

ConfigException (org.collectionspace.chain.csp.config.ConfigException)8 IOException (java.io.IOException)3 JSONArray (org.json.JSONArray)3 SAXException (org.xml.sax.SAXException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParser (javax.xml.parsers.SAXParser)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerHandler (javax.xml.transform.sax.TransformerHandler)2 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)2 Structure (org.collectionspace.chain.csp.schema.Structure)2 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)2 JSONObject (org.json.JSONObject)2 InputStream (java.io.InputStream)1 SAXResult (javax.xml.transform.sax.SAXResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Configurable (org.collectionspace.chain.csp.config.Configurable)1 RuleSetImpl (org.collectionspace.chain.csp.config.impl.main.RuleSetImpl)1 ConfigParser (org.collectionspace.chain.csp.config.impl.parser.ConfigParser)1 Field (org.collectionspace.chain.csp.schema.Field)1 Instance (org.collectionspace.chain.csp.schema.Instance)1