Example usage for org.xml.sax SAXParseException getSystemId

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

Introduction

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

Prototype

public String getSystemId() 

Source Link

Document

Get the system identifier of the entity where the exception occurred.

Usage

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/** Prints the error message. */
private void printError(final String messageType, final SAXParseException exception) {

    System.err.print("[");
    System.err.print(messageType);
    System.err.print("] ");
    String systemId = exception.getSystemId();
    if (systemId != null) {
        final int index = systemId.lastIndexOf('/');
        if (index != -1) {
            systemId = systemId.substring(index + 1);
        }//from  w  ww.j a  v a  2  s. c  o  m
        System.err.print(systemId);
    }
    System.err.print(':');
    System.err.print(exception.getLineNumber());
    System.err.print(':');
    System.err.print(exception.getColumnNumber());
    System.err.print(": ");
    System.err.print(exception.getMessage());
    System.err.println();
    System.err.flush();

}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

/**
* This can be used to read additional schemas even after the registry was initialized.
*//*from   w w  w. j  ava 2s  . c  o m*/
public void initialize() throws SAXException, IOException, SchemaException {
    if (prismContext == null) {
        throw new IllegalStateException("Prism context not set");
    }
    if (namespacePrefixMapper == null) {
        throw new IllegalStateException("Namespace prefix mapper not set");
    }
    try {
        initResolver();
        parsePrismSchemas();
        parseJavaxSchema();
        compileCompileTimeClassList();
        initialized = true;

    } catch (SAXException ex) {
        if (ex instanceof SAXParseException) {
            SAXParseException sex = (SAXParseException) ex;
            throw new SchemaException("Error parsing schema " + sex.getSystemId() + " line "
                    + sex.getLineNumber() + ": " + sex.getMessage());
        }
        throw ex;
    }
}

From source file:Writer.java

/** Prints the error message. */
protected void printError(String type, SAXParseException ex) {

    System.err.print("[");
    System.err.print(type);/*from  w  ww  .j a  v  a 2s .  c  om*/
    System.err.print("] ");
    String systemId = ex.getSystemId();
    if (systemId != null) {
        int index = systemId.lastIndexOf('/');
        if (index != -1)
            systemId = systemId.substring(index + 1);
        System.err.print(systemId);
    }
    System.err.print(':');
    System.err.print(ex.getLineNumber());
    System.err.print(':');
    System.err.print(ex.getColumnNumber());
    System.err.print(": ");
    System.err.print(ex.getMessage());
    System.err.println();
    System.err.flush();

}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistryImpl.java

/**
* This can be used to read additional schemas even after the registry was initialized.
*//*www. ja  v a  2  s. c o  m*/
@Override
public void initialize() throws SAXException, IOException, SchemaException {
    if (prismContext == null) {
        throw new IllegalStateException("Prism context not set");
    }
    if (namespacePrefixMapper == null) {
        throw new IllegalStateException("Namespace prefix mapper not set");
    }
    try {
        LOGGER.trace("initialize() starting");
        long start = System.currentTimeMillis();

        initResolver();
        long resolverDone = System.currentTimeMillis();
        LOGGER.trace("initResolver() done in {} ms", resolverDone - start);

        parsePrismSchemas();
        long prismSchemasDone = System.currentTimeMillis();
        LOGGER.trace("parsePrismSchemas() done in {} ms", prismSchemasDone - resolverDone);

        parseJavaxSchema();
        long javaxSchemasDone = System.currentTimeMillis();
        LOGGER.trace("parseJavaxSchema() done in {} ms", javaxSchemasDone - prismSchemasDone);

        compileCompileTimeClassList();
        long classesDone = System.currentTimeMillis();
        LOGGER.trace("compileCompileTimeClassList() done in {} ms", classesDone - javaxSchemasDone);

        initialized = true;
    } catch (SAXException ex) {
        if (ex instanceof SAXParseException) {
            SAXParseException sex = (SAXParseException) ex;
            throw new SchemaException("Error parsing schema " + sex.getSystemId() + " line "
                    + sex.getLineNumber() + ": " + sex.getMessage(), sex);
        }
        throw ex;
    }
}

