X4O: Deleted INPUT_SOURCE property support
This commit is contained in:
parent
0b75d4e283
commit
c71f8c0a82
2 changed files with 21 additions and 38 deletions
|
|
@ -29,6 +29,7 @@ import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.el.ValueExpression;
|
import javax.el.ValueExpression;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
@ -44,7 +45,6 @@ import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
||||||
import org.x4o.xml.lang.phase.X4OPhaseType;
|
import org.x4o.xml.lang.phase.X4OPhaseType;
|
||||||
import org.xml.sax.EntityResolver;
|
import org.xml.sax.EntityResolver;
|
||||||
import org.xml.sax.ErrorHandler;
|
import org.xml.sax.ErrorHandler;
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -68,7 +68,6 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
||||||
public final static String DOC_BUFFER_SIZE = PROPERTY_CONTEXT_PREFIX + "doc/buffer-size";
|
public final static String DOC_BUFFER_SIZE = PROPERTY_CONTEXT_PREFIX + "doc/buffer-size";
|
||||||
public final static String INPUT_STREAM = PROPERTY_CONTEXT_PREFIX + "input/stream";
|
public final static String INPUT_STREAM = PROPERTY_CONTEXT_PREFIX + "input/stream";
|
||||||
public final static String INPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "input/encoding";
|
public final static String INPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "input/encoding";
|
||||||
public final static String INPUT_SOURCE = PROPERTY_CONTEXT_PREFIX + "input/source";
|
|
||||||
public final static String INPUT_SYSTEM_ID = PROPERTY_CONTEXT_PREFIX + "input/system-id";
|
public final static String INPUT_SYSTEM_ID = PROPERTY_CONTEXT_PREFIX + "input/system-id";
|
||||||
public final static String INPUT_BASE_PATH = PROPERTY_CONTEXT_PREFIX + "input/base-path";
|
public final static String INPUT_BASE_PATH = PROPERTY_CONTEXT_PREFIX + "input/base-path";
|
||||||
public final static String VALIDATION_SCHEMA_AUTO_WRITE = PROPERTY_CONTEXT_PREFIX + "validation/schema-auto-write";
|
public final static String VALIDATION_SCHEMA_AUTO_WRITE = PROPERTY_CONTEXT_PREFIX + "validation/schema-auto-write";
|
||||||
|
|
@ -84,9 +83,8 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
||||||
new PropertyConfigItem(SAX_ENTITY_RESOLVER,EntityResolver.class),
|
new PropertyConfigItem(SAX_ENTITY_RESOLVER,EntityResolver.class),
|
||||||
new PropertyConfigItem(DOC_EMPTY_NAMESPACE_URI,String.class),
|
new PropertyConfigItem(DOC_EMPTY_NAMESPACE_URI,String.class),
|
||||||
new PropertyConfigItem(DOC_BUFFER_SIZE,Integer.class,4096*2),
|
new PropertyConfigItem(DOC_BUFFER_SIZE,Integer.class,4096*2),
|
||||||
new PropertyConfigItem(INPUT_STREAM,InputStream.class),
|
new PropertyConfigItem(true,INPUT_STREAM,InputStream.class),
|
||||||
new PropertyConfigItem(INPUT_ENCODING,String.class,SAX3XMLConstants.XML_DEFAULT_ENCODING),
|
new PropertyConfigItem(INPUT_ENCODING,String.class,SAX3XMLConstants.XML_DEFAULT_ENCODING),
|
||||||
new PropertyConfigItem(INPUT_SOURCE,InputSource.class),
|
|
||||||
new PropertyConfigItem(true,INPUT_SYSTEM_ID,String.class),
|
new PropertyConfigItem(true,INPUT_SYSTEM_ID,String.class),
|
||||||
new PropertyConfigItem(true,INPUT_BASE_PATH,URL.class),
|
new PropertyConfigItem(true,INPUT_BASE_PATH,URL.class),
|
||||||
new PropertyConfigItem(VALIDATION_SCHEMA_AUTO_WRITE,Boolean.class,true),
|
new PropertyConfigItem(VALIDATION_SCHEMA_AUTO_WRITE,Boolean.class,true),
|
||||||
|
|
@ -115,6 +113,10 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
||||||
@Override
|
@Override
|
||||||
public void readSession(X4OLanguageSession languageSession, InputStream input, String systemId, URL basePath)
|
public void readSession(X4OLanguageSession languageSession, InputStream input, String systemId, URL basePath)
|
||||||
throws X4OConnectionException, SAXException, IOException {
|
throws X4OConnectionException, SAXException, IOException {
|
||||||
|
Objects.requireNonNull(languageSession, "Can't read into null language session");
|
||||||
|
Objects.requireNonNull(input, "Can't read a null input stream");
|
||||||
|
Objects.requireNonNull(systemId, "No system-id provided for the input streamn");
|
||||||
|
Objects.requireNonNull(basePath, "No base-path provided for the input streamn"); // TODO; make optional, use default working folder
|
||||||
setProperty(INPUT_STREAM, input);
|
setProperty(INPUT_STREAM, input);
|
||||||
setProperty(INPUT_SYSTEM_ID, systemId);
|
setProperty(INPUT_SYSTEM_ID, systemId);
|
||||||
setProperty(INPUT_BASE_PATH, basePath);
|
setProperty(INPUT_BASE_PATH, basePath);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
|
|
@ -65,20 +66,25 @@ public class X4OContentParser {
|
||||||
languageSession.getX4ODebugWriter().debugSAXConfigStart();
|
languageSession.getX4ODebugWriter().debugSAXConfigStart();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
parseSax(languageSession);
|
// Validate required input
|
||||||
|
InputStream inputStream = Objects.requireNonNull((InputStream) getPropertyConfig().getProperty(DefaultX4OReader.INPUT_STREAM), "Missing property: " + DefaultX4OReader.INPUT_STREAM);
|
||||||
|
String inputEncoding = Objects.requireNonNull((String) getPropertyConfig().getProperty(DefaultX4OReader.INPUT_ENCODING), "Missing property: " + DefaultX4OReader.INPUT_ENCODING);
|
||||||
|
String inputSystemId = Objects.requireNonNull((String) getPropertyConfig().getProperty(DefaultX4OReader.INPUT_SYSTEM_ID), "Missing property: " + DefaultX4OReader.INPUT_SYSTEM_ID);
|
||||||
|
// Wrap input stream to source with added meta info
|
||||||
|
InputSource inputSource = new InputSource(inputStream);
|
||||||
|
inputSource.setEncoding(inputEncoding);
|
||||||
|
inputSource.setSystemId(inputSystemId);
|
||||||
|
// Start the SAX bases parsing
|
||||||
|
parseSax(languageSession, inputSource);
|
||||||
} finally {
|
} finally {
|
||||||
|
// Close the debug parse group tag
|
||||||
if (languageSession.hasX4ODebugWriter()) {
|
if (languageSession.hasX4ODebugWriter()) {
|
||||||
languageSession.getX4ODebugWriter().debugSAXConfigEnd();
|
languageSession.getX4ODebugWriter().debugSAXConfigEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseSax(X4OLanguageSession languageSession) throws SAXException, IOException, ParserConfigurationException {
|
private void parseSax(X4OLanguageSession languageSession, InputSource inputSource) throws SAXException, IOException, ParserConfigurationException {
|
||||||
// If xsd caching is needed this should be the way
|
|
||||||
// XMLParserConfiguration config = new XIncludeAwareParserConfiguration();
|
|
||||||
// config.setProperty("http://apache.org/xml/properties/internal/grammar-pool",myFullGrammarPool);
|
|
||||||
// SAXParser parser = new SAXParser(config);
|
|
||||||
|
|
||||||
// Create Sax parser with x4o tag handler
|
// Create Sax parser with x4o tag handler
|
||||||
X4OContentHandler xth = new X4OContentHandler(languageSession, getPropertyConfig());
|
X4OContentHandler xth = new X4OContentHandler(languageSession, getPropertyConfig());
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
|
|
@ -129,7 +135,7 @@ public class X4OContentParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for required features
|
// Check for required features
|
||||||
List<String> requiredFeatures = getSAXParserFeaturesRequired(languageSession);
|
List<String> requiredFeatures = getSAXParserFeaturesRequired(languageSession);
|
||||||
for (String requiredFeature : requiredFeatures) {
|
for (String requiredFeature : requiredFeatures) {
|
||||||
if (reader.getFeature(requiredFeature) == false) {
|
if (reader.getFeature(requiredFeature) == false) {
|
||||||
|
|
@ -139,32 +145,7 @@ public class X4OContentParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally start parsing the xml input stream
|
// Finally start parsing the xml input stream
|
||||||
Object requestInputSource = getPropertyConfig().getProperty(DefaultX4OReader.INPUT_SOURCE);
|
reader.parse(inputSource);
|
||||||
InputSource input = null;
|
|
||||||
InputStream inputStream = null;
|
|
||||||
if (requestInputSource instanceof InputSource) {
|
|
||||||
input = (InputSource) requestInputSource;
|
|
||||||
} else {
|
|
||||||
inputStream = (InputStream) getPropertyConfig().getProperty(DefaultX4OReader.INPUT_STREAM);
|
|
||||||
input = new InputSource(inputStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object requestInputEncoding = getPropertyConfig().getProperty(DefaultX4OReader.INPUT_ENCODING);
|
|
||||||
if (requestInputEncoding != null && requestInputEncoding instanceof String) {
|
|
||||||
input.setEncoding(requestInputEncoding.toString());
|
|
||||||
}
|
|
||||||
Object requestSystemId = getPropertyConfig().getProperty(DefaultX4OReader.INPUT_SYSTEM_ID);
|
|
||||||
if (requestSystemId != null && requestSystemId instanceof String) {
|
|
||||||
input.setSystemId(requestSystemId.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
reader.parse(input);
|
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void debugMessageLog(String message, X4OLanguageSession languageSession) throws SAXException {
|
private void debugMessageLog(String message, X4OLanguageSession languageSession) throws SAXException {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue