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:com.textocat.textokit.commons.io.axml.AXMLContentHandler.java

private String getElementName(String uri, String localName, String qName) throws SAXParseException {
    String elemName = localName;//w ww .j a va2  s.  co m
    if (elemName.isEmpty()) {
        elemName = qName;
    }
    if (elemName.isEmpty()) {
        throw new SAXParseException("Could not determine element name", locator);
    }
    return elemName;
}

From source file:com.jkoolcloud.jesl.simulator.TNT4JSimulatorParserHandler.java

private void defineOption(Attributes attributes) throws SAXException {
    String name = null;/*from w ww .  j  a v a 2s .  c o m*/
    String value = null;

    try {
        for (int i = 0; i < attributes.getLength(); i++) {
            String attName = attributes.getQName(i);
            String attValue = expandEnvVars(attributes.getValue(i));

            if (attName.equals(SIM_XML_ATTR_NAME))
                name = attValue;
            else if (attName.equals(SIM_XML_ATTR_VALUE)) {
                value = attValue;
                String[] args = value.split(",");
                TNT4JSimulator.processArgs(this, args);
            } else {
                throw new SAXParseException("Unknown <" + SIM_XML_PROP + "> attribute '" + attName + "'",
                        saxLocator);
            }
        }

        if (StringUtils.isEmpty(name))
            throw new SAXParseException("<" + SIM_XML_VAR + ">: must specify '" + SIM_XML_ATTR_NAME + "'",
                    saxLocator);
        TNT4JSimulator.trace(simCurrTime, "Defining option: '" + name + "=" + value + "'");
    } catch (Exception e) {
        if (e instanceof SAXException)
            throw (SAXException) e;
        throw new SAXException("Failed processing definition for option '" + name + "': " + e, e);
    }
}

From source file:org.esco.grouper.parsing.SGSParsingUtil.java

/**
 * Handles the privilege informations./*from  w  w w  . j  a  v  a  2  s.c  o m*/
 * @throws SAXException If there is a parsing exception.
 * @throws UnknownTemplateElementTempateElement If the definition of the
 * privilege used a template element wich is not defined.
 */
protected void handlePrivileges() throws SAXException, UnknownTemplateElementTempateElement {

    // Checks the path.
    if (attributeHandler.getPath() == null || "".equals(attributeHandler.getPath())) {
        handleAttributeError(PRIVILEGE_TAG, SGSAttributeHandler.PATH_ATTR);
    }

    // Adds privilege to the current group or folder definition.
    final String resolvedPath = resolvePath(PRIVILEGE_TAG, attributeHandler.getPath());
    final PrivilegeDefinition privilege = new PrivilegeDefinition(attributeHandler.getRight(),
            new EvaluableString(resolvedPath));
    current.addPrivilege(privilege);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Adding privilege: " + privilege + " to the group or folder: " + current.getPath());
    }

    // The privilege must registered as a recursive one.
    if (attributeHandler.getRecursive()) {

        // Error if the recursive administring path is already defined.
        if (recPrivileges.contains(privilege)) {
            String originalStart = "";
            final Iterator<String> iter = startOfRecPrivileges.keySet().iterator();
            boolean found = false;
            while (iter.hasNext() && !found) {
                final String start = iter.next();
                final List<PrivilegeDefinition> recPriv = startOfRecPrivileges.get(start);
                if (recPriv.contains(privilege)) {
                    originalStart = start;
                    found = true;
                }
            }

            final String msg = "Encounters recursive privilege " + privilege + " for: " + currentPath
                    + " which is already defined for: " + originalStart + " (line " + locator.getLineNumber()
                    + ").";
            LOGGER.error(msg);
            throw new SAXParseException(msg, locator);
        }

        recPrivileges.add(privilege);
        List<PrivilegeDefinition> privilegesForCurrent = startOfRecPrivileges.get(currentPath);

        if (privilegesForCurrent == null) {
            privilegesForCurrent = new ArrayList<PrivilegeDefinition>();
            startOfRecPrivileges.put(currentPath, privilegesForCurrent);
        }
        privilegesForCurrent.add(privilege);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Registering starting point " + currentPath + " for recursive administrating path: "
                    + attributeHandler.getPath() + ".");
        }
    }
}

From source file:com.jkoolcloud.jesl.simulator.TNT4JSimulatorParserHandler.java