From source file:com.cablelabs.sim.PCSim2.java

/**
 * This method determines whether the global presence server needs to be started
 * /* w w  w  . j a  v a 2s .com*/
 */
private boolean configPresenceServer() {
    presenceServerEnabled = SystemSettings.getBooleanSetting("Presence Server");
    if (presenceServerEnabled) {
        Properties platform = SystemSettings.getSettings(SettingConstants.PLATFORM);
        String psName = platform.getProperty(SettingConstants.PRESENCE_SERVER_FSM);
        if (presenceServerFile == null) {
            presenceServerFile = psName;
        } else if (presenceServerFile.equals(psName)) {
            return true;
        } else {
            if (stacks != null)
                stacks.shutdownPresenceServer();
            presenceServerFile = psName;
        }
        if (presenceServerFile != null) {
            File ps = new File(presenceServerFile);
            if (ps != null && ps.exists() && ps.canRead() && ps.isFile()) {
                TSParser tsp = new TSParser(false);
                try {
                    logger.info(PC2LogCategory.Parser, subCat,
                            "Parsing document " + presenceServerFile + " for PresenceServer processing.");
                    TSDocument psDoc = tsp.parse(presenceServerFile);
                    LinkedList<FSM> fsms = psDoc.getFsms();
                    if (fsms.size() == 1) {
                        FSM f = fsms.getFirst();
                        if (f.getModel() instanceof PresenceModel) {
                            PresenceModel model = (PresenceModel) f.getModel();
                            // Initialize the settings that can be overwritten from
                            // within the document 
                            setExtensions(fsms);
                            PresenceServer server = PresenceServer.getInstance(f, model.getElements());
                            if (server != null) {
                                Stacks.setPresenceServer(server);
                                server.init();
                                return true;
                            }
                        }

                    }
                } catch (PC2XMLException pe) {
                    String err = "\n** Parsing error in file \n    " + pe.getFileName() + " at line "
                            + pe.getLineNumber();
                    if (pe.getSystemId() != null) {
                        err += ", uri " + pe.getSystemId();
                    }
                    if (pe.getPublicId() != null) {
                        err += ", public " + pe.getPublicId();
                    }
                    err += "\n";

                    logger.fatal(PC2LogCategory.Parser, subCat, err, pe);
                } catch (SAXParseException spe) {
                    String err = "\n** Parsing error in file \n    " + presenceServerFile + " at line "
                            + spe.getLineNumber();
                    if (spe.getSystemId() != null) {
                        err += ", uri " + spe.getSystemId();
                    }
                    if (spe.getPublicId() != null) {
                        err += ", public " + spe.getPublicId();
                    }
                    err += "\n";

                    logger.fatal(PC2LogCategory.Parser, subCat, err, spe);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                //               if (ps == null) {
                //                  logger.fatal(PC2LogCategory.Parser, subCat,
                //                        "The platform configuration file doesn't appear to have a " 
                //                        + "value for the \"Presence Server FSM\" setting.");
                //               }
                if (!ps.exists()) {
                    logger.fatal(PC2LogCategory.Parser, subCat, "The \"Presence Server FSM\" setting=[" + ps
                            + "] doesn't appear to define a valid path or file name.");
                }
                if (!ps.canRead()) {
                    logger.fatal(PC2LogCategory.Parser, subCat,
                            "The \"Presence Server FSM\" setting=[" + ps + "] can not be read by the system.");
                }
                if (!ps.isFile()) {
                    logger.fatal(PC2LogCategory.Parser, subCat, "The \"Presence Server FSM\" setting=[" + ps
                            + "] doesn't appear to define a file.");
                }
            }
        }
    }
    return false;
}

From source file:com.cablelabs.sim.PCSim2.java

/**
 * This method determines whether the global registration needs to be started
 * /*from w  ww .j  av  a  2s  .  co m*/
 */
private boolean configGlobalRegistrar() {
    globalRegEnabled = SystemSettings.getBooleanSetting("Global Registrar");
    if (globalRegEnabled) {
        Properties platform = SystemSettings.getSettings(SettingConstants.PLATFORM);
        String grName = platform.getProperty(SettingConstants.GLOBAL_REGISTRAR_FSM);
        if (globalRegFile == null) {
            globalRegFile = grName;
        } else if (globalRegFile.equals(grName)) {
            return true;
        } else {
            if (stacks != null)
                stacks.shutdownGlobalRegistrars();
            globalRegFile = grName;
        }
        if (globalRegFile != null) {
            File gr = new File(globalRegFile);
            if (gr != null && gr.exists() && gr.canRead() && gr.isFile()) {
                TSParser tsp = new TSParser(false);
                try {
                    logger.info(PC2LogCategory.Parser, subCat,
                            "Parsing document " + globalRegFile + " for GlobalRegistrar processing.");
                    TSDocument grDoc = tsp.parse(globalRegFile);
                    LinkedList<FSM> fsms = grDoc.getFsms();
                    if (fsms.size() == 1) {
                        // Initialize the settings that can be overwritten from
                        // within the document 
                        setExtensions(fsms);
                        FSM grFsm = fsms.getFirst();
                        String transport = grFsm.getModel().getProperty(SettingConstants.TRANSPORT_PROTOCOL);
                        Transport t = Transport.UDP;
                        if (transport != null) {
                            if (transport.equals(Transport.UDP.toString()))
                                t = Transport.UDP;
                            else if (transport.equals(Transport.TCP.toString()))
                                t = Transport.TCP;
                            else if (transport.equals(Transport.TLS.toString()))
                                t = Transport.TLS;
                        } else {
                            if (platform != null) {
                                transport = platform.getProperty(SettingConstants.SIP_DEF_TRANPORT_PROTOCOL);
                                if (transport != null) {
                                    if (transport.equals(Transport.UDP.toString()))
                                        t = Transport.UDP;
                                    else if (transport.equals(Transport.TCP.toString()))
                                        t = Transport.TCP;
                                    else if (transport.equals(Transport.TLS.toString()))
                                        t = Transport.TLS;
                                }
                            }
                        }
                        GlobalRegistrar.setMasterFSM(grFsm, t);

                        return true;

                    }
                } catch (PC2XMLException pe) {
                    String err = "\n** Parsing error in file \n    " + pe.getFileName() + " at line "
                            + pe.getLineNumber();
                    if (pe.getSystemId() != null) {
                        err += ", uri " + pe.getSystemId();
                    }
                    if (pe.getPublicId() != null) {
                        err += ", public " + pe.getPublicId();
                    }
                    err += "\n";

                    logger.fatal(PC2LogCategory.Parser, subCat, err, pe);
                } catch (SAXParseException spe) {
                    String err = "\n** Parsing error in file \n    " + globalRegFile + " at line "
                            + spe.getLineNumber();
                    if (spe.getSystemId() != null) {
                        err += ", uri " + spe.getSystemId();
                    }
                    if (spe.getPublicId() != null) {
                        err += ", public " + spe.getPublicId();
                    }
                    err += "\n";

                    logger.fatal(PC2LogCategory.Parser, subCat, err, spe);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                //               if (gr == null) {
                //                  logger.fatal(PC2LogCategory.Parser, subCat,
                //                        "The platform configuration file doesn't appear to have a " 
                //                        + "value for the \"Global Registrar FSM\" setting.");
                //               }
                if (!gr.exists()) {
                    logger.fatal(PC2LogCategory.Parser, subCat, "The \"Global Registrar FSM\" setting=[" + gr
                            + "] doesn't appear to define a valid path or file name.");
                }
                if (!gr.canRead()) {
                    logger.fatal(PC2LogCategory.Parser, subCat,
                            "The \"Global Registrar FSM\" setting=[" + gr + "] can not be read by the system.");
                }
                if (!gr.isFile()) {
                    logger.fatal(PC2LogCategory.Parser, subCat, "The \"Global Registrar FSM\" setting=[" + gr
                            + "] doesn't appear to define a file.");
                }
            }

        }
    }
    return false;
}

From source file:com.cablelabs.sim.PCSim2.java

/**
 * Parses the XML Document passed into the application.
 * /*from   w  w  w.j  ava 2  s .  c om*/
 * @param args - the fully-qualified name of the test
 *          script document.
 * @return - true if the document parsed successfully, 
 *          false otherwise.
 */
protected boolean parseAndStart() {
    //String ts = testScriptFiles.getFirst(); 
    File f = new File(activeTestScriptFile);
    if (f != null) {
        logger.info(PC2LogCategory.Parser, subCat, "Using input document " + activeTestScriptFile);

        TSParser tsp = new TSParser(true);
        try {
            doc = tsp.parse(activeTestScriptFile);
            logPackage();
            logger.info(PC2LogCategory.Parser, subCat,
                    "Using input document " + activeTestScriptFile + " v." + doc.getVersion());

            Stacks.logStackSocketInformation();
            ss.setDynamicPlatformSettings(doc.getProperties());
            ss.logSettings();

            // Now see if we are running a test for an UE and if so
            // See if we should auto provision the device?
            ProvisioningData pd = autoProvision(doc.getName());
            if (pd != null) {
                String macAddr = autoGenerate(pd);
                if (macAddr != null) {
                    // doc.setAutoProv(pd);
                    logger.info(PC2LogCategory.PCSim2, subCat,
                            "Updating the global registrar's that the DUT is rebooting");

                    ProvListener pl = new ProvListener(pd);
                    if (pl != null) {
                        logger.debug(PC2LogCategory.PCSim2, subCat,
                                "Starting the provisioning listener operation.");
                        autoProvisioned = pl.run();
                        if (!autoProvisioned) {
                            logger.error(PC2LogCategory.PCSim2, subCat,
                                    "Auto provisioning did not occur as expected, test is terminating.");
                            provDB.clearIssuedData(macAddr);
                            return false;
                        } else {
                            Properties dut = SystemSettings.getSettings(SettingConstants.DUT);
                            String pui = dut.getProperty(SettingConstants.PUI);
                            if (pui != null)
                                Stacks.generateAutoRebootEvent(pui);
                            String pui2 = dut.getProperty(SettingConstants.PUI2);
                            if (pui2 != null)
                                Stacks.generateAutoRebootEvent(pui2);
                            logger.info(PC2LogCategory.PCSim2, subCat,
                                    "Test execution pausing while resetting the DUT.");
                            Thread.sleep(5000);
                            logger.info(PC2LogCategory.PCSim2, subCat, "Pause complete.");
                        }
                    }
                } else {
                    logger.info(PC2LogCategory.PCSim2, subCat,
                            "Auto generate didn't return an updated data file for provisioning.");
                }
            } else {
                logger.info(PC2LogCategory.PCSim2, subCat,
                        "Auto provisioning did not return a data file for the device.");
            }

            LinkedList<FSM> fsms = doc.getFsms();
            // Initialize the settings that can be overwritten from
            // within the document 
            setExtensions(fsms);
            if (doc.getInspector())
                ss.enableInspector();

            for (int i = 0; i < fsms.size(); i++) {
                FSM fsm = fsms.get(i);
                PC2Models testModel = null;
                String modelName = fsm.getModel().getName();
                if (modelName.equalsIgnoreCase("session")) {
                    testModel = new Session(fsm);
                    if (testModel != null)
                        testModel.init();
                    try {
                        fsm.getNetworkElements().certify();
                    } catch (PC2Exception e) {

                    }
                } else if (modelName.equalsIgnoreCase(MsgRef.STUN_MSG_TYPE)) {
                    testModel = new Stun(fsm);
                    if (testModel != null)
                        testModel.init();
                    //if (!fsm.getNetworkElements().certify())
                    //   return false;
                } else if (modelName.equalsIgnoreCase("registrar")) {
                    Properties dut = SystemSettings.getSettings("DUT");
                    String pui = dut.getProperty(SettingConstants.PUI);
                    Properties platform = SystemSettings.getSettings(SettingConstants.PLATFORM);
                    String destIP = platform.getProperty(SettingConstants.IP);
                    if (pui != null) {
                        testModel = new Registrar(fsm, pui, destIP);
                        if (testModel != null)
                            testModel.init();
                        try {
                            fsm.getNetworkElements().certify();
                        } catch (PC2Exception e) {

                        }
                    } else
                        return false;
                }
                if (modelName.equalsIgnoreCase("register")) {
                    testModel = new Register(fsm);
                    if (testModel != null)
                        testModel.init();
                    try {
                        fsm.getNetworkElements().certify();
                    } catch (PC2Exception e) {

                    }
                }

                if (testModel != null) {
                    testModel.start();
                    activeModels.add(testModel);
                }
            }
            return true;
        } catch (PC2XMLException pe) {
            String err = "\n** Parsing error in file \n    " + pe.getFileName() + " at line "
                    + pe.getLineNumber();
            if (pe.getSystemId() != null) {
                err += ", uri " + pe.getSystemId();
            }
            if (pe.getPublicId() != null) {
                err += ", public " + pe.getPublicId();
            }
            err += "\n";

            logger.fatal(PC2LogCategory.Parser, subCat, err, pe);
        } catch (SAXParseException spe) {
            String err = "\n** Parsing error in file \n    " + activeTestScriptFile + " at line "
                    + spe.getLineNumber();
            if (spe.getSystemId() != null) {
                err += ", uri " + spe.getSystemId();
            }
            if (spe.getPublicId() != null) {
                err += ", public " + spe.getPublicId();
            }
            err += "\n";

            logger.fatal(PC2LogCategory.Parser, subCat, err, spe);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return false;
}

From source file:nl.nn.adapterframework.core.IbisException.java

public String getExceptionSpecificDetails(Throwable t) {
    String result = null;//from  w  ww .jav  a2  s .  c om
    if (t instanceof AddressException) {
        AddressException ae = (AddressException) t;
        String parsedString = ae.getRef();
        if (StringUtils.isNotEmpty(parsedString)) {
            result = addPart(result, " ", "[" + parsedString + "]");
        }
        int column = ae.getPos() + 1;
        if (column > 0) {
            result = addPart(result, " ", "at column [" + column + "]");
        }
    }
    if (t instanceof SAXParseException) {
        SAXParseException spe = (SAXParseException) t;
        int line = spe.getLineNumber();
        int col = spe.getColumnNumber();
        String sysid = spe.getSystemId();

        String locationInfo = null;
        if (StringUtils.isNotEmpty(sysid)) {
            locationInfo = "SystemId [" + sysid + "]";
        }
        if (line >= 0) {
            locationInfo = addPart(locationInfo, " ", "line [" + line + "]");
        }
        if (col >= 0) {
            locationInfo = addPart(locationInfo, " ", "column [" + col + "]");
        }
        result = addPart(locationInfo, ": ", result);
    }
    if (t instanceof TransformerException) {
        TransformerException te = (TransformerException) t;
        SourceLocator locator = te.getLocator();
        if (locator != null) {
            int line = locator.getLineNumber();
            int col = locator.getColumnNumber();
            String sysid = locator.getSystemId();

            String locationInfo = null;
            if (StringUtils.isNotEmpty(sysid)) {
                locationInfo = "SystemId [" + sysid + "]";
            }
            if (line >= 0) {
                locationInfo = addPart(locationInfo, " ", "line [" + line + "]");
            }
            if (col >= 0) {
                locationInfo = addPart(locationInfo, " ", "column [" + col + "]");
            }
            result = addPart(locationInfo, ": ", result);
        }
    }
    if (t instanceof SQLException) {
        SQLException sqle = (SQLException) t;
        int errorCode = sqle.getErrorCode();
        String sqlState = sqle.getSQLState();
        if (errorCode != 0) {
            result = addPart("errorCode [" + errorCode + "]", ", ", result);
        }
        if (StringUtils.isNotEmpty(sqlState)) {
            result = addPart("SQLState [" + sqlState + "]", ", ", result);
        }
    }
    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./*  w w w  . ja  va2  s  .c o 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.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();
}