summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosiah Gaskin <josiahgaskin@google.com>2013-08-08 22:55:21 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-08-08 22:55:21 +0000
commitc8a54a8ffd114264861a6080ea5dfe843c6b6968 (patch)
tree84d3c4ec5f0ab62fe18aa2143300039ee41b4b2b
parentb94088c06a10c8e53b27651d50d7156e2d1e9a5a (diff)
parente7d0adbb0184bcbf78a0abb87d00d2131f031054 (diff)
downloadidea-kitkat-mr2.1-release.tar.gz
-rwxr-xr-xandroid/src/com/android/tools/idea/templates/Template.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/android/src/com/android/tools/idea/templates/Template.java b/android/src/com/android/tools/idea/templates/Template.java
index f68d6df8ecc..5c45a07e3ec 100755
--- a/android/src/com/android/tools/idea/templates/Template.java
+++ b/android/src/com/android/tools/idea/templates/Template.java
@@ -52,6 +52,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.*;
import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -306,7 +307,12 @@ public class Template {
xml = processFreemarkerTemplate(freemarker, paramMap, path);
}
- SAXParserFactory.newInstance().newSAXParser().parse(new ByteArrayInputStream(xml.getBytes()), new DefaultHandler() {
+ // Handle UTF-8 since processed file may contain file paths
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8.toString()));
+ Reader reader = new InputStreamReader(inputStream, Charsets.UTF_8.toString());
+ InputSource inputSource = new InputSource(reader);
+ inputSource.setEncoding(Charsets.UTF_8.toString());
+ SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
if (TAG_PARAMETER.equals(name)) {
@@ -433,8 +439,13 @@ public class Template {
myLoader.setTemplateFile(getTemplateFile(file));
String xml = processFreemarkerTemplate(freemarker, paramMap, file);
- // Parse and execute the resulting instruction list.
- SAXParserFactory.newInstance().newSAXParser().parse(new ByteArrayInputStream(xml.getBytes()), new DefaultHandler() {
+ // Parse and execute the resulting instruction list. We handle UTF-8 since the processed file contains paths which may
+ // have UTF-8 characters.
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8.toString()));
+ Reader reader = new InputStreamReader(inputStream, Charsets.UTF_8.toString());
+ InputSource inputSource = new InputSource(reader);
+ inputSource.setEncoding(Charsets.UTF_8.toString());
+ SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
try {
@@ -487,7 +498,6 @@ public class Template {
}
}
});
-
} catch (Exception e) {
ourMostRecentException = e;
LOG.warn(e);