private void defineVar(Attributes attributes) throws SAXException {
    String name = null;/*ww w . j  a  va 2s.c o  m*/
    String value = null;

    try {
        for (int i = 0; i < attributes.getLength(); i++) {
            String attName = attributes.getQName(i);
            String attValue = expandEnvVars(attributes.getValue(i));

            if (attName.equals(SIM_XML_ATTR_NAME))
                name = attValue;
            else if (attName.equals(SIM_XML_ATTR_VALUE)) {
                value = processVarValue(attValue);
            } else {
                throw new SAXParseException("Unknown <" + SIM_XML_PROP + "> attribute '" + attName + "'",
                        saxLocator);
            }
        }

        if (StringUtils.isEmpty(name))
            throw new SAXParseException("<" + SIM_XML_VAR + ">: must specify '" + SIM_XML_ATTR_NAME + "'",
                    saxLocator);

        if (value.equalsIgnoreCase("=?")) {
            // requires input if not defined
            String oVal = vars.get(name);
            if (oVal == null) {
                value = processVarValue(TNT4JSimulator.readFromConsole("\nDefine variable [" + name + "]:"));
            } else {
                TNT4JSimulator.trace(simCurrTime, "Skipping duplicate variable: '" + name + "=" + value
                        + "', existing.value='" + oVal + "'");
            }
        }

        String eVal = vars.putIfAbsent(name, value);
        if (eVal != null) {
            TNT4JSimulator.trace(simCurrTime,
                    "Skipping duplicate variable: '" + name + "=" + value + "', existing.value='" + eVal + "'");
        }
        TNT4JSimulator.trace(simCurrTime, "Defining variable: '" + name + "=" + value + "'");
    } catch (Exception e) {
        if (e instanceof SAXException)
            throw (SAXException) e;
        throw new SAXException("Failed processing definition for variable '" + name + "': " + e, e);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    if (CONFIG_ROOT_ELMT.equals(qName) || CONFIG_ROOT_ELMT_OLD.equals(qName)) {
        if (streamsConfigData.isStreamsAvailable()) {
            throw new SAXParseException(
                    StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                            "ConfigParserHandler.multiple.elements", qName),
                    currParseLocation);/* w  w  w .  j  a v a2s  .  c om*/
        }
    } else if (PROPERTY_ELMT.equals(qName)) {
        processProperty(attributes);
    } else if (FIELD_ELMT.equals(qName)) {
        processField(attributes);
    } else if (FIELD_LOC_ELMT.equals(qName)) {
        processFieldLocator(attributes);
    } else if (FIELD_MAP_ELMT.equals(qName)) {
        processFieldMap(attributes);
    } else if (PARSER_REF_ELMT.equals(qName)) {
        processParserRef(attributes);
    } else if (PARSER_ELMT.equals(qName)) {
        processParser(attributes);
    } else if (STREAM_ELMT.equals(qName)) {
        processStream(attributes);
    } else if (FILTER_ELMT.equals(qName)) {
        processFilter(attributes);
    } else if (VALUE_ELMT.equals(qName)) {
        processValue(attributes);
    } else if (EXPRESSION_ELMT.equals(qName)) {
        processFilterExpression(attributes);
    } else if (TNT4J_PROPERTIES_ELMT.equals(qName)) {
        processTNT4JProperties(attributes);
    } else if (REF_ELMT.equals(qName)) {
        processReference(attributes);
    } else if (JAVA_OBJ_ELMT.equals(qName)) {
        processJavaObject(attributes);
    } else if (PARAM_ELMT.equals(qName)) {
        processParam(attributes);
    } else if (FIELD_TRANSFORM_ELMT.equals(qName)) {
        processFieldTransform(attributes);
    } else if (EMBEDDED_ACTIVITY_ELMT.equals(qName)) {
        processEmbeddedActivity(attributes);
    } else if (CACHE_ELMT.equals(qName)) {
        processCache(attributes);
    } else if (CACHE_ENTRY_ELMT.equals(qName)) {
        processCacheEntry(attributes);
    } else if (CACHE_KEY_ELMT.equals(qName)) {
        processKey(attributes);
    } else if (FIELD_MAP_REF_ELMT.equals(qName)) {
        processFieldMapReference(attributes);
    } else if (RESOURCE_REF_ELMT.equals(qName)) {
        processResourceReference(attributes);
    }
}

