List of usage examples for org.xml.sax SAXParseException getLineNumber
public int getLineNumber()
From source file:org.ajax4jsf.renderkit.compiler.HtmlCompiler.java
public PreparedTemplate compile(Reader input) { // By default - empty result. we not throw any exceptions in compile phase - // since it can be in static class initialization. PreparedTemplate result = null;/* w w w.ja va 2 s. c o m*/ try { digestr.clear(); digestr.push(new RootElement()); result = (PreparedTemplate) digestr.parse(input); } catch (SAXParseException e) { // TODO - locate compilation error. How get name ? String errorstr = Messages.getMessage(Messages.PARSING_TEMPLATE_ERROR, new Object[] { "" + e.getLineNumber(), "" + e.getColumnNumber(), e.toString() }); // errorstr.append(digestr.getDocumentLocator().getLineNumber()).append(" and position ").append(digestr.getDocumentLocator().getColumnNumber()); log.error(errorstr, e); result = new CompiledError(errorstr.toString(), e); } catch (IOException e) { String errorstr = Messages.getMessage(Messages.TEMPLATE_IO_ERROR, e.toString()); log.error(errorstr, e); result = new CompiledError(errorstr.toString(), e); } catch (SAXException e) { String errorstr = Messages.getMessage(Messages.PARSING_TEMPLATE_ERROR_2, e.toString()); log.error(errorstr, e); result = new CompiledError(errorstr.toString(), e); } return result; }
From source file:org.ajax4jsf.renderkit.compiler.HtmlCompiler.java
/** * Compile input {@link InputStream} to {@link PreparedTemplate} - set of Java classes to encode as JSF output. * @param input stream with template XML text. * @param sourcename ( optional ) name of resource, for debug purposes. * @return compiled template./*from www . ja v a2 s . c om*/ */ public PreparedTemplate compile(InputStream input, String sourcename) { // By default - empty result. we not throw any exceptions in compile phase - // since it can be in static class initialization. PreparedTemplate result = null; try { if (log.isDebugEnabled()) { log.debug(Messages.getMessage(Messages.START_COMPILE_TEMPLATE_INFO, sourcename)); } digestr.clear(); RootElement root = new RootElement(); root.setTemplateName(sourcename); digestr.push(root); result = (PreparedTemplate) digestr.parse(input); } catch (SAXParseException e) { // TODO - locate compilation error. How get name ? String errorstr = Messages.getMessage(Messages.PARSING_TEMPLATE_ERROR_a, new Object[] { sourcename, "" + e.getLineNumber(), "" + e.getColumnNumber(), e.toString() }); // errorstr.append(digestr.getDocumentLocator().getLineNumber()).append(" and position ").append(digestr.getDocumentLocator().getColumnNumber()); log.error(errorstr, e); result = new CompiledError(errorstr.toString(), e); } catch (IOException e) { String errorstr = Messages.getMessage(Messages.TEMPLATE_IO_ERROR_a, sourcename, e.toString()); log.error(errorstr, e); result = new CompiledError(errorstr.toString(), e); } catch (SAXException e) { String errorstr = Messages.getMessage(Messages.PARSING_TEMPLATE_ERROR_2a, sourcename, e.toString()); log.error(errorstr, e); result = new CompiledError(errorstr.toString(), e); } if (log.isDebugEnabled()) { log.debug(Messages.getMessage(Messages.FINISH_COMPILE_TEMPLATE_INFO, sourcename)); } return result; }
From source file:org.apache.cocoon.components.notification.DefaultNotifyingBuilder.java
/** * Builds a Notifying object (SimpleNotifyingBean in this case) * that tries to explain what the Object o can reveal. * * @param sender who sent this Object./*from ww w.j a va2 s . co m*/ * @param o the object to use when building the SimpleNotifyingBean * @return the Notifying Object that was build * @see org.apache.cocoon.components.notification.Notifying */ public Notifying build(Object sender, Object o) { if (o instanceof Notifying) { return (Notifying) o; } else if (o instanceof Throwable) { Throwable t = (Throwable) o; SimpleNotifyingBean n = new SimpleNotifyingBean(sender); n.setType(Notifying.ERROR_NOTIFICATION); n.setTitle("An Error Occurred"); if (t != null) { Throwable rootCause = getRootCause(t); n.setSource(t.getClass().getName()); // NullPointerException usually does not have a message if (rootCause.getMessage() != null) { n.setMessage(rootCause.getMessage()); } else { n.setMessage(t.getMessage()); } n.setDescription(t.toString()); n.addExtraDescription(Notifying.EXTRA_CAUSE, rootCause.toString()); if (rootCause instanceof SAXParseException) { SAXParseException saxParseException = (SAXParseException) rootCause; n.addExtraDescription(Notifying.EXTRA_LOCATION, String.valueOf(saxParseException.getSystemId())); n.addExtraDescription(Notifying.EXTRA_LINE, String.valueOf(saxParseException.getLineNumber())); n.addExtraDescription(Notifying.EXTRA_COLUMN, String.valueOf(saxParseException.getColumnNumber())); } else if (rootCause instanceof TransformerException) { TransformerException transformerException = (TransformerException) rootCause; SourceLocator sourceLocator = transformerException.getLocator(); if (null != sourceLocator) { n.addExtraDescription(Notifying.EXTRA_LOCATION, String.valueOf(sourceLocator.getSystemId())); n.addExtraDescription(Notifying.EXTRA_LINE, String.valueOf(sourceLocator.getLineNumber())); n.addExtraDescription(Notifying.EXTRA_COLUMN, String.valueOf(sourceLocator.getColumnNumber())); } } // Add root cause exception stacktrace StringWriter sw = new StringWriter(); rootCause.printStackTrace(new PrintWriter(sw)); n.addExtraDescription(Notifying.EXTRA_STACKTRACE, sw.toString()); // Add full exception chain sw = new StringWriter(); appendTraceChain(sw, t); n.addExtraDescription(Notifying.EXTRA_FULLTRACE, sw.toString()); } return n; } else { SimpleNotifyingBean n = new SimpleNotifyingBean(sender); n.setType(Notifying.UNKNOWN_NOTIFICATION); n.setTitle("Object Notification"); n.setMessage(String.valueOf(o)); n.setDescription("No details available."); return n; } }
From source file:org.apache.maven.doxia.module.fo.FoAggregateSinkTest.java
/** * Test the FO PDF generation with some special characters in company name. *//*from ww w .ja v a 2 s . co m*/ public void testSpecialCharacters() throws IOException, TransformerException { DocumentModel model = new DocumentModel(); DocumentCover cover = new DocumentCover(); cover.setCompanyName("Partner & Friends"); cover.setCoverTitle("A Masterpice in Encoding Theory <>&"); cover.setCoverSubTitle("Some nice Encodings & <METHODS>"); cover.setProjectName("A Masterpice in Encoding Theory <>&"); cover.setAuthor("Partner & Friends"); model.setCover(cover); File foFile = File.createTempFile("fo-test", ".fo"); File pdfFile = File.createTempFile("fo-test", ".pdf"); try { sink = new FoAggregateSink(WriterFactory.newXmlWriter(foFile)); sink.setDocumentModel(model); sink.setDocumentTitle("A Masterpice in Encoding Theory <>&"); sink.beginDocument(); sink.coverPage(); // sink.toc(); sink.endDocument(); } finally { sink.close(); } try { FoUtils.convertFO2PDF(foFile, pdfFile, null, model); } catch (TransformerException e) { if ((e.getCause() != null) && (e.getCause() instanceof SAXParseException)) { SAXParseException sax = (SAXParseException) e.getCause(); StringBuffer sb = new StringBuffer(); sb.append("Error creating PDF from ").append(foFile.getAbsolutePath()).append(":") .append(sax.getLineNumber()).append(":").append(sax.getColumnNumber()).append("\n"); sb.append(e.getMessage()); throw new RuntimeException(sb.toString()); } throw new TransformerException("Error creating PDF from " + foFile + ": " + e.getMessage()); } }
From source file:org.apache.myfaces.shared_impl.util.xml.MyFacesErrorHandler.java
private String getMessage(SAXParseException exception) { StringBuffer buf = new StringBuffer(); buf.append("SAXParseException at"); buf.append(" URI="); buf.append(exception.getSystemId()); buf.append(" Line="); buf.append(exception.getLineNumber()); buf.append(" Column="); buf.append(exception.getColumnNumber()); return buf.toString(); }
From source file:org.apache.nifi.cluster.manager.impl.WebClusterManager.java
private Document parse(final byte[] serialized) throws SAXException, ParserConfigurationException, IOException { final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true);/*from ww w . j a va 2 s. co m*/ final DocumentBuilder builder = docFactory.newDocumentBuilder(); builder.setErrorHandler(new org.xml.sax.ErrorHandler() { @Override public void fatalError(final SAXParseException err) throws SAXException { logger.error("Config file line " + err.getLineNumber() + ", col " + err.getColumnNumber() + ", uri " + err.getSystemId() + " :message: " + err.getMessage()); if (logger.isDebugEnabled()) { logger.error("Error Stack Dump", err); } throw err; } @Override public void error(final SAXParseException err) throws SAXParseException { logger.error("Config file line " + err.getLineNumber() + ", col " + err.getColumnNumber() + ", uri " + err.getSystemId() + " :message: " + err.getMessage()); if (logger.isDebugEnabled()) { logger.error("Error Stack Dump", err); } throw err; } @Override public void warning(final SAXParseException err) throws SAXParseException { logger.warn(" Config file line " + err.getLineNumber() + ", uri " + err.getSystemId() + " : message : " + err.getMessage()); if (logger.isDebugEnabled()) { logger.warn("Warning stack dump", err); } throw err; } }); // build the docuemnt final Document document = builder.parse(new ByteArrayInputStream(serialized)); return document; }
From source file:org.apache.nifi.controller.service.ControllerServiceLoader.java
public List<ControllerServiceNode> loadControllerServices(final ControllerServiceProvider provider) throws IOException { final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); InputStream fis = null;//from w ww . j ava 2s . c o m BufferedInputStream bis = null; documentBuilderFactory.setNamespaceAware(true); final List<ControllerServiceNode> services = new ArrayList<>(); try { final URL configurationResource = this.getClass().getResource("/ControllerServiceConfiguration.xsd"); if (configurationResource == null) { throw new NullPointerException("Unable to load XML Schema for ControllerServiceConfiguration"); } final Schema schema = schemaFactory.newSchema(configurationResource); documentBuilderFactory.setSchema(schema); final DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); builder.setErrorHandler(new org.xml.sax.ErrorHandler() { @Override public void fatalError(final SAXParseException err) throws SAXException { logger.error("Config file line " + err.getLineNumber() + ", col " + err.getColumnNumber() + ", uri " + err.getSystemId() + " :message: " + err.getMessage()); if (logger.isDebugEnabled()) { logger.error("Error Stack Dump", err); } throw err; } @Override public void error(final SAXParseException err) throws SAXParseException { logger.error("Config file line " + err.getLineNumber() + ", col " + err.getColumnNumber() + ", uri " + err.getSystemId() + " :message: " + err.getMessage()); if (logger.isDebugEnabled()) { logger.error("Error Stack Dump", err); } throw err; } @Override public void warning(final SAXParseException err) throws SAXParseException { logger.warn(" Config file line " + err.getLineNumber() + ", uri " + err.getSystemId() + " : message : " + err.getMessage()); if (logger.isDebugEnabled()) { logger.warn("Warning stack dump", err); } throw err; } }); //if controllerService.xml does not exist, create an empty file... fis = Files.newInputStream(this.serviceConfigXmlPath, StandardOpenOption.READ); bis = new BufferedInputStream(fis); if (Files.size(this.serviceConfigXmlPath) > 0) { final Document document = builder.parse(bis); final NodeList servicesNodes = document.getElementsByTagName("services"); final Element servicesElement = (Element) servicesNodes.item(0); final List<Element> serviceNodes = DomUtils.getChildElementsByTagName(servicesElement, "service"); for (final Element serviceElement : serviceNodes) { //get properties for the specific controller task - id, name, class, //and schedulingPeriod must be set final String serviceId = DomUtils.getChild(serviceElement, "identifier").getTextContent() .trim(); final String serviceClass = DomUtils.getChild(serviceElement, "class").getTextContent().trim(); //set the class to be used for the configured controller task final ControllerServiceNode serviceNode = provider.createControllerService(serviceClass, serviceId, false); //optional task-specific properties for (final Element optionalProperty : DomUtils.getChildElementsByTagName(serviceElement, "property")) { final String name = optionalProperty.getAttribute("name").trim(); final String value = optionalProperty.getTextContent().trim(); serviceNode.setProperty(name, value); } services.add(serviceNode); provider.enableControllerService(serviceNode); } } } catch (SAXException | ParserConfigurationException sxe) { throw new IOException(sxe); } finally { FileUtils.closeQuietly(fis); FileUtils.closeQuietly(bis); } return services; }
From source file:org.apache.ode.utils.sax.LoggingErrorHandler.java
private String formatMessage(String level, SAXParseException spe) { StringBuffer sb = new StringBuffer(64); if (spe.getSystemId() != null) { sb.append(spe.getSystemId());//from ww w . jav a 2s. com } sb.append(':'); sb.append(spe.getLineNumber()); sb.append(':'); sb.append(spe.getColumnNumber()); sb.append(':'); sb.append(level); sb.append(':'); sb.append(spe.getMessage()); return sb.toString(); }
From source file:org.apache.tomcat.util.digester.Digester.java
/** * Forward notification of a parsing error to the application supplied * error handler (if any).// ww w . ja v a2s . com * * @param exception The error information * * @exception SAXException if a parsing exception occurs */ public void error(SAXParseException exception) throws SAXException { log.error("Parse Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); if (errorHandler != null) { errorHandler.error(exception); } }
From source file:org.apache.tomcat.util.digester.Digester.java
/** * Forward notification of a fatal parsing error to the application * supplied error handler (if any).//from w w w . j a v a 2 s . c om * * @param exception The fatal error information * * @exception SAXException if a parsing exception occurs */ public void fatalError(SAXParseException exception) throws SAXException { log.error("Parse Fatal Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); if (errorHandler != null) { errorHandler.fatalError(exception); } }