Example usage for org.xml.sax SAXParseException getLineNumber

List of usage examples for org.xml.sax SAXParseException getLineNumber

Introduction

In this page you can find the example usage for org.xml.sax SAXParseException getLineNumber.

Prototype

public int getLineNumber() 

Source Link

Document

The line number of the end of the text where the exception occurred.

Usage

From source file:org.unitedinternet.cosmo.calendar.hcalendar.HCalendarParser.java

/**
 * Parse./*from w ww  .j a va  2s  .c o  m*/
 * @param in The input source.
 * @param handler The content handler.
 * @throws IOException - if something is wrong this exception is thrown.
 * @throws ParserException - if something is wrong this exception is thrown.
 */
private void parse(InputSource in, ContentHandler handler) throws IOException, ParserException {
    try {
        Document d = BUILDER_FACTORY.newDocumentBuilder().parse(in);
        buildCalendar(d, handler);
    } catch (ParserConfigurationException e) {
        throw new CosmoParseException(e);
    } catch (SAXException e) {
        if (e instanceof SAXParseException) {
            SAXParseException pe = (SAXParseException) e;
            throw new ParserException("Could not parse XML", pe.getLineNumber(), e);
        }
        throw new ParserException(e.getMessage(), -1, e);
    }
}

From source file:org.vulpe.commons.xml.XMLReader.java

public List<XMLAttribute> reader(final String xml) {
    final List<XMLAttribute> attributeList = new ArrayList<XMLAttribute>();
    if (StringUtils.isNotEmpty(xml)) {
        try {// w w  w  . j a  v a 2  s.  com
            final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            final ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf-8"));
            final Document document = docBuilder.parse(bais);
            final Node entity = document.getChildNodes().item(0);
            final NodeList atributos = entity.getChildNodes();
            for (int i = 0; i < atributos.getLength(); i++) {
                final String attribute = atributos.item(i).getNodeName();
                if (!"#text".equals(attribute)) {
                    final String value = getChildTagValue((Element) entity, attribute);
                    attributeList.add(new XMLAttribute(attribute, value));
                }
            }
        } catch (SAXParseException err) {
            LOG.error("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
            LOG.error(" " + err.getMessage());
        } catch (SAXException e) {
            final Exception exception = e.getException();
            LOG.error(((exception == null) ? e.getMessage() : exception.getMessage()));
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
    }
    return attributeList;
}

From source file:org.webcurator.domain.MockPermissionTemplateDAO.java

public MockPermissionTemplateDAO(String filename) {

    super();//from www  .jav  a  2 s  .  c  o  m
    try {
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        theFile = docBuilder.parse(new File(filename));

        NodeList permissionNodes = theFile.getElementsByTagName("permission");

        // force a nested load of everything
        // loadPermissionsFromNodeList(permissionNodes);
    } catch (SAXParseException err) {
        log.debug("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
        log.debug(" " + err.getMessage());
    } catch (SAXException se) {
        Exception x = se.getException();
        ((x == null) ? se : x).printStackTrace();
    } catch (Exception e) {
        log.debug(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:org.wso2.carbon.bpel.common.LoggingErrorHandler.java

private String formatMessage(String level, SAXParseException spe) {
    StringBuilder sb = new StringBuilder(64);

    if (spe.getSystemId() != null) {
        sb.append(spe.getSystemId());/*  w  ww.ja v  a 2 s  .  c  o  m*/
    }

    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.wso2.carbon.identity.entitlement.pap.PAPPolicyReader.java

/**
 * {@inheritDoc}//from   w w w  .  ja  va2s  .c om
 */
public void warning(SAXParseException exception) throws SAXException {
    if (log.isWarnEnabled()) {
        String message = null;
        message = "Warning on line " + exception.getLineNumber() + ": " + exception.getMessage();
        log.warn(message);
    }
}

From source file:org.wso2.carbon.identity.entitlement.pap.PAPPolicyReader.java

/**
 * {@inheritDoc}/* ww  w.  ja  v a  2 s. c  o  m*/
 */
public void error(SAXParseException exception) throws SAXException {
    if (log.isWarnEnabled()) {
        log.warn("Error on line " + exception.getLineNumber() + ": " + exception.getMessage() + " ... "
                + "Policy will not be available");
    }

    throw new SAXException("error parsing policy");
}

From source file:org.wso2.carbon.identity.entitlement.pap.PAPPolicyReader.java

/**
 * {@inheritDoc}//from  ww w .  j a v  a  2 s .c  o  m
 */
public void fatalError(SAXParseException exception) throws SAXException {
    if (log.isWarnEnabled()) {
        log.warn("Fatal error on line " + exception.getLineNumber() + ": " + exception.getMessage() + " ... "
                + "Policy will not be available");
    }

    throw new SAXException("fatal error parsing policy");
}

From source file:org.yawlfoundation.yawl.unmarshal.YawlXMLSpecificationValidator.java

private String getLineNumber(SAXParseException e) {
    return (e.getSystemId() != null) ? "[ln: " + e.getLineNumber() + " col: " + e.getColumnNumber() + "]" : "";
}

From source file:pl.nask.hsn2.workflow.parser.HWLParser.java

private WorkflowSyntaxException makeWorkflowSyntaxException(JAXBException e) {
    int lineNo = -1;
    int colNo = -1;
    String msg = e.getMessage();//from w ww  .j a v  a 2s.co  m
    if (e.getLinkedException() instanceof SAXParseException) {
        SAXParseException linked = (SAXParseException) e.getLinkedException();
        lineNo = linked.getLineNumber();
        colNo = linked.getColumnNumber();
        msg = linked.getMessage();
    }

    return new WorkflowSyntaxException(e, lineNo, colNo, msg);
}

From source file:simpleserver.config.DTDEntityResolver.java

private void printExceptionInfo(SAXParseException e) {
    System.out.println(prefix + "L. " + e.getLineNumber() + ": " + e.getMessage());
    parent.loadsuccess = false;/*from  w  w  w.  jav  a  2 s .  c  o m*/
}