From source file:com.jkoolcloud.jesl.simulator.TNT4JSimulatorParserHandler.java

private void recordSource(Attributes attributes) throws SAXException {
    if (TNT4JSimulator.getIteration() > 1L)
        return;/*from   w  w  w. j  a  v a 2  s  . c  o m*/

    if (!SIM_XML_ROOT.equals(curElement))
        throw new SAXParseException(
                "<" + SIM_XML_SOURCE + ">: must have <" + SIM_XML_ROOT + "> as parent element", saxLocator);

    int id = 0;
    String fqn = null;
    String url = null;
    String user = null;

    try {
        for (int i = 0; i < attributes.getLength(); i++) {
            String attName = attributes.getQName(i);
            String attValue = expandEnvVars(attributes.getValue(i));

            if (attName.equals(SIM_XML_ATTR_ID))
                id = Integer.parseInt(attValue);
            else if (attName.equals(SIM_XML_ATTR_FQN))
                fqn = attValue;
            else if (attName.equals(SIM_XML_ATTR_USER))
                user = attValue;
            else if (attName.equals(SIM_XML_ATTR_URL))
                url = attValue;
            else
                throw new SAXParseException("Unknown <" + SIM_XML_SOURCE + "> attribute " + attName,
                        saxLocator);
        }

        if (id <= 0)
            throw new SAXParseException("<" + SIM_XML_SOURCE + "> element has missing or invalid "
                    + SIM_XML_ATTR_ID + " attribute ", saxLocator);

        if (sourceIds.containsKey(id))
            throw new SAXParseException(
                    "<" + SIM_XML_SOURCE + "> duplicate " + SIM_XML_ATTR_ID + " attribute: " + id, saxLocator);

        if (StringUtils.isEmpty(fqn))
            throw new SAXParseException(
                    "<" + SIM_XML_SOURCE + "> element is missing " + SIM_XML_ATTR_FQN + " attribute ",
                    saxLocator);

        if (sourceNames.containsKey(fqn))
            throw new SAXParseException(
                    "<" + SIM_XML_SOURCE + "> duplicate " + SIM_XML_ATTR_FQN + " attribute: " + fqn,
                    saxLocator);

        Source src = DefaultSourceFactory.getInstance().newFromFQN(fqn);
        if (!StringUtils.isEmpty(user))
            src.setUser(user);
        if (!StringUtils.isEmpty(url))
            src.setUrl(url);

        sourceNames.put(fqn, src);
        sourceIds.put(id, src);

        TrackerConfig srcCfg = DefaultConfigFactory.getInstance().getConfig(fqn);
        srcCfg.setSource(src);

        srcCfg.setProperty("Url", TNT4JSimulator.getConnectUrl());

        String token = TNT4JSimulator.getAccessToken();
        if (!StringUtils.isEmpty(token))
            srcCfg.setProperty("Token", token);

        Tracker tracker = trackerFactory.getInstance(srcCfg.build());
        trackers.put(fqn, tracker);
    } catch (Exception e) {
        if (e instanceof SAXException)
            throw (SAXException) e;
        throw new SAXParseException("Failed processing definition for source: ", saxLocator, e);
    }

    TNT4JSimulator.trace(simCurrTime, "Recording Server: " + fqn + " ...");
}

From source file:com.abstratt.mdd.core.util.MDDUtil.java

