X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2FresourceFiles%2FResourceFile.java;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2FresourceFiles%2FResourceFile.java;h=25758343d59751d3dd2a5d28d2aac8d950485ebe;hp=2b3fd2b71e74580bb36c0471c83648baa4041e8a;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java index 2b3fd2b71..25758343d 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFile.java @@ -1,115 +1,115 @@ -package org.simantics.graph.compiler.internal.resourceFiles; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.net.URL; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.simantics.graph.IResourceFile; - -import freemarker.cache.URLTemplateLoader; -import freemarker.template.Configuration; -import freemarker.template.DefaultObjectWrapper; -import freemarker.template.Template; - -public class ResourceFile implements IResourceFile { - String packageName; - String className; - List resources; - - public ResourceFile(String packageName, String className, - List resources) { - this.packageName = packageName; - this.className = className; - this.resources = resources; - } - - /* (non-Javadoc) - * @see org.simantics.graph.resourceFiles.IResourceFile#getPackageName() - */ - @Override - public String getPackageName() { - return packageName; - } - - /* (non-Javadoc) - * @see org.simantics.graph.resourceFiles.IResourceFile#getClassName() - */ - @Override - public String getClassName() { - return className; - } - - public Collection getResources() { - return resources; - } - - private static Configuration configuration = null; - private static Configuration getConfiguration() { - if(configuration == null) { - configuration = new Configuration(); - configuration.setTemplateLoader( - new URLTemplateLoader() { - @Override - protected URL getURL(String name) { - return ResourceFile.class.getResource(name); - } - }); - configuration.setObjectWrapper(new DefaultObjectWrapper()); - } - return configuration; - } - - /* (non-Javadoc) - * @see org.simantics.graph.resourceFiles.IResourceFile#write(java.io.Writer) - */ - @Override - public void write(Writer writer) { - try { - Template temp = - getConfiguration().getTemplate("resourceFile.ftl"); - - temp.process(this, writer); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /* (non-Javadoc) - * @see org.simantics.graph.resourceFiles.IResourceFile#getContent() - */ - @Override - public InputStream getContent() { - StringWriter writer = new StringWriter(); - write(writer); - return new ByteArrayInputStream(writer.toString().getBytes()); - } - - /* (non-Javadoc) - * @see org.simantics.graph.resourceFiles.IResourceFile#getFileName() - */ - @Override - public String getFileName() { - return "src/" + packageName.replace('.', '/') + "/" + className + ".java"; - } - - public void sort() { - Collections.sort(resources); - } - - public static void main(String[] args) { - 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.asList( - Foo, Bar - )).write(new OutputStreamWriter(System.out)); - } -} +package org.simantics.graph.compiler.internal.resourceFiles; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.io.Writer; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.simantics.graph.IResourceFile; + +import freemarker.cache.URLTemplateLoader; +import freemarker.template.Configuration; +import freemarker.template.DefaultObjectWrapper; +import freemarker.template.Template; + +public class ResourceFile implements IResourceFile { + String packageName; + String className; + List resources; + + public ResourceFile(String packageName, String className, + List resources) { + this.packageName = packageName; + this.className = className; + this.resources = resources; + } + + /* (non-Javadoc) + * @see org.simantics.graph.resourceFiles.IResourceFile#getPackageName() + */ + @Override + public String getPackageName() { + return packageName; + } + + /* (non-Javadoc) + * @see org.simantics.graph.resourceFiles.IResourceFile#getClassName() + */ + @Override + public String getClassName() { + return className; + } + + public Collection getResources() { + return resources; + } + + private static Configuration configuration = null; + private static Configuration getConfiguration() { + if(configuration == null) { + configuration = new Configuration(); + configuration.setTemplateLoader( + new URLTemplateLoader() { + @Override + protected URL getURL(String name) { + return ResourceFile.class.getResource(name); + } + }); + configuration.setObjectWrapper(new DefaultObjectWrapper()); + } + return configuration; + } + + /* (non-Javadoc) + * @see org.simantics.graph.resourceFiles.IResourceFile#write(java.io.Writer) + */ + @Override + public void write(Writer writer) { + try { + Template temp = + getConfiguration().getTemplate("resourceFile.ftl"); + + temp.process(this, writer); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /* (non-Javadoc) + * @see org.simantics.graph.resourceFiles.IResourceFile#getContent() + */ + @Override + public InputStream getContent() { + StringWriter writer = new StringWriter(); + write(writer); + return new ByteArrayInputStream(writer.toString().getBytes()); + } + + /* (non-Javadoc) + * @see org.simantics.graph.resourceFiles.IResourceFile#getFileName() + */ + @Override + public String getFileName() { + return "src/" + packageName.replace('.', '/') + "/" + className + ".java"; + } + + public void sort() { + Collections.sort(resources); + } + + public static void main(String[] args) { + 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.asList( + Foo, Bar + )).write(new OutputStreamWriter(System.out)); + } +}