Example usage for org.xml.sax SAXParseException SAXParseException

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

Introduction

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

Prototype

public SAXParseException(String message, Locator locator) 

Source Link

Document

Create a new SAXParseException from a message and a Locator.

Usage

From source file:org.jcurl.core.io.SetupSaxDeSer.java

@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes atts)
        throws SAXException {
    // log.debug("[" + localName + "] [" + qName + "] [" + uri + "]");
    final String elem = qName;
    final String parent = elems.size() > 0 ? (String) elems.peek() : null;
    final String grandParent = elems.size() > 1 ? (String) elems.get(elems.size() - 2) : null;
    elems.push(elem);/*  w w w  . j a v a  2 s  .  c om*/
    if (log.isDebugEnabled())
        log.debug(elems + " " + atts.getLength());
    buf.setLength(0);
    try {
        // check
        switch (elems.size()) {
        case 1:
            if ("jcurl".equals(elem))
                ;
            else
                break;
            return;
        case 2:
            if ("setup".equals(elem))
                ;
            else
                break;
            return;
        case 3:
            if ("meta".equals(elem))
                ;
            else if ("model".equals(elem)) {
                modelClass = Class.forName(atts.getValue("engine"));
                modelProps.clear();
            } else if ("positions".equals(elem))
                ;
            else if ("speeds".equals(elem))
                ;
            else
                break;
            return;
        case 4:
            if ("event".equals(elem))
                ;
            else if ("game".equals(elem))
                ;
            else if ("description".equals(elem) && "model".equals(parent))
                ;
            else if ("param".equals(elem) && "model".equals(parent)) {
                final String key = atts.getValue("name");
                final String val = atts.getValue("val");
                final String dim = atts.getValue("dim");
                if (dim != null)
                    modelProps.put(key, new DimVal(Double.parseDouble(val), Dim.find(dim)));
                else
                    modelProps.put(key, val);
            } else if ("rock".equals(elem))
                currRock = new RockIdx(atts);
            else
                break;
            return;
        case 5:
            if ("a".equals(elem))
                if ("positions".equals(grandParent))
                    setup.setAngle(currRock.idx16, getDim(atts));
                else if ("speeds".equals(grandParent))
                    setup.setSpin(currRock.idx16, getDim(atts));
                else
                    break;
            else if ("x".equals(elem))
                if ("positions".equals(grandParent))
                    setup.setPosX(currRock.idx16, getDim(atts));
                else if ("speeds".equals(grandParent))
                    setup.setSpeedX(currRock.idx16, getDim(atts));
                else
                    break;
            else if ("y".equals(elem))
                if ("positions".equals(grandParent))
                    setup.setPosY(currRock.idx16, getDim(atts));
                else if ("speeds".equals(grandParent))
                    setup.setSpeedY(currRock.idx16, getDim(atts));
                else
                    break;
            else if ("out".equals(elem))
                if ("positions".equals(grandParent))
                    setup.setPosOut(currRock.idx16);
                else
                    break;
            else if ("nearhog".equals(elem))
                if ("positions".equals(grandParent))
                    setup.setPosNHog(currRock.idx16);
                else
                    break;
            else if ("to_x".equals(elem))
                if ("speeds".equals(grandParent))
                    setup.setToX(currRock.idx16, getDim(atts));
                else
                    break;
            else if ("to_y".equals(elem))
                if ("speeds".equals(grandParent))
                    setup.setToY(currRock.idx16, getDim(atts));
                else
                    break;
            else if ("speed".equals(elem))
                if ("speeds".equals(grandParent))
                    setup.setSpeed(currRock.idx16, getDim(atts));
                else
                    break;
            else if ("spin".equals(elem))
                if ("speeds".equals(grandParent))
                    setup.setSpin(currRock.idx16, getDim(atts));
                else
                    break;
            else
                break;
            return;
        }
        error(new SAXParseException("unexpected element [" + elem + "]", locator));
    } catch (final RuntimeException e) {
        log.warn("error in [" + elems + "]", e);
        error(new SAXParseException("error in [" + elems + "]", locator, e));
    } catch (final ClassNotFoundException e) {
        log.warn("error in [" + elems + "]", e);
        error(new SAXParseException("error in [" + elems + "]", locator, e));
    }
}

From source file:org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper.java

