Search in sources :

Example 1 with CacheXmlParser

use of org.apache.geode.internal.cache.xmlcache.CacheXmlParser in project geode by apache.

the class XmlUtils method getDocumentBuilder.

public static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    // the actual builder or parser
    DocumentBuilder builder = factory.newDocumentBuilder();
    builder.setEntityResolver(new CacheXmlParser());
    return builder;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CacheXmlParser(org.apache.geode.internal.cache.xmlcache.CacheXmlParser)

Example 2 with CacheXmlParser

use of org.apache.geode.internal.cache.xmlcache.CacheXmlParser in project geode by apache.

the class GemFireCacheImpl method loadCacheXml.

@Override
public void loadCacheXml(InputStream is) throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
    // make this cache available to callbacks being initialized during xml create
    final GemFireCacheImpl oldValue = xmlCache.get();
    xmlCache.set(this);
    Reader reader = null;
    Writer stringWriter = null;
    OutputStreamWriter writer = null;
    try {
        CacheXmlParser xml;
        if (XML_PARAMETERIZATION_ENABLED) {
            char[] buffer = new char[1024];
            reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
            stringWriter = new StringWriter();
            int numChars;
            while ((numChars = reader.read(buffer)) != -1) {
                stringWriter.write(buffer, 0, numChars);
            }
            /*
         * Now replace all replaceable system properties here using {@code PropertyResolver}
         */
            String replacedXmlString = this.resolver.processUnresolvableString(stringWriter.toString());
            /*
         * Turn the string back into the default encoding so that the XML parser can work correctly
         * in the presence of an "encoding" attribute in the XML prolog.
         */
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            writer = new OutputStreamWriter(baos, "ISO-8859-1");
            writer.write(replacedXmlString);
            writer.flush();
            xml = CacheXmlParser.parse(new ByteArrayInputStream(baos.toByteArray()));
        } else {
            xml = CacheXmlParser.parse(is);
        }
        xml.create(this);
    } catch (IOException e) {
        throw new CacheXmlException("Input Stream could not be read for system property substitutions.", e);
    } finally {
        xmlCache.set(oldValue);
        closeQuietly(reader);
        closeQuietly(stringWriter);
        closeQuietly(writer);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) CacheXmlParser(org.apache.geode.internal.cache.xmlcache.CacheXmlParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) StringWriter(java.io.StringWriter) CacheXmlException(org.apache.geode.cache.CacheXmlException) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 3 with CacheXmlParser

use of org.apache.geode.internal.cache.xmlcache.CacheXmlParser in project geode by apache.

the class LuceneIndexXmlParserIntegrationJUnitTest method createRegionCreation.

private RegionCreation createRegionCreation(String regionName) throws FileNotFoundException {
    CacheXmlParser parser = CacheXmlParser.parse(new FileInputStream(getXmlFileForTest()));
    CacheCreation cache = parser.getCacheCreation();
    return (RegionCreation) cache.getRegion(regionName);
}
Also used : CacheXmlParser(org.apache.geode.internal.cache.xmlcache.CacheXmlParser) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) FileInputStream(java.io.FileInputStream)

Example 4 with CacheXmlParser

use of org.apache.geode.internal.cache.xmlcache.CacheXmlParser in project geode by apache.

the class CacheElement method resolveSchema.

/**
   * Resolve schema from <code>schemaLocationsNape</code> or <code>namespaceUri</code> for given
   * <code>namespaceUri</code>.
   * 
   * @param schemaLocationMap {@link Map} of namespaceUri to URLs.
   * @param namespaceUri Namespace URI for schema.
   * @return {@link InputSource} for schema if found.
   * @throws IOException if unable to open {@link InputSource}.
   * @since GemFire 8.1
   */
private static InputSource resolveSchema(final Map<String, List<String>> schemaLocationMap, String namespaceUri) throws IOException {
    final EntityResolver2 entityResolver = new CacheXmlParser();
    InputSource inputSource = null;
    // Try loading schema from locations until we find one.
    final List<String> locations = schemaLocationMap.get(namespaceUri);
    for (final String location : locations) {
        try {
            inputSource = entityResolver.resolveEntity(null, location);
            if (null != inputSource) {
                break;
            }
        } catch (final SAXException e) {
        // ignore
        }
    }
    if (null == inputSource) {
        // Try getting it from the namespace, will throw if does not exist.
        inputSource = new InputSource(new URL(namespaceUri).openStream());
    }
    return inputSource;
}
Also used : InputSource(org.xml.sax.InputSource) CacheXmlParser(org.apache.geode.internal.cache.xmlcache.CacheXmlParser) EntityResolver2(org.xml.sax.ext.EntityResolver2) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Example 5 with CacheXmlParser

use of org.apache.geode.internal.cache.xmlcache.CacheXmlParser in project geode by apache.

the class CacheElementJUnitTest method loadSchema.

private Document loadSchema(final String schemaLocation) throws Exception {
    final CacheXmlParser entityResolver = new CacheXmlParser();
    final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    xmlReader.setEntityResolver(entityResolver);
    return XmlUtils.getDocumentBuilder().parse(entityResolver.resolveEntity(null, schemaLocation).getByteStream());
}
Also used : CacheXmlParser(org.apache.geode.internal.cache.xmlcache.CacheXmlParser) XMLReader(org.xml.sax.XMLReader)

Aggregations

CacheXmlParser (org.apache.geode.internal.cache.xmlcache.CacheXmlParser)5 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 URL (java.net.URL)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 LogWriter (org.apache.geode.LogWriter)1 CacheXmlException (org.apache.geode.cache.CacheXmlException)1 ExtensionPoint (org.apache.geode.internal.cache.extension.ExtensionPoint)1 SimpleExtensionPoint (org.apache.geode.internal.cache.extension.SimpleExtensionPoint)1 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)1 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)1