org.apache.xerces.parsers.SAXParser Java Examples

The following examples show how to use org.apache.xerces.parsers.SAXParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SourceBean.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public static SourceBean fromXMLStream(InputSource stream, boolean trimCharacters, boolean upperCase) throws SourceBeanException {
	if (stream == null) {
		TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.WARNING, "SourceBean::fromXMLStream: stream nullo");
		return null;
	} // if (stream == null)
	SourceBean sourceBean = null;
	XMLReader parser = new SAXParser();
	try {
		SourceBeanContentHandler contentHandler = new SourceBeanContentHandler(trimCharacters, upperCase);
		parser.setContentHandler(contentHandler);
		parser.parse(stream);
		sourceBean = contentHandler.getSourceBean();
	} // try
	catch (Exception ex) {
		TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.CRITICAL, "SourceBean::fromXMLString: impossibile elaborare lo stream XML", ex);
		throw new SourceBeanException("Impossibile elaborare lo stream XML");
	} // catch (Exception ex) try
	return sourceBean;
}
 
Example #2
Source File: XMLValidator.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private static void checkExternalSchema(Map<String, String> result, SAXParser reader)
		throws SAXNotRecognizedException, SAXNotSupportedException {
	if (result != null) {
		String noNamespaceSchemaLocation = result.get(IExternalSchemaLocationProvider.NO_NAMESPACE_SCHEMA_LOCATION);
		if (noNamespaceSchemaLocation != null) {
			reader.setProperty(IExternalSchemaLocationProvider.NO_NAMESPACE_SCHEMA_LOCATION,
					noNamespaceSchemaLocation);
		}
	}
}
 
Example #3
Source File: SourceBean.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SourceBean fromXMLStream(InputSource stream, boolean trimCharacters, boolean  upperCase)
	throws SourceBeanException {
    if (stream == null) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.WARNING,
            "SourceBean::fromXMLStream: stream nullo");
        return null;
    } // if (stream == null)
    SourceBean sourceBean = null;
    XMLReader parser = new SAXParser();
    try {
        SourceBeanContentHandler contentHandler =
            new SourceBeanContentHandler(trimCharacters, upperCase);
        parser.setContentHandler(contentHandler);
        parser.parse(stream);
        sourceBean = contentHandler.getSourceBean();
    } // try
    catch (Exception ex) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.CRITICAL,
            "SourceBean::fromXMLString: impossibile elaborare lo stream XML",
            ex);
        throw new SourceBeanException("Impossibile elaborare lo stream XML");
    } // catch (Exception ex) try
    return sourceBean;
}
 
Example #4
Source File: SourceBean.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SourceBean fromXMLStream(InputSource stream, boolean trimCharacters, boolean  upperCase)
	throws SourceBeanException {
    if (stream == null) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.WARNING,
            "SourceBean::fromXMLStream: stream nullo");
        return null;
    } // if (stream == null)
    SourceBean sourceBean = null;
    XMLReader parser = new SAXParser();
    try {
        SourceBeanContentHandler contentHandler =
            new SourceBeanContentHandler(trimCharacters, upperCase);
        parser.setContentHandler(contentHandler);
        parser.parse(stream);
        sourceBean = contentHandler.getSourceBean();
    } // try
    catch (Exception ex) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.CRITICAL,
            "SourceBean::fromXMLString: impossibile elaborare lo stream XML",
            ex);
        throw new SourceBeanException("Impossibile elaborare lo stream XML");
    } // catch (Exception ex) try
    return sourceBean;
}
 
Example #5
Source File: SourceBean.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SourceBean fromXMLStream(InputSource stream, boolean trimCharacters, boolean  upperCase)
	throws SourceBeanException {
    if (stream == null) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.WARNING,
            "SourceBean::fromXMLStream: stream nullo");
        return null;
    } // if (stream == null)
    SourceBean sourceBean = null;
    XMLReader parser = new SAXParser();
    try {
        SourceBeanContentHandler contentHandler =
            new SourceBeanContentHandler(trimCharacters, upperCase);
        parser.setContentHandler(contentHandler);
        parser.parse(stream);
        sourceBean = contentHandler.getSourceBean();
    } // try
    catch (Exception ex) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.CRITICAL,
            "SourceBean::fromXMLString: impossibile elaborare lo stream XML",
            ex);
        throw new SourceBeanException("Impossibile elaborare lo stream XML");
    } // catch (Exception ex) try
    return sourceBean;
}
 