public static boolean isGenerated(java.net.URI uri) {
    if (cachedParserFactory == null) {
        cachedParserFactory = SAXParserFactory.newInstance();
    }//  w ww  . jav a 2s .c om
    SAXParser xmlParser;
    try {
        xmlParser = cachedParserFactory.newSAXParser();
    } catch (ParserConfigurationException e) {
        if (Platform.inDebugMode())
            LogUtils.logError(MDDCore.PLUGIN_ID, "Error creating XML parser", e);
        return false;
    } catch (SAXException e) {
        if (Platform.inDebugMode())
            LogUtils.logError(MDDCore.PLUGIN_ID, "Error creating XML parser", e);
        return false;
    }
    final boolean[] generated = { false };
    final boolean[] aborted = { false };
    InputStream stream = null;
    try {
        stream = new BufferedInputStream(uri.toURL().openStream());
        xmlParser.parse(stream, new DefaultHandler() {
            private boolean skipping = true;

            @Override
            public void startElement(String uri, String localName, String name, Attributes attributes)
                    throws SAXException {
                if (name.equalsIgnoreCase("eAnnotations"))
                    if (GENERATED.equals(attributes.getValue("source"))) {
                        generated[0] = true;
                        aborted[0] = true;
                        throw new SAXParseException("", null);
                    } else
                        return;
                if (!skipping) {
                    // should have seen the annotation by now
                    aborted[0] = true;
                    throw new SAXParseException("", null);
                }
                if (name.startsWith("uml"))
                    skipping = false;
            }
        });
    } catch (SAXException e) {
        if (!aborted[0] && Platform.inDebugMode())
            LogUtils.logError(MDDCore.PLUGIN_ID, "Error parsing " + uri, e);
    } catch (IOException e) {
        if (Platform.inDebugMode())
            LogUtils.logError(MDDCore.PLUGIN_ID, "Error parsing " + uri, e);
    } finally {
        if (stream != null)
            try {
                stream.close();
            } catch (IOException e) {
                // no biggie
            }
    }
    return generated[0];
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <key>} element under <entry> element.
 *
 * @param attrs/*from   w  ww.  ja  v  a 2  s  . co m*/
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processCacheEntry(Attributes attrs) throws SAXException {
    if (currCacheEntry != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration", CACHE_ENTRY_ELMT), currParseLocation);
    }

    if (processingCache == false) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration2", CACHE_ENTRY_ELMT, CACHE_ELMT),
                currParseLocation);
    }

    if (currCacheEntry == null) {
        currCacheEntry = new CacheEntryData();
    }

    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (ID_ATTR.equals(attName)) {
            currCacheEntry.id = attValue;
        }
    }

    notEmpty(currCacheEntry.id, CACHE_ENTRY_ELMT, ID_ATTR);
}

From source file:com.jkoolcloud.jesl.simulator.TNT4JSimulatorParserHandler.java

private void recordSnapshot(Attributes attributes) throws SAXException {
    if ((curActivity == null || !SIM_XML_ACTIVITY.equals(curElement))
            && (curEvent == null || !SIM_XML_EVENT.equals(curElement))) {
        throw new SAXParseException("<" + SIM_XML_SNAPSHOT + ">: must have <" + SIM_XML_ACTIVITY + "> or <"
                + SIM_XML_EVENT + "> as parent element", saxLocator);
    }/*  w ww . j a  va  2  s  . com*/

    String name = null;
    String category = null;
    OpLevel severity = OpLevel.INFO;

    try {
        for (int i = 0; i < attributes.getLength(); i++) {
            String attName = attributes.getQName(i);
            String attValue = expandEnvVars(attributes.getValue(i));

            if (attName.equals(SIM_XML_ATTR_NAME)) {
                name = attValue;
                TNT4JSimulator.trace(simCurrTime, "Recording Snapshot: " + attValue + " ...");
            } else if (attName.equals(SIM_XML_ATTR_CAT)) {
                category = attValue;
            } else if (attName.equals(SIM_XML_ATTR_SEVERITY)) {
                severity = getLevel(attValue);
            } else {
                throw new SAXParseException("Unknown <" + SIM_XML_SNAPSHOT + "> attribute '" + attName + "'",
                        saxLocator);
            }
        }

        if (StringUtils.isEmpty(name))
            throw new SAXParseException("<" + SIM_XML_SNAPSHOT + ">: missing '" + SIM_XML_ATTR_NAME + "'",
                    saxLocator);

        if (StringUtils.isEmpty(category))
            category = null;

        curSnapshot = new PropertySnapshot(category, name, severity, simCurrTime);
        curSnapshot.setTTL(TNT4JSimulator.getTTL());
    } catch (Exception e) {
        if (e instanceof SAXException)
            throw (SAXException) e;
        throw new SAXException("Failed processing definition for snapshot '" + name + "': " + e, e);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <key>} element under <entry> element.
 *
 * @param attrs//from  w  w w  .j  a  va  2 s.  c om
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processKey(Attributes attrs) throws SAXException {
    if (currCacheEntry == null) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration2", CACHE_KEY_ELMT, CACHE_ENTRY_ELMT),
                currParseLocation);
    }

    elementData = new StringBuilder();
}