Author: michiel
Date: 2010-04-02 17:36:20 +0200 (Fri, 02 Apr 2010)
New Revision: 41735
Modified:
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/xml/EntityResolver.java
Log:
You'd say that xincluding an other XML doesn't need an explict enocding (while
the silly xml itself sais what it is). It doesn't. Doing something with
encodings, here, to at least avoid dependeing on system properties (which is
STUPID)
Modified:
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/xml/EntityResolver.java
===================================================================
---
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/xml/EntityResolver.java
2010-04-02 14:46:19 UTC (rev 41734)
+++
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/xml/EntityResolver.java
2010-04-02 15:36:20 UTC (rev 41735)
@@ -26,6 +26,7 @@
/**
* Take the systemId and converts it into a local file, using the MMBase
config path
+ * This is used for resolving DTD's and XSD's, but also e.g. for Xincludes.
*
* @author Gerard van Enk
* @author Michiel Meeuwissen
@@ -59,7 +60,11 @@
* Container for dtd resources information
*/
static abstract class Resource {
+ String encoding = "UTF-8";
abstract InputStream getStream();
+ public String getEncoding() {
+ return encoding;
+ }
}
static class StringResource extends Resource {
private String string;
@@ -67,7 +72,12 @@
string = s;
}
InputStream getStream() {
- return new ByteArrayInputStream(string.getBytes());
+ try {
+ return new ByteArrayInputStream(string.getBytes(encoding));
+ } catch (java.io.UnsupportedEncodingException uee) {
+ log.error(uee); // WTF
+ return new ByteArrayInputStream(string.getBytes());
+ }
}
}
static class FileResource extends Resource {
@@ -99,7 +109,6 @@
if (stream == null && clazz != null) {
stream = clazz.getResourceAsStream(getResource());
}
-
return stream;
}
@@ -306,6 +315,7 @@
}
InputStream definitionStream = null;
+ String encoding = "UTF-8";
if ("http://www.mmbase.org/mmentities.ent".equals(systemId)) {
log.debug("Reding mmbase entities for " + systemId + " " +
publicId);
@@ -321,6 +331,9 @@
Resource res = publicIDtoResource.get(publicId);
log.debug("Found publicId " + publicId + " -> " + res);
definitionStream = res == null ? null : res.getStream();
+ if (res != null) {
+ encoding = res.getEncoding();
+ }
}
@@ -330,6 +343,7 @@
Resource res = systemIDtoResource.get(systemId);
if (res != null) {
definitionStream = res.getStream();
+ encoding = res.getEncoding();
}
log.debug("Get definition stream by registered system id: " +
systemId + " " + definitionStream);
}
@@ -360,6 +374,7 @@
log.debug("mmbase resource " +
ResourceLoader.getConfigurationRoot().getResource(mmResource));
}
definitionStream =
ResourceLoader.getConfigurationRoot().getResourceAsStream(mmResource);
+ encoding = "UTF-8";
if (definitionStream == null) {
Class<?> base = resolveBase; // if resolveBase was
specified, use that.
Resource res = null;
@@ -402,7 +417,14 @@
}
hasDefinition = true;
- InputStreamReader definitionInputStreamReader = new
InputStreamReader(definitionStream);
+ InputStreamReader definitionInputStreamReader;
+ try {
+ definitionInputStreamReader = new
InputStreamReader(definitionStream, encoding);
+ } catch (java.io.UnsupportedEncodingException uee) {
+ log.error(uee); // WTF
+ definitionInputStreamReader = new
InputStreamReader(definitionStream);
+ }
+
InputSource definitionInputSource = new InputSource();
if (systemId != null) {
definitionInputSource.setSystemId(systemId);
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs