Example usage for org.xml.sax SAXException getException

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

Introduction

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

Prototype

public Exception getException() 

Source Link

Document

Return the embedded exception, if any.

Usage

From source file:Util.java

/**
 * Looks up and returns the root cause of an exception. If none is found, returns
 * supplied Throwable object unchanged. If root is found, recursively "unwraps" it,
 * and returns the result to the user./*  w ww .j  a va2  s .  co  m*/
 */
public static Throwable unwindException(Throwable th) {
    if (th instanceof SAXException) {
        SAXException sax = (SAXException) th;
        if (sax.getException() != null) {
            return unwindException(sax.getException());
        }
    } else if (th instanceof SQLException) {
        SQLException sql = (SQLException) th;
        if (sql.getNextException() != null) {
            return unwindException(sql.getNextException());
        }
    } else if (th.getCause() != null) {
        return unwindException(th.getCause());
    }

    return th;
}

From source file:Main.java

/**
 * Parse the XML file and create Document
 * @param fileName/*w  ww  .  j  av  a2 s.  co  m*/
 * @return Document
 */
public static Document parse(InputStream fs) {
    Document document = null;
    // Initiate DocumentBuilderFactory
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    // To get a validating parser
    factory.setValidating(false);

    // To get one that understands namespaces
    factory.setNamespaceAware(true);
    try {
        // Get DocumentBuilder
        DocumentBuilder builder = factory.newDocumentBuilder();

        // Parse and load into memory the Document
        //document = builder.parse( new File(fileName));
        document = builder.parse(fs);
        return document;
    } catch (SAXParseException spe) {
        // Error generated by the parser
        System.err.println("\n** Parsing error , line " + spe.getLineNumber() + ", uri " + spe.getSystemId());
        System.err.println(" " + spe.getMessage());
        // Use the contained exception, if any
        Exception x = spe;
        if (spe.getException() != null)
            x = spe.getException();
        x.printStackTrace();
    } catch (SAXException sxe) {
        // Error generated during parsing
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        x.printStackTrace();
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        pce.printStackTrace();
    } catch (IOException ioe) {
        // I/O error
        ioe.printStackTrace();
    }

    return null;
}

From source file:embedding.events.ExampleEvents.java

/**
 * This method extracts the original exception from some exception. The exception
 * might be nested multiple levels deep.
 * @param t the Throwable to inspect/*from w w w . ja  v  a  2 s.  co m*/
 * @return the original Throwable or the method parameter t if there are no nested Throwables.
 */
private static Throwable getOriginalThrowable(Throwable t) {
    if (t instanceof SAXException) {
        SAXException saxe = (SAXException) t;
        if (saxe.getException() != null) {
            return getOriginalThrowable(saxe.getException());
        } else {
            return saxe;
        }
    } else {
        if (t.getCause() != null) {
            return getOriginalThrowable(t.getCause());
        } else {
            return t;
        }
    }
}

From source file:com.microsoft.tfs.core.clients.workitem.internal.form.WIFormParseHandler.java

public static WIFormElement parse(final String xml) {
    final WIFormParseHandler handler = new WIFormParseHandler();

    try {//  w  ww.ja v a 2  s .co  m
        final SAXParser parser = SAXUtils.newSAXParser();
        parser.parse(new InputSource(new StringReader(xml)), handler);
    } catch (final SAXException ex) {
        ex.initCause(ex.getException());
        throw new RuntimeException(ex);
    } catch (final Exception ex) {
        throw new RuntimeException(ex);
    }

    return handler.root;
}

From source file:cz.zcu.kiv.eegdatabase.logic.schemagen.ScenarioSchemaGenerator.java

