List of usage examples for org.xml.sax SAXParseException SAXParseException
public SAXParseException(String message, String publicId, String systemId, int lineNumber, int columnNumber)
From source file:Main.java
public static Document openXmlStream(InputStream stream, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXParseException, SAXException { DocumentBuilder builder = newDocumentBuilder(schema, isNamespaceAware, isXIncludeAware); Document docu;/*from ww w . j a v a 2s . c o m*/ builder.setErrorHandler(new org.xml.sax.ErrorHandler() { @Override public void error(SAXParseException exception) throws SAXParseException { throw new SAXParseException("Parse Error in instream, line " + exception.getLineNumber() + ": " + exception.getMessage(), "", "instream", exception.getLineNumber(), 0); } @Override public void fatalError(SAXParseException exception) throws SAXParseException { throw new SAXParseException("Parse Error in instream, line " + exception.getLineNumber() + ": " + exception.getMessage(), "", "instream", exception.getLineNumber(), 0); } @Override public void warning(SAXParseException exception) { System.err.println("Parse Warning: " + exception.getMessage() + exception.getLineNumber()); } }); docu = builder.parse(stream); return docu; }
From source file:Main.java
public static Document openXmlFile(File file, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXParseException, SAXException { final String fname = file.getCanonicalPath(); DocumentBuilder builder = newDocumentBuilder(schema, isNamespaceAware, isXIncludeAware); Document docu;/*from www . j a v a2 s. c o m*/ builder.setErrorHandler(new org.xml.sax.ErrorHandler() { @Override public void error(SAXParseException exception) throws SAXParseException { //System.err.println("Parse Error in file " + fname + ", line " + exception.getLineNumber() + ": " + exception.getMessage()); throw new SAXParseException("Parse Error in file " + fname + ", line " + exception.getLineNumber() + ": " + exception.getMessage(), "", fname, exception.getLineNumber(), 0); } @Override public void fatalError(SAXParseException exception) throws SAXParseException { //System.err.println("Parse Fatal Error: " + exception.getMessage() + exception.getLineNumber()); throw new SAXParseException("Parse Error in file " + fname + ", line " + exception.getLineNumber() + ": " + exception.getMessage(), "", fname, exception.getLineNumber(), 0); } @Override public void warning(SAXParseException exception) { System.err.println("Parse Warning: " + exception.getMessage() + exception.getLineNumber()); } }); docu = builder.parse(file); return docu; }
From source file:org.gbif.harvest.digir.DigirHarvesterTest.java
/** * Test method for {@link org.gbif.harvest.biocase.BiocaseHarvester#search(String, String, String, String, String, * String, Boolean, String, int)}. Difference from test3Harvest() being that this mocks the RequestUtils execute * method always returning a WrappedSaxException instead of a Diagnostics object. *///from w w w . j a v a2s. c o m @Test public void testHarvestWithMockSAXParseException() throws IOException, OperationStoppedException, HarvesterException { // Mocked SAXException RequestUtils requestUtils = mock(RequestUtils.class); when(requestUtils.executeGetRequestAndReturnDiagnostics(anyString(), any(ProtocolTypeEnum.class), any(RequestResponseWriterManager.class))) // (String message, String publicId, String systemId, int lineNumber, int columnNumber) .thenThrow(new WrappedSaxException(new SAXParseException("msg", "pubId", "sysId", 1, 1))); harvester = new DigirHarvester(new TemplateUtils(), fileUtils, requestUtils, new DigesterUtils(fileUtils), gbifLogger); // runs through all name ranges, doesn't just terminate first time it encounters a SAXParseException harvester.search(TEST_RESOURCE, TEST_DESTINATION, targetDirectory.getAbsolutePath(), TEST_PROTOCOL, TEST_MAX_SEARCH_RESPONSE, TEST_TARGET_COUNT); // collect search request files (there were 2 ranges, 4 request per increment up to max target count size (5)) String[] files = targetDirectory.list(new PrefixFileFilter(Constants.SEARCH_REQUEST_FILENAME)); assertEquals(48, files.length); // there were no search response files because the exception was thrown each time files = targetDirectory.list(new PrefixFileFilter(Constants.SEARCH_RESPONSE_FILENAME)); assertEquals(0, files.length); log.info("Harvest was successful. Please check the folder " + TEST_DIRECTORY); }
From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.PomReader.java
public PomReader(final LocallyAvailableExternalResource resource) throws SAXException { final String systemId = resource.getLocalResource().getFile().toURI().toASCIIString(); Document pomDomDoc = resource.withContent(new Transformer<Document, InputStream>() { public Document transform(InputStream inputStream) { try { return parseToDom(inputStream, systemId); } catch (Exception e) { throw new MetaDataParseException("POM", resource, e); }//from w w w.j av a2s .c o m } }); projectElement = pomDomDoc.getDocumentElement(); if (!PROJECT.equals(projectElement.getNodeName()) && !MODEL.equals(projectElement.getNodeName())) { throw new SAXParseException("project must be the root tag", systemId, systemId, 0, 0); } parentElement = getFirstChildElement(projectElement, PARENT); setDefaultParentGavProperties(); setPomProperties(); setActiveProfileProperties(); }
From source file:stroom.pipeline.server.filter.SchemaFilter.java
/** * @see stroom.pipeline.server.filter.AbstractXMLFilter#startProcessing() *///from w ww . j a va2 s.c o m @Override public void startProcessing() { try { if (errorHandler == null) { errorHandler = new ErrorHandlerAdaptor(getElementId(), locationFactory, errorReceiverProxy) { @Override protected void log(final Severity severity, final SAXParseException exception) { String message = exception.getMessage(); if (message.contains("cvc-")) { message = CVC_PATTERN.matcher(message).replaceAll(""); } if (message.contains("One of")) { message = NS_REDUCTION_PATTERN.matcher(message).replaceAll(""); } message = message.trim(); final SAXParseException ex = new SAXParseException(message, exception.getPublicId(), exception.getSystemId(), exception.getLineNumber(), exception.getColumnNumber()); super.log(severity, ex); } }; } schemaLocations = null; prefixes.clear(); validator = null; } finally { super.startProcessing(); } }