public void importSchema(File mondrianFile, String databaseConnection, String parameters) {

    try {/*from   w  w  w . j ava2s. c o m*/
        String datasourceInfo = "Provider=mondrian;DataSource=" + databaseConnection; //$NON-NLS-1$
        if (!StringUtils.isEmpty(parameters)) {
            datasourceInfo = parameters;
        }

        // Note: Mondrian parameters could be validated here and throw subsequent exception if they do not conform to
        // spec.

        FileInputStream parsingInputStream = new FileInputStream(mondrianFile);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        org.w3c.dom.Document document = builder.parse(parsingInputStream);
        NodeList schemas = document.getElementsByTagName("Schema"); //$NON-NLS-1$
        Node schema = schemas.item(0);
        if (schema == null) {
            throw new SAXParseException("", null); // Generic schema error message will be provided at catch statement.
        }
        Node name = schema.getAttributes().getNamedItem("name"); //$NON-NLS-1$
        String catalogName = name.getTextContent();
        parsingInputStream.close();

        FileInputStream schemaInputStream = new FileInputStream(mondrianFile);
        org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper helper = new org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper(
                PentahoSystem.get(IUnifiedRepository.class));
        helper.addSchema(schemaInputStream, catalogName, datasourceInfo);

        reInit(PentahoSessionHolder.getSession());

        flushCacheForCatalog(catalogName, PentahoSessionHolder.getSession());
    } catch (SAXParseException e) {
        throw new MondrianCatalogServiceException(
                Messages.getInstance().getString("MondrianCatalogHelper.ERROR_0018_IMPORT_SCHEMA_ERROR")); //$NON-NLS-1$
    } catch (Exception e) {
        throw new MondrianCatalogServiceException(
                Messages.getInstance().getString("MondrianCatalogHelper.ERROR_0008_ERROR_OCCURRED"), //$NON-NLS-1$
                Reason.valueOf(e.getMessage()));
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.bundle.content.ContentRootElementHandler.java

/**
 * Starts parsing.//from   w w w . j  av  a2  s  .  c  om
 *
 * @param attrs
 *          the attributes.
 * @throws SAXException
 *           if there is a parsing error.
 */
protected void startParsing(final Attributes attrs) throws SAXException {
    final Object maybeReport = getRootHandler().getHelperObject(ReportParserUtil.HELPER_OBJ_REPORT_NAME);
    if (maybeReport instanceof MasterReport == false) {
        // replace it ..
        report = new MasterReport();
        report.setAttribute(AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.FILEFORMAT,
                "unified-fileformat");

        final ResourceKey key = getRootHandler().getSource();
        if (key.getParent() != null) {
            final ResourceManager resourceManager = getRootHandler().getResourceManager();
            try {
                final Resource bundleData = resourceManager.create(key.getParent(), null, DocumentBundle.class);
                final DocumentBundle documentBundle = (DocumentBundle) bundleData.getResource();
                report.setBundle(documentBundle);

                final DocumentMetaData metaData = documentBundle.getMetaData();
                final int versionMajorRaw = getBundleAttribute(metaData, "prpt-spec.version.major");
                final int versionMinorRaw = getBundleAttribute(metaData, "prpt-spec.version.minor");
                final int versionPatchRaw = getBundleAttribute(metaData, "prpt-spec.version.patch");

                if (versionMajorRaw == -1 || versionMinorRaw == -1 || versionPatchRaw == -1
                        || (versionMajorRaw == 0 && versionMinorRaw == 0 && versionPatchRaw == 0)) {
                    // any of the version attributes is missing. Assume we are running with a legacy report.
                    getRootHandler().setHelperObject(PRPT_SPEC_VERSION,
                            ClassicEngineBoot.computeVersionId(3, 8, 0));
                } else {
                    validateVersionNumbers(versionMajorRaw, versionMinorRaw, versionPatchRaw);

                    // file has been created with at least 3.9.0 or a development version. Therefore the
                    // version number is set to either the number or zero for dev versions.
                    getRootHandler().setHelperObject(PRPT_SPEC_VERSION, ClassicEngineBoot
                            .computeVersionId(versionMajorRaw, versionMinorRaw, versionPatchRaw));
                }
            } catch (ResourceException e) {
                getRootHandler().warning(new SAXParseException(
                        "Unable to load the bundle. Bundle data may be unavailable.", getLocator()));
            }
        }
    } else {
        report = (MasterReport) maybeReport;
    }
}

From source file:org.plasma.sdo.xml.DefaultErrorHandler.java

public void error(SAXParseException e) throws SAXException {
    String msg = "line:column[" + e.getLineNumber() + ":" + e.getColumnNumber() + "]";
    msg += " - " + e.getMessage();
    if (options.isFailOnValidationError()) {
        throw new SAXParseException(msg, new ErrorLocator(e));
    } else {/*from   w  w w  .j  a  va 2  s  . com*/
        if (options.getValidationLog() != null) {
            options.getValidationLog().error(msg);
        } else
            log.error(msg);
    }
}

From source file:org.plasma.sdo.xml.DefaultErrorHandler.java

public void fatalError(SAXParseException e) throws SAXException {
    String msg = "line:column[" + e.getLineNumber() + ":" + e.getColumnNumber() + "]";
    msg += " - " + e.getMessage();
    if (options.isFailOnValidationError()) {
        throw new SAXParseException(msg, new ErrorLocator(e));
    } else {/*from ww  w .  j  a  v  a  2 s  . co m*/
        if (options.getValidationLog() != null) {
            options.getValidationLog().fatal(msg);
        } else
            log.fatal(msg);
    }
}

From source file:stroom.pipeline.server.filter.SchemaFilter.java

private void fatalError(final CharBuffer sb) throws SAXException {
    final String message = sb.toString();
    sb.clear();//from   w w  w  .j  ava 2 s . com

    final SAXParseException exception = new SAXParseException(message, locator);
    errorHandler.fatalError(exception);

    // If we aren't stepping then throw an exception to terminate early.
    if (!pipelineContext.isStepping()) {
        throw new LoggedException(message, exception);
    }
}

From source file:stroom.pipeline.server.filter.SchemaFilter.java

private void deprecatedSchema(final String uri) throws SAXException {
    sb.append("Schema is deprecated: ");
    sb.append(uri);/*from w ww .ja va 2 s .  c  om*/
    errorHandler.warning(new SAXParseException(sb.toString(), locator));
    sb.clear();
}

From source file:stroom.pipeline.server.filter.SchemaFilter.java

private ValidatorHandler getValidator() throws SAXException {
    ValidatorHandler validatorHandler = null;

    if (schemaValidation && schemaPool != null) {
        // Put back the old schema if we need to.
        returnCurrentSchema();/*  ww  w .jav a 2  s.com*/

        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        sb.append("<xsd:schema xmlns:xsd=\"");
        sb.append(schemaLanguage);
        sb.append("\"");
        final CharBuffer namespaces = new CharBuffer(100);
        final CharBuffer locations = new CharBuffer(100);
        for (final String prefix : prefixes.keySet()) {
            final String namespace = prefixes.get(prefix);
            final String location = schemaLocations.get(namespace);
            if (location != null) {
                namespaces.append(" xmlns");
                if (prefix.length() > 0) {
                    namespaces.append(":");
                    namespaces.append(prefix);
                }
                namespaces.append("=\"");
                namespaces.append(namespace);
                namespaces.append("\"");

                locations.append("<xsd:import namespace=\"");
                locations.append(namespace);
                locations.append("\" schemaLocation=\"");
                locations.append(location);
                locations.append("\"/>\n");
            }
        }
        sb.append(namespaces.toString());
        sb.append(">\n");
        sb.append(locations.toString());
        sb.append("</xsd:schema>");

        final String data = sb.toString();
        sb.clear();

        // Get another schema.
        final SchemaKey schemaKey = new SchemaKey(schemaLanguage, data);
        poolItem = schemaPool.borrowObject(schemaKey, true);
        final StoredSchema storedSchema = poolItem.getValue();

        // Replay errors generated when creating schema.
        try {
            storedSchema.getErrorReceiver().replay(errorReceiverProxy);
        } catch (final Exception e) {
            errorHandler.fatalError(new SAXParseException(e.getMessage(), null));
        }

        // Create a validator handler.
        validatorHandler = storedSchema.getSchema().newValidatorHandler();
        validatorHandler.setDocumentLocator(locator);
        validatorHandler.setErrorHandler(errorHandler);

        validatorHandler.startDocument();
        for (final String prefix : prefixes.keySet()) {
            validatorHandler.startPrefixMapping(prefix, prefixes.get(prefix));
        }
    }

    return validatorHandler;
}