private String getElement() {

    InputStream xsd = new ByteArrayInputStream(content);

    XSOMParser parser = new XSOMParser();
    String myString = content.toString();

    try {/*from  w  ww  . j  a  va 2s  . c o m*/
        parser.parse(xsd);
    } catch (SAXException e) {
        if (e.getException() != null)
            e.getException().printStackTrace();
    }

    Set<SchemaDocument> docSet = parser.getDocuments();
    Map<String, XSElementDecl> elementDeclMap = null;
    for (SchemaDocument doc : docSet) {
        elementDeclMap = doc.getSchema().getElementDecls();
        if (!elementDeclMap.isEmpty())
            break;
    }

    TreeSet<String> elementNameSet = new TreeSet(elementDeclMap.keySet());
    String elementName = elementNameSet.first();

    System.out.println(elementName);

    return elementName;
}

From source file:net.sf.joost.trax.TemplatesImpl.java

/**
 * Configures the <code>Templates</code> - initializing by parsing the
 * stylesheet.//from  w w w  . j  ava 2s.  co m
 * @param reader The <code>XMLReader</code> for parsing the stylesheet
 * @param isource The <code>InputSource</code> of the stylesheet
 * @throws TransformerConfigurationException When an error occurs while
 *  initializing the <code>Templates</code>.
 */
private void init(XMLReader reader, InputSource isource) throws TransformerConfigurationException {

    if (DEBUG)
        log.debug("init with InputSource " + isource.getSystemId());
    try {
        /**
         * Register ErrorListener from
         * {@link TransformerFactoryImpl#getErrorListener()}
         * if available.
         */
        // check if transformerfactory is in debug mode
        boolean debugmode = ((Boolean) this.factory.getAttribute(DEBUG_FEATURE)).booleanValue();

        ParseContext pContext = new ParseContext();
        pContext.allowExternalFunctions = factory.allowExternalFunctions;
        pContext.setErrorListener(factory.getErrorListener());
        pContext.uriResolver = factory.getURIResolver();
        if (debugmode) {
            if (DEBUG)
                log.info("init transformer in debug mode");
            pContext.parserListener = factory.getParserListenerMgr();
            processor = new DebugProcessor(reader, isource, pContext, factory.getMessageEmitter());
        } else {
            processor = new Processor(reader, isource, pContext);
        }
        processor.setTransformerHandlerResolver(factory.thResolver);
        processor.setOutputURIResolver(factory.outputUriResolver);
    } catch (java.io.IOException iE) {
        if (DEBUG)
            log.debug(iE);
        throw new TransformerConfigurationException(iE.getMessage(), iE);
    } catch (org.xml.sax.SAXException sE) {
        Exception emb = sE.getException();
        if (emb instanceof TransformerConfigurationException)
            throw (TransformerConfigurationException) emb;
        if (DEBUG)
            log.debug(sE);
        throw new TransformerConfigurationException(sE.getMessage(), sE);
    } catch (java.lang.NullPointerException nE) {
        if (DEBUG)
            log.debug(nE);
        nE.printStackTrace(System.err);
        throw new TransformerConfigurationException(
                "could not found value for property javax.xml.parsers.SAXParser ", nE);
    }
}

From source file:edu.ucsd.xmlrpc.xmlrpc.server.XmlRpcStreamServer.java

