Java Code Examples for javax.xml.stream.XMLStreamException#getLocation()

The following examples show how to use javax.xml.stream.XMLStreamException#getLocation() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void parse() throws SAXException {
	try {
		parseInternal();
	}
	catch (XMLStreamException ex) {
		Locator locator = null;
		if (ex.getLocation() != null) {
			locator = new StaxLocator(ex.getLocation());
		}
		SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex);
		if (getErrorHandler() != null) {
			getErrorHandler().fatalError(saxException);
		}
		else {
			throw saxException;
		}
	}
}
 
Example 2
private void parse() throws SAXException {
	try {
		parseInternal();
	}
	catch (XMLStreamException ex) {
		Locator locator = null;
		if (ex.getLocation() != null) {
			locator = new StaxLocator(ex.getLocation());
		}
		SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex);
		if (getErrorHandler() != null) {
			getErrorHandler().fatalError(saxException);
		}
		else {
			throw saxException;
		}
	}
}
 
Example 3
private void parse() throws SAXException {
	try {
		parseInternal();
	}
	catch (XMLStreamException ex) {
		Locator locator = null;
		if (ex.getLocation() != null) {
			locator = new StaxLocator(ex.getLocation());
		}
		SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex);
		if (getErrorHandler() != null) {
			getErrorHandler().fatalError(saxException);
		}
		else {
			throw saxException;
		}
	}
}
 
Example 4
private void parse() throws SAXException {
	try {
		parseInternal();
	}
	catch (XMLStreamException ex) {
		Locator locator = null;
		if (ex.getLocation() != null) {
			locator = new StaxLocator(ex.getLocation());
		}
		SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex);
		if (getErrorHandler() != null) {
			getErrorHandler().fatalError(saxException);
		}
		else {
			throw saxException;
		}
	}
}
 
Example 5
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 6
Source Project: jdk8u60   File: StAXSource.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 7
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 8
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 9
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 10
Source Project: hottub   File: StAXSource.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 11
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 12
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 13
public void testExceptionLocation() throws Exception {
	String str = "{\"junk";
	Configuration config = new Configuration();
	MappedXMLInputFactory factory = new MappedXMLInputFactory(config);
	try {
	    factory.createXMLStreamReader(new StringReader(str));
	    fail("Exception expected");
	} catch (XMLStreamException ex) {
		Location loc = ex.getLocation();
		assertNotNull(loc);
		assertEquals(0, loc.getLineNumber());
		assertEquals(6, loc.getColumnNumber());
	}
}
 
Example 14
Source Project: rich-test-results   File: AntXmlParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the list of {@link TestSuite} objects parsed from the Ant XML format input stream.
 */
public ImmutableList<TestSuite> parse(InputStream in, Charset encoding)
    throws XmlParseException {
  try {
    XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(in, encoding.name());
    try {
      while (xmlStreamReader.hasNext()) {
        int next = xmlStreamReader.next();
        if (next == XMLStreamConstants.END_DOCUMENT) {
          break;
        }
        if (!xmlStreamReader.hasName()) {
          continue;
        }
        String tagName = xmlStreamReader.getName().toString();
        if (xmlStreamReader.isStartElement()) {
          switch (tagName) {
            case "testsuites":
              return parseSuites(xmlStreamReader);
            case "testsuite":
              return ImmutableList.of(parseSuite(xmlStreamReader));
            default:
              handleUnsupportedElement("root", tagName);
          }
        }
      }
    } finally {
      xmlStreamReader.close();
    }
  } catch (XMLStreamException e) {
    if (e.getLocation() != null) {
      throw new XmlParseException(e.getMessage(), e);
    } else {
      throw new RuntimeException(e);
    }
  }
  throw new XmlParseException("No testsuites or testsuite element found.");
}
 
Example 15
Source Project: keycloak   File: ParsingException.java    License: Apache License 2.0 4 votes vote down vote up
public ParsingException(XMLStreamException xmle) {
    super(xmle);
    location = xmle.getLocation();
}