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;
}
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);
}
}
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);
}
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;
}
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());
}
Aggregations