]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java
Enabling ResourceFile CR filtering based on locale
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / resourceFiles / ResourceFile.java
index c7e1f22b14ccf58b173ab2b323cad58a4955346b..a847dbee130e61fb4ab6ea84a17afa14020ee9f8 100644 (file)
@@ -6,6 +6,7 @@ import java.io.OutputStreamWriter;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -19,6 +20,8 @@ import freemarker.template.DefaultObjectWrapper;
 import freemarker.template.Template;
 
 public class ResourceFile implements IResourceFile {
+    private final static Charset UTF8 = Charset.forName("UTF-8");
+    
        String packageName;
        String className;
        List<ResourceRef> resources;
@@ -88,8 +91,8 @@ public class ResourceFile implements IResourceFile {
        @Override
        public InputStream getContent() {
                StringWriter writer = new StringWriter();
-               write(writer);
-               return new ByteArrayInputStream(writer.toString().replace("\r\n", "\n").getBytes());
+               write(String.format("%n").length() == 1 ? new FilterCRWriter(writer) : writer);
+               return new ByteArrayInputStream(writer.toString().getBytes(UTF8));
        }
        
        /* (non-Javadoc)
@@ -105,11 +108,12 @@ public class ResourceFile implements IResourceFile {
        }
        
        public static void main(String[] args) {
-               ResourceRef Foo = new ResourceRef("Foo", "http://www.dsf.sdf/Foo");
+               /*ResourceRef Foo = new ResourceRef("Foo", "http://www.dsf.sdf/Foo");
                ResourceRef Bar = new ResourceRef("Foo", "http://www.dsf.sdf/Bar");
                Bar.deprecated = true;
                new ResourceFile("org.simantics.graph", "Testi", Arrays.<ResourceRef>asList(
                                Foo, Bar
-                       )).write(new OutputStreamWriter(System.out));
+                       )).write(new OutputStreamWriter(System.out));*/
+           System.out.println(String.format("%n").length());
        }
 }