Java Code Examples for org.xml.sax.SAXException

The following are top voted examples for showing how to use org.xml.sax.SAXException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: richfaces   File: SAXResponseWriter.java View source code Vote up 6 votes
void writeText(char[] text, int off, int len) throws IOException {
    try {
        xmlConsumer.characters(text, off, len);
    } catch (SAXException e) {
        throw new IOException("Sax exceptions in writeText: " + e.getMessage());
    }
}
 
Example 2
Project: jena   File: WrappedException.java View source code Vote up 6 votes
/** Creates new WrappedException */
WrappedException(SAXException e) {
    Exception in0 = e.getException();
    if ( in0 == null ) {
        initCause(e);
        return;
    }
    if ( (in0 instanceof RuntimeException) 
         || (in0 instanceof SAXException )
         || (in0 instanceof IOException ) )
        {
        initCause(in0);
        return;
    }
    initCause(e);
}
 
Example 3
Project: fiji   File: XMLFunctions.java View source code Vote up 6 votes
public static Document parseXMLFile( final String xmlFile )
{
	Document dom = null;
	
	//get the factory
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	try {

		//Using factory get an instance of document builder
		DocumentBuilder db = dbf.newDocumentBuilder();

		//parse using builder to get DOM representation of the XML file
		dom = db.parse( xmlFile );
	}
	catch(ParserConfigurationException pce) 
	{
		pce.printStackTrace();
	}
	catch(SAXException se) 
	{
		se.printStackTrace();
	}
	catch(IOException ioe) 
	{
		ioe.printStackTrace();
	} 

	return dom;
}
 
Example 4
Project: JFugue-for-Android   File: ToUnknownStream.java View source code Vote up 6 votes
private void flush()
{
    try
    {
    if (m_firstTagNotEmitted)
    {
        emitFirstTag();
    }
    if (m_needToCallStartDocument)
    {
        m_handler.startDocument();
        m_needToCallStartDocument = false;
    }
    }
    catch(SAXException e)
    {
        throw new RuntimeException(e.toString());
    }
      

}
 
Example 5
Project: nmedit   File: PModuleDocumentationParser.java View source code Vote up 6 votes
public static Map<String, String> build(InputSource is) 
    throws ParserConfigurationException, SAXException, IOException 
{

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    
    Map<String, String> documentation = new HashMap<String, String>();
    DocumentHandler handler = new DocumentHandler(documentation);
   
    try
    {
        parser.parse(is, handler);
    }
    catch (SAXException e)
    {
        Locator l = handler.locator;
        if (l == null)
            throw e;
        
        SAXException se = new SAXException("error in line:col="+l.getLineNumber()+":"+l.getColumnNumber());
        se.initCause(e);
        
        throw se;
    }

    return documentation;
}
 
Example 6
Project: OpenClinica   File: XmlSchemaValidationHelper.java View source code Vote up 6 votes
public void validateAgainstSchema(File xmlFile, File xsdFile) {
    try {
        // parse an XML document into a DOM tree
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setNamespaceAware(true);
        DocumentBuilder parser = builderFactory.newDocumentBuilder();
        Document document = parser.parse(xmlFile);

        // create a SchemaFactory capable of understanding WXS schemas
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

        // load a WXS schema, represented by a Schema instance
        Source schemaFile = new StreamSource(xsdFile);
        Schema schema = factory.newSchema(schemaFile);

        // create a Validator instance, which can be used to validate an
        // instance document
        Validator validator = schema.newValidator();

        // validate the DOM tree
        validator.validate(new DOMSource(document));

    } catch (FileNotFoundException ex) {
        throw new OpenClinicaSystemException("File was not found", ex.getCause());
    } catch (IOException ioe) {
        throw new OpenClinicaSystemException("IO Exception", ioe.getCause());
    } catch (SAXParseException spe) {
        //spe.printStackTrace();
        throw new OpenClinicaSystemException("Line : " + spe.getLineNumber() + " - " + spe.getMessage(), spe.getCause());
    } catch (SAXException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (ParserConfigurationException pce) {
        throw new OpenClinicaSystemException(pce.getMessage(), pce.getCause());
    }
}
 
Example 7
Project: OmegaT   File: XMLFilter2.java View source code Vote up 6 votes
/** Processes a single file. */
public void processFile(BufferedReader infile, BufferedWriter outfile) 
        throws IOException, TranslationException
{
    XMLHandler2 handler;
    handler = new XMLHandler2(this, outfile, translatableTags, translatableAttributes);
    InputSource is = new InputSource(infile);
    try
    {
        XMLReader reader = parser.getXMLReader();
        reader.setContentHandler(handler);
        reader.setDTDHandler(handler);
        reader.setEntityResolver(handler);
        reader.setErrorHandler(handler);
        reader.setProperty("http://xml.org/sax/properties/lexical-handler",  handler);
        reader.setProperty("http://xml.org/sax/properties/declaration-handler",  handler);
        parser.parse(is, handler);
    }
    catch( SAXException saxe )
    {
        saxe.printStackTrace(StaticUtils.getLogStream());
        throw new TranslationException(saxe.getLocalizedMessage());
    }
}