-package org.simantics.document.linking.report.templates.custom;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.document.linking.report.DocumentLine;\r
-import org.simantics.scl.compiler.commands.CommandSession;\r
-import org.simantics.scl.compiler.types.Types;\r
-import org.simantics.scl.osgi.SCLOsgi;\r
-import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;\r
-\r
-\r
-\r
-/**\r
- * SCL-script based customization\r
- * \r
- * NOTE: this does not work, since at the moment the CommandSession is not able to attach itself to given read transaction.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class SCLCustomizableContent implements CustomizableContent {\r
- \r
- private CommandSession session;\r
- private String sclCode[];\r
- \r
- private String label;\r
- \r
- public SCLCustomizableContent(String label) {\r
- session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);\r
- \r
- sclCode = new String[]{"import \"Simantics/Ontologies\"",\r
- "nameOfResource r = match possibleRelatedValue r L0.HasName with\n"+\r
- " Just name -> name\n"+\r
- " Nothing -> \"no name\"",\r
- "nameOfResource res"}; \r
- }\r
- \r
- @Override\r
- public String getCustomizationDescription() {\r
- return label;\r
- }\r
- \r
- @Override\r
- public String getContent(ReadGraph graph, Resource resource, Map<Object, Object> context)\r
- throws DatabaseException {\r
- \r
- session.setVariable("res", Types.con("Simantics/DB", "Resource"), resource);\r
- final StringBuilder responseBuilder = new StringBuilder();\r
- final StringBuilder errorBuilder = new StringBuilder();\r
- for (String code : sclCode) {\r
- session.execute(code, new AbstractSCLReportingHandler() {\r
- \r
- @Override\r
- public void print(String text) {\r
- responseBuilder.append(text).append('\n');\r
- }\r
- \r
- @Override\r
- public void printError(String error) {\r
- errorBuilder.append(error).append('\n');\r
- }\r
- \r
- @Override\r
- public void printCommand(String command) {\r
- }\r
- });\r
- if(errorBuilder.length() > 0)\r
- throw new DatabaseException("Error executing SCL \"" + code + "\" " + errorBuilder.toString().trim());\r
- }\r
- return responseBuilder.toString().trim();\r
- }\r
- \r
- @Override\r
- public List<DocumentLine> getLines(ReadGraph graph, Resource resource, Map<Object, Object> context)\r
- throws DatabaseException {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
- \r
- public String[] getSclCode() {\r
- return sclCode;\r
- }\r
- \r
- public void setSclCode(String[] sclCode) {\r
- this.sclCode = sclCode;\r
- }\r
- \r
-\r
-}\r
+package org.simantics.document.linking.report.templates.custom;
+
+import java.util.List;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.document.linking.report.DocumentLine;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;
+
+
+
+/**
+ * SCL-script based customization
+ *
+ * NOTE: this does not work, since at the moment the CommandSession is not able to attach itself to given read transaction.
+ *
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class SCLCustomizableContent implements CustomizableContent {
+
+ private CommandSession session;
+ private String sclCode[];
+
+ private String label;
+
+ public SCLCustomizableContent(String label) {
+ session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
+
+ sclCode = new String[]{"import \"Simantics/Ontologies\"", //$NON-NLS-1$
+ "nameOfResource r = match possibleRelatedValue r L0.HasName with\n"+ //$NON-NLS-1$
+ " Just name -> name\n"+ //$NON-NLS-1$
+ " Nothing -> \"no name\"", //$NON-NLS-1$
+ "nameOfResource res"}; //$NON-NLS-1$
+ }
+
+ @Override
+ public String getCustomizationDescription() {
+ return label;
+ }
+
+ @Override
+ public String getContent(ReadGraph graph, Resource resource, Map<Object, Object> context)
+ throws DatabaseException {
+
+ session.setVariable("res", Types.con("Simantics/DB", "Resource"), resource); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ final StringBuilder responseBuilder = new StringBuilder();
+ final StringBuilder errorBuilder = new StringBuilder();
+ for (String code : sclCode) {
+ session.execute(code, new AbstractSCLReportingHandler() {
+
+ @Override
+ public void print(String text) {
+ responseBuilder.append(text).append('\n');
+ }
+
+ @Override
+ public void printError(String error) {
+ errorBuilder.append(error).append('\n');
+ }
+
+ @Override
+ public void printCommand(String command) {
+ }
+ });
+ if(errorBuilder.length() > 0)
+ throw new DatabaseException("Error executing SCL \"" + code + "\" " + errorBuilder.toString().trim()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return responseBuilder.toString().trim();
+ }
+
+ @Override
+ public List<DocumentLine> getLines(ReadGraph graph, Resource resource, Map<Object, Object> context)
+ throws DatabaseException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String[] getSclCode() {
+ return sclCode;
+ }
+
+ public void setSclCode(String[] sclCode) {
+ this.sclCode = sclCode;
+ }
+
+
+}