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.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

@SuppressWarnings("unchecked")
private void handleFieldTransform(FieldTransformData currTransformData) throws SAXException {
    String eDataVal = getElementData();

    if (eDataVal != null) {
        if (StringUtils.isNotEmpty(currTransformData.beanRef) && eDataVal.length() > 0) {
            throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                    "ConfigParserHandler.element.has.both3", FIELD_TRANSFORM_ELMT, BEAN_REF_ATTR,
                    getLocationInfo()));
        } else if (currTransformData.scriptCode == null) {
            currTransformData.scriptCode = eDataVal;
        }//from   ww  w .j a  va 2  s .c  om
    }

    if (StringUtils.isEmpty(currTransformData.beanRef) && StringUtils.isEmpty(currTransformData.scriptCode)) {
        throw new SAXParseException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "ConfigParserHandler.must.contain", FIELD_TRANSFORM_ELMT, BEAN_REF_ATTR, CDATA),
                currParseLocation);
    }

    ValueTransformation<Object, Object> transform;

    if (StringUtils.isNotEmpty(currTransformData.beanRef)) {
        Object tObj = javaObjectsMap.get(currTransformData.beanRef);

        if (tObj == null) {
            throw new SAXParseException(StreamsResources.getStringFormatted(
                    StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.undefined.reference",
                    FIELD_TRANSFORM_ELMT, currTransformData.beanRef), currParseLocation);
        }

        if (tObj instanceof ValueTransformation) {
            transform = (ValueTransformation<Object, Object>) tObj;
        } else {
            throw new SAXNotSupportedException(
                    StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                            "ConfigParserHandler.not.extend.class", FIELD_TRANSFORM_ELMT, BEAN_REF_ATTR,
                            tObj.getClass().getName(), ValueTransformation.class.getName(), getLocationInfo()));
        }
    } else {
        transform = AbstractScriptTransformation.createScriptTransformation(currTransformData.name,
                currTransformData.scriptLang, currTransformData.scriptCode);
    }

    if (currLocatorData != null) {
        currLocatorData.valueTransforms.add(transform);
    } else {
        currField.addTransformation(transform);
    }
}

From source file:nl.nn.adapterframework.align.ToXml.java

public void handleError(String msg) throws SAXException {
    ErrorHandler errorHandler = validatorHandler.getErrorHandler();
    if (errorHandler != null) {
        errorHandler.error(new SAXParseException(msg, null));
    } else {/*from   w ww . java  2s  .c o  m*/
        throw new SAXException(msg);
    }
}

From source file:nl.nn.adapterframework.align.ToXml.java

public void handleError(SAXException e) throws SAXException {
    ErrorHandler errorHandler = validatorHandler.getErrorHandler();
    if (errorHandler != null) {
        errorHandler.error(new SAXParseException(e.getMessage(), null));
    } else {//from   ww w. ja v  a2s.c  o  m
        throw e;
    }
}

From source file:nl.nn.adapterframework.extensions.sap.jco2.IdocXmlHandler.java

public void characters(char[] ch, int start, int length) throws SAXException {
    if (currentField == null) {
        String part = new String(ch, start, length).trim();
        if (StringUtils.isNotEmpty(part)) {
            throw new SAXParseException("found character content [" + part + "] outside a field", locator);
        }/*from  ww w  .  j a v a2s.c o m*/
        return;
    }
    currentFieldValue.append(ch, start, length);
}

From source file:org.jajuk.base.TestCollection.java

/**
 * Test method for./* www.ja  va 2 s .  c om*/
 *
 * {@link org.jajuk.base.Collection#warning(org.xml.sax.SAXParseException)}.
 */
public final void testWarningSAXParseException() {
    Collection coll = Collection.getInstance();
    try {
        coll.warning(new SAXParseException("Testexception", null));
        fail("Should throw exception here...");
    } catch (SAXException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Testexception"));
    }
}

From source file:org.jajuk.base.TestCollection.java

/**
 * Test method for./*w w  w  . j  av  a2  s .co m*/
 *
 * @throws Exception the exception
 * {@link org.jajuk.base.Collection#error(org.xml.sax.SAXParseException)}.
 */
public final void testErrorSAXParseException() throws Exception {
    Collection coll = Collection.getInstance();
    try {
        coll.error(new SAXParseException("Testexception", null));
        fail("Should throw exception here...");
    } catch (SAXException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Testexception"));
    }
}

From source file:org.jajuk.base.TestCollection.java

/**
 * Test method for.//w  w  w. j  ava  2 s .com
 *
 * @throws Exception the exception
 * {@link org.jajuk.base.Collection#fatalError(org.xml.sax.SAXParseException)}
 * .
 */
public final void testFatalErrorSAXParseException() throws Exception {
    Collection coll = Collection.getInstance();
    try {
        coll.fatalError(new SAXParseException("Testexception", null));
        fail("Should throw exception here...");
    } catch (SAXException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Testexception"));
    }
}

From source file:org.jajuk.services.bookmark.TestHistory.java

/**
 * Test method for.//www  .  j  a va 2  s  .  c  o m
 *
 * {@link org.jajuk.services.bookmark.History#warning(org.xml.sax.SAXParseException)}
 * .
 */
public final void testWarningSAXParseException() {
    try {
        History.getInstance().warning(new SAXParseException("testmessage", null));
        fail("Will throw exception");
    } catch (SAXException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("testmessage"));
    }
}

From source file:org.jajuk.services.bookmark.TestHistory.java

/**
 * Test method for./*www  . j a va  2 s .  co  m*/
 *
 * {@link org.jajuk.services.bookmark.History#error(org.xml.sax.SAXParseException)}
 * .
 */
public final void testErrorSAXParseException() {
    try {
        History.getInstance().error(new SAXParseException("testmessage", null));
        fail("Will throw exception");
    } catch (SAXException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("testmessage"));
    }
}

From source file:org.jajuk.services.bookmark.TestHistory.java

/**
 * Test method for.//from  w ww .j  a v a  2 s  .c  o  m
 *
 * {@link org.jajuk.services.bookmark.History#fatalError(org.xml.sax.SAXParseException)}
 * .
 */
public final void testFatalErrorSAXParseException() {
    try {
        History.getInstance().fatalError(new SAXParseException("testmessage", null));
        fail("Will throw exception");
    } catch (SAXException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("testmessage"));
    }
}