Example #6
Source File: SourceBean.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SourceBean fromXMLStream(InputSource stream, boolean trimCharacters, boolean  upperCase)
	throws SourceBeanException {
    if (stream == null) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.WARNING,
            "SourceBean::fromXMLStream: stream nullo");
        return null;
    } // if (stream == null)
    SourceBean sourceBean = null;
    XMLReader parser = new SAXParser();
    try {
        SourceBeanContentHandler contentHandler =
            new SourceBeanContentHandler(trimCharacters, upperCase);
        parser.setContentHandler(contentHandler);
        parser.parse(stream);
        sourceBean = contentHandler.getSourceBean();
    } // try
    catch (Exception ex) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.CRITICAL,
            "SourceBean::fromXMLString: impossibile elaborare lo stream XML",
            ex);
        throw new SourceBeanException("Impossibile elaborare lo stream XML");
    } // catch (Exception ex) try
    return sourceBean;
}
 
Example #7
Source File: SourceBean.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SourceBean fromXMLStream(InputSource stream, boolean trimCharacters, boolean  upperCase)
	throws SourceBeanException {
    if (stream == null) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.WARNING,
            "SourceBean::fromXMLStream: stream nullo");
        return null;
    } // if (stream == null)
    SourceBean sourceBean = null;
    XMLReader parser = new SAXParser();
    try {
        SourceBeanContentHandler contentHandler =
            new SourceBeanContentHandler(trimCharacters, upperCase);
        parser.setContentHandler(contentHandler);
        parser.parse(stream);
        sourceBean = contentHandler.getSourceBean();
    } // try
    catch (Exception ex) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.CRITICAL,
            "SourceBean::fromXMLString: impossibile elaborare lo stream XML",
            ex);
        throw new SourceBeanException("Impossibile elaborare lo stream XML");
    } // catch (Exception ex) try
    return sourceBean;
}
 
Example #8
Source File: SourceBean.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SourceBean fromXMLStream(InputSource stream, boolean trimCharacters, boolean  upperCase)
	throws SourceBeanException {
    if (stream == null) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.WARNING,
            "SourceBean::fromXMLStream: stream nullo");
        return null;
    } // if (stream == null)
    SourceBean sourceBean = null;
    XMLReader parser = new SAXParser();
    try {
        SourceBeanContentHandler contentHandler =
            new SourceBeanContentHandler(trimCharacters, upperCase);
        parser.setContentHandler(contentHandler);
        parser.parse(stream);
        sourceBean = contentHandler.getSourceBean();
    } // try
    catch (Exception ex) {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.CRITICAL,
            "SourceBean::fromXMLString: impossibile elaborare lo stream XML",
            ex);
        throw new SourceBeanException("Impossibile elaborare lo stream XML");
    } // catch (Exception ex) try
    return sourceBean;
}
 
Example #9
Source File: CustomSAXSVGDocumentFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Document createDocument(InputSource is) throws IOException {
    try {
        final XMLReader parser = new SAXParser();

        parser.setContentHandler(this);
        parser.setDTDHandler(this);
        parser.setEntityResolver(this);
        parser.setErrorHandler((errorHandler == null) ? this : errorHandler);

        parser.setFeature("http://xml.org/sax/features/namespaces",
                true);
        parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
                true);
        parser.setFeature("http://xml.org/sax/features/validation",
                isValidating);
        parser.setProperty("http://xml.org/sax/properties/lexical-handler",
                this);
        parser.parse(is);
    } catch (final SAXException e) {
        final Exception ex = e.getException();
        if (ex != null && ex instanceof InterruptedIOException) {
            throw (InterruptedIOException) ex;
        }
        throw new IOException(e.getMessage());
    }

    currentNode = null;
    final Document ret = document;
    document = null;
    locator = null;
    return ret;
}
 
Example #10
Source File: XMLValidator.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
private static void parseXML(String content, String uri, SAXParser parser) throws SAXException, IOException {
	InputSource inputSource = new InputSource();
	inputSource.setCharacterStream(new StringReader(content));
	inputSource.setSystemId(uri);
	parser.parse(inputSource);
}