protected XmlRpcRequest getRequest(final XmlRpcStreamRequestConfig pConfig, InputStream pStream)
        throws XmlRpcException {
    final XmlRpcRequestParser parser = new XmlRpcRequestParser(pConfig, getTypeFactory());
    final XMLReader xr = SAXParsers.newXMLReader();
    xr.setContentHandler(parser);/*w ww. jav a2  s .  c  om*/
    try {
        xr.parse(new InputSource(pStream));
    } catch (SAXException e) {
        Exception ex = e.getException();
        if (ex != null && ex instanceof XmlRpcException) {
            throw (XmlRpcException) ex;
        }
        throw new XmlRpcException("Failed to parse XML-RPC request: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcException("Failed to read XML-RPC request: " + e.getMessage(), e);
    }
    final List params = parser.getParams();
    // Ucsd modified code
    return new XmlRpcClientRequestImpl(pConfig, parser.getMethodName(), parser.getParams(), parser.getJobID());
    // end
}

From source file:gov.nih.nci.caadapter.ui.mapping.sdtm.SDTMMapFileTransformer.java

public SDTMMapFileTransformer(String mapFileName, String csvFileName, AbstractMainFrame _callingFrame,
        String saveSDTMPath) throws Exception {
    mainFrame = _callingFrame;/*  w w  w.j a  v a 2 s.co m*/
    _saveSDTMPath = saveSDTMPath;
    _csvFileName = csvFileName;
    // create a complete list before
    ParseSDTMXMLFile _parseSDTMFile = new ParseSDTMXMLFile(getDefineXMlName(mapFileName));
    ArrayList<String> _retArray = _parseSDTMFile.getSDTMStructure();
    // LinkedList defineXMLList = new LinkedList();
    for (int k = 0; k < 18; k++) {
        if (_retArray.get(k).startsWith("KEY")) {
            // EmptyStringTokenizer _str = new EmptyStringTokenizer(_retArray.get(k),",");
        } else {
            EmptyStringTokenizer _str = new EmptyStringTokenizer(_retArray.get(k), ",");
            String _tmpStr = _str.getTokenAt(1).toString();
            defineXMLList.add(_tmpStr.substring(0, _tmpStr.indexOf("&")));
            // pNode.add(new DefaultTargetTreeNode(new SDTMMetadata(_str.getTokenAt(1),_str.getTokenAt(2), _str.getTokenAt(3), _str.getTokenAt(4))));
        }
    }
    SDTM_CSVReader _csvData = new SDTM_CSVReader();
    _csvData.readCSVFile(csvFileName);
    _csvDataFromFile = _csvData.get_CSVData();
    try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(new File(mapFileName));
        //System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName());
        NodeList linkNodeList = doc.getElementsByTagName("link");
        int totalPersons = linkNodeList.getLength();
        //System.out.println("Total no of links are : " + totalPersons);
        //System.out.println(defineXMLList.toString());
        for (int s = 0; s < linkNodeList.getLength(); s++) {
            Node node = linkNodeList.item(s);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element firstPersonElement = (Element) node;
                NodeList targetNode = firstPersonElement.getElementsByTagName("target");
                Element targetName = (Element) targetNode.item(0);
                NodeList textLNList = targetName.getChildNodes();
                String _targetName = ((Node) textLNList.item(0)).getNodeValue().trim();
                EmptyStringTokenizer _tmpEmp = new EmptyStringTokenizer(_targetName.toString(), "\\");
                String finalTargetName = _tmpEmp.getTokenAt(_tmpEmp.countTokens() - 1);
                NodeList sourceNode = firstPersonElement.getElementsByTagName("source");
                Element sourceName = (Element) sourceNode.item(0);
                NodeList textFNList = sourceName.getChildNodes();
                String _srcNodeVal = ((Node) textFNList.item(0)).getNodeValue().trim();
                EmptyStringTokenizer _str = new EmptyStringTokenizer(_srcNodeVal, "\\");
                String _tmp = _str.getTokenAt(_str.countTokens() - 2);
                String sourceNodeValue = _str.getTokenAt(_str.countTokens() - 1);
                // _mappedData.put(finalTargetName, _tmp+"%"+sourceNodeValue);
                StringBuffer _sBuf = new StringBuffer();
                if (_mappedData.get(_tmp) == null) {
                    _sBuf.append(sourceNodeValue + "?" + finalTargetName);
                    _mappedData.put(_tmp, _sBuf);
                } else {
                    StringBuffer _tBuf = (StringBuffer) _mappedData.get(_tmp);
                    _tBuf.append("," + sourceNodeValue + "?" + finalTargetName);
                    _mappedData.put(_tmp, _tBuf);
                }
            } // end of if clause
        } // end of for loop with s var
        System.out.println(_mappedData);
        System.out.println(_csvDataFromFile);
        BeginTransformation();
    } catch (SAXParseException err) {
        System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
        System.out.println(" " + err.getMessage());
    } catch (SAXException e) {
        Exception x = e.getException();
        ((x == null) ? e : x).printStackTrace();
    } catch (Throwable t) {
        // JOptionPane.showMessageDialog(mainFrame, "SDTM Record File created successfully");
        t.printStackTrace();
    }
    JOptionPane.showMessageDialog(mainFrame, "SDTM Record File " + _saveSDTMPath + " created successfully");
    // System.exit (0);
}

