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:Main.java

static String[] typeDescription(String type, String defaultNameSpace, Node node) throws SAXParseException {
    final String typeNameSpace;
    final String typeName;
    String[] split = type.split(":");
    switch (split.length) {
    case 1:/*from   w ww .  j a va2  s  .c om*/
        typeNameSpace = defaultNameSpace;
        typeName = split[0];
        break;
    case 2:
        typeNameSpace = node.lookupNamespaceURI(split[0]);
        typeName = split[1];
        break;
    default:
        throw new SAXParseException("Illegal type format: " + type, null);
    }
    return new String[] { typeNameSpace, typeName };
}

From source file:net.sf.joost.instruction.MessageFactory.java

public NodeBase createNode(NodeBase parent, String qName, Attributes attrs, ParseContext context)
        throws SAXParseException {
    Tree selectExpr = parseExpr(attrs.getValue("select"), context);
    Tree terminateAVT = parseAVT(attrs.getValue("terminate"), context);
    int level = getEnumAttValue("level", attrs, LEVEL_VALUES, context);

    String loggerAtt = attrs.getValue("logger");

    // if one of 'level' or 'logger' is present, we need both
    if ((level != -1) ^ (loggerAtt != null))
        throw new SAXParseException(level != -1 ? "Missing 'logger' attribute when 'level' is present"
                : "Missing 'level' attribute when 'logger' is present", context.locator);

    checkAttributes(qName, attrs, attrNames, context);
    return new Instance(qName, parent, context, selectExpr, terminateAVT, level, loggerAtt);
}

From source file:net.sf.joost.instruction.PDocumentFactory.java

public NodeBase createNode(NodeBase parent, String qName, Attributes attrs, ParseContext context)
        throws SAXParseException {
    Tree href = parseRequiredExpr(qName, attrs, "href", context);

    Tree baseAVT = parseAVT(attrs.getValue("base"), context);

    String groupAtt = attrs.getValue("group");

    String filterMethodAtt = attrs.getValue("filter-method");

    if (groupAtt != null && filterMethodAtt != null)
        throw new SAXParseException("It's not allowed to use both 'group' and 'filter-method' " + "attributes",
                context.locator);//from   w ww.  j ava  2 s. c  o m

    String filterSrcAtt = attrs.getValue("filter-src");

    if (filterSrcAtt != null && filterMethodAtt == null)
        throw new SAXParseException(
                "Missing 'filter-method' attribute in '" + qName + "' ('filter-src' is present)",
                context.locator);

    checkAttributes(qName, attrs, attrNames, context);
    return new Instance(qName, parent, context, href, baseAVT, groupAtt, filterMethodAtt, filterSrcAtt);
}

From source file:net.javacrumbs.springws.test.helper.MessageValidatorTest.java

@Test(expected = WsTestException.class)
public void testValidateGenericFail() throws IOException {
    XmlValidator validator = createMock(XmlValidator.class);
    expect(validator.validate((Source) anyObject()))
            .andReturn(new SAXParseException[] { new SAXParseException("Test message", null) });
    replay(validator);//from  w  ww .  ja  v a  2  s  .  co m

    WebServiceMessage message = createMessage("xml/invalid-message.xml");
    new MessageValidator(message).validate(validator);

    verify(validator);
}

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

private void processScenario(Attributes attrs) throws SAXParseException {
    if (currScenario != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration", SCENARIO_ELMT), currParseLocation);
    }//from   w  w w .j  a va 2s .  com

    String name = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            name = attValue;
        }
    }

    notEmpty(name, SCENARIO_ELMT, NAME_ATTR);

    currScenario = new WsScenario(name);
}

From source file:com.textocat.textokit.commons.io.axml.AXMLContentHandler.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    String elemName = getElementName(uri, localName, qName);
    if (readingBody) {
        onAnnotationStart(elemName, attributes);
    } else if (E_DOC.equals(elemName)) {
        onDocStart();/*from   w ww. j av  a2 s . c o m*/
    } else if (E_META.equals(elemName)) {
        onMetaStart(attributes);
    } else if (E_BODY.equals(elemName)) {
        onBodyStart();
    } else if (E_ALIASES.equals(elemName)) {
        onAliasesStart();
    } else if (E_ALIAS.equals(elemName)) {
        onAliasStart(attributes);
    } else if (E_FEATURE_ALIAS.equals(elemName)) {
        onFeatureAliasStart(attributes);
    } else {
        throw new SAXParseException(String.format("Unknown element '%s'", elemName), locator);
    }
}

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

private void processScenarioStep(Attributes attrs) throws SAXException {
    if (currScenario == null) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.malformed.configuration2", STEP_ELMT, SCENARIO_ELMT),
                currParseLocation);/* ww  w  .  j av  a  2  s  .  co  m*/
    }
    String name = null;
    String url = null;
    String method = null;
    String username = null;
    String password = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            name = attValue;
        } else if (URL_ATTR.equals(attName)) {
            url = attValue;
        } else if (METHOD_ATTR.equals(attName)) {
            method = attValue;
        } else if (USERMAME_ATTR.equals(attName)) {
            username = attValue;
        } else if (PASSWORD_ATTR.equals(attName)) {
            password = attValue;
        }
    }
    notEmpty(name, STEP_ELMT, NAME_ATTR);

    currStep = new WsScenarioStep(name);
    currStep.setUrlStr(url);
    currStep.setMethod(method);
    currStep.setCredentials(username, password);
}

From source file:com.spoledge.util.xml.XMLValidatorInstance.java

/**
 * XML parser method./*from w w  w.  j  av a 2s . com*/
 */
public void error(SAXParseException e) throws SAXException {
    throw new SAXParseException("line " + locator.getLineNumber() + " column " + locator.getColumnNumber()
            + (lastStartElement != null ? " in '" + lastStartElement + "'"
                    : (lastEndElement != null ? " after '" + lastEndElement + "'" : ""))
            + ": " + e.getMessage(), locator);
}

From source file:com.textocat.textokit.commons.io.axml.AXMLContentHandler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    String elemName = getElementName(uri, localName, qName);
    if (readingBody) {
        if (E_BODY.equals(elemName)) {
            onBodyEnd();//from   w ww . java 2 s . c  o m
        } else {
            onAnnotationEnd(elemName);
        }
    } else if (E_DOC.equals(elemName)) {
        onDocEnd();
    } else if (E_ALIASES.equals(elemName)) {
        onAliasesEnd();
    } else if (E_ALIAS.equals(elemName)) {
        onAliasEnd();
    } else if (E_FEATURE_ALIAS.equals(elemName)) {
        onFeatureAliasEnd();
    } else if (E_META.equals(elemName)) {
        onMetaEnd();
    } else {
        throw new SAXParseException(String.format("End of unknown element '%s'", elemName), locator);
    }
}

From source file:com.spoledge.util.xml.XMLValidatorInstance.java

/**
 * XML parser method.//from  w w  w. j  a v a 2  s .c o  m
 */
public void fatalError(SAXParseException e) throws SAXException {
    throw new SAXParseException("line " + locator.getLineNumber() + " column " + locator.getColumnNumber()
            + (lastStartElement != null ? " in '" + lastStartElement + "'"
                    : (lastEndElement != null ? " after '" + lastEndElement + "'" : ""))
            + ": " + e.getMessage(), locator);
}