From source file:com.keithhutton.ws.proxy.ProxyServlet.java

private XmlRpcRequest getMethodAndParamsFromRequest(ServletRequest req) throws XmlRpcException {
    final XmlRpcStreamRequestConfig pConfig = getConfig((HttpServletRequest) req);
    final XmlRpcRequestParser parser = new XmlRpcRequestParser(pConfig, getTypeFactory());
    final XMLReader xr = SAXParsers.newXMLReader();
    xr.setContentHandler(parser);//from w  w  w  . j  av  a2s. c  om
    try {
        xr.parse(new InputSource(req.getInputStream()));
    } catch (SAXException e) {
        Exception ex = e.getException();
        if (ex != null && ex instanceof XmlRpcException) {
            throw (XmlRpcException) ex;
        }
        throw new XmlRpcException("Failed to parse XML-RPC request: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcException("Failed to read XML-RPC request: " + e.getMessage(), e);
    }
    final List params = parser.getParams();
    final int paramCount = params == null ? 0 : params.size();
    XmlRpcRequest xmlRpcRequest = new XmlRpcRequest() {
        public XmlRpcRequestConfig getConfig() {
            return pConfig;
        }

        public String getMethodName() {
            return parser.getMethodName();
        }

        public int getParameterCount() {
            return params == null ? 0 : params.size();
        }

        public Object getParameter(int pIndex) {
            return paramCount > 0 ? params.get(pIndex) : null;
        }
    };
    this.log.info("xmlRpcRequest method = " + xmlRpcRequest.getMethodName());
    this.log.info("xmlRpcRequest pcount = " + xmlRpcRequest.getParameterCount());
    this.log.info("xmlRpcRequest param1 = " + xmlRpcRequest.getParameter(0));
    return xmlRpcRequest;

}

From source file:net.ontopia.topicmaps.db2tm.RelationMapping.java

public static RelationMapping read(InputStream istream, File basedir) throws IOException {
    // Create new parser object
    XMLReader parser;// w  w  w.j av a2s  . c  o  m
    try {
        parser = new DefaultXMLReaderFactory().createXMLReader();
    } catch (SAXException e) {
        throw new IOException("Problems occurred when creating SAX2 XMLReader: " + e.getMessage());
    }

    // Create content handler
    RelationMapping mapping = new RelationMapping();
    mapping.setBaseDirectory(basedir);
    ContentHandler vhandler = new ValidatingContentHandler(mapping, getRelaxNGSchema(), true);
    parser.setContentHandler(vhandler);

    try {
        // Parse input source
        parser.parse(new InputSource(istream));
    } catch (FileNotFoundException e) {
        log.error("Resource not found: {}", e.getMessage());
        throw e;
    } catch (SAXParseException e) {
        throw new OntopiaRuntimeException("XML parsing problem: " + e.toString() + " at: " + e.getSystemId()
                + ":" + e.getLineNumber() + ":" + e.getColumnNumber(), e);
    } catch (SAXException e) {
        if (e.getException() instanceof IOException)
            throw (IOException) e.getException();
        throw new OntopiaRuntimeException(e);
    }

    // Compile mapping
    mapping.compile();

    return mapping;
}