[isidorus-cvs] r498 - in branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine: . Base TopicMaps jtmsBasedEngine
lgiessmann at common-lisp.net
lgiessmann at common-lisp.net
Thu Jun 23 00:51:05 UTC 2011
Author: lgiessmann
Date: Wed Jun 22 17:51:04 2011
New Revision: 498
Log:
gdl-frontend: TmEngine: started to implement the JTM 1.1 exporter
Added:
branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/Base/ExporterException.java
branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/TopicMaps/ConstructStub.java
Modified:
branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/Base/TmEngine.java
branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/GDL_TmEngine.gwt.xml
branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/TopicMaps/Construct.java
branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java
branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java
Added: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/Base/ExporterException.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/Base/ExporterException.java Wed Jun 22 17:51:04 2011 (r498)
@@ -0,0 +1,18 @@
+package us.isidor.gdl.anaToMia.TmEngine.Base;
+
+public class ExporterException extends Exception {
+ private static final long serialVersionUID = 1L;
+ private String message = "";
+
+ protected ExporterException() {}
+
+
+ public ExporterException(String message){
+ this.message = message;
+ }
+
+
+ public String getMessage(){
+ return this.message;
+ }
+}
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/Base/TmEngine.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/Base/TmEngine.java Wed Jun 22 15:45:56 2011 (r497)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/Base/TmEngine.java Wed Jun 22 17:51:04 2011 (r498)
@@ -5,7 +5,7 @@
public interface TmEngine{
public Construct importTm(String tmData, TopicMap tm) throws FormatException, MissingReference;
- public String exportTm(TopicMap tm);
+ public String exportTm(Construct construct) throws ExporterException;
public TopicMap createTopicMap(String tmLocator);
public TopicMap getTopicMap(String tmLocator);
public TopicMap[] getTopicMaps();
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/GDL_TmEngine.gwt.xml
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/GDL_TmEngine.gwt.xml Wed Jun 22 15:45:56 2011 (r497)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/GDL_TmEngine.gwt.xml Wed Jun 22 17:51:04 2011 (r498)
@@ -1,30 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='gdl_tmengine'>
- <!-- Inherit the core Web Toolkit stuff. -->
- <inherits name='com.google.gwt.user.User'/>
- <inherits name='com.google.gwt.json.JSON'/>
-
- <!-- Inherit the default GWT style sheet. You can change -->
- <!-- the theme of your GWT application by uncommenting -->
- <!-- any one of the following lines. -->
- <inherits name='com.google.gwt.user.theme.clean.Clean'/>
- <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
- <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
- <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
-
- <!-- Other module inherits -->
-
- <!-- Specify the app entry point class. -->
- <entry-point class='us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.TestClass'/>
-
- <!-- Specify the paths for translatable code -->
- <source path='jtmsBasedEngine'/>
- <source path="TopicMaps"/>
- <source path="Base"/>
-
- <!-- Reference the javascript file that is necessary for tmjs -->
- <script src="lib/tm.min.js" />
-
- <!-- only for debugging -->
- <!--<script src="lib/tm.js"/>-->
+ <!-- Inherit the core Web Toolkit stuff. -->
+ <inherits name='com.google.gwt.user.User' />
+ <inherits name='com.google.gwt.json.JSON' />
+
+ <!-- Inherit the default GWT style sheet. You can change -->
+ <!-- the theme of your GWT application by uncommenting -->
+ <!-- any one of the following lines. -->
+ <inherits name='com.google.gwt.user.theme.clean.Clean' />
+ <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
+ <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
+ <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
+
+ <!-- Other module inherits -->
+
+ <!-- Specify the app entry point class. -->
+ <entry-point
+ class='us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.TestClass' />
+
+ <!-- Specify the paths for translatable code -->
+ <source path='jtmsBasedEngine' />
+ <source path="TopicMaps" />
+ <source path="Base" />
+
+ <!-- Reference the javascript file that is necessary for tmjs -->
+ <script src="lib/tm.min.js" />
+
+ <!-- only for debugging -->
+ <!--<script src="lib/tm.js"/> -->
</module>
\ No newline at end of file
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/TopicMaps/Construct.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/TopicMaps/Construct.java Wed Jun 22 15:45:56 2011 (r497)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/TopicMaps/Construct.java Wed Jun 22 17:51:04 2011 (r498)
@@ -13,7 +13,7 @@
/*
public String getId();
public boolean equals(Object other);
- void addItemIdentifier(Locator itemIdentifier);
+ public void addItemIdentifier(Locator itemIdentifier);
public JsArray<Locator> getItemIdentifiers();
public Construct getParent();
public TopicMap getTopicMap();
Added: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/TopicMaps/ConstructStub.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/TopicMaps/ConstructStub.java Wed Jun 22 17:51:04 2011 (r498)
@@ -0,0 +1,49 @@
+package us.isidor.gdl.anaToMia.TmEngine.TopicMaps;
+
+import com.google.gwt.core.client.JsArray;
+
+public class ConstructStub implements Construct {
+ public final native String getId() /*-{
+ return this.getId() + "";
+ }-*/;
+
+
+ public final native boolean equals(Object other) /*-{
+ return this.equals(other);
+ }-*/;
+
+
+ public final native void addItemIdentifier(Locator itemIdentifier) /*-{
+ this.addItemIdentifier(itemIdentifier);
+ }-*/;
+
+
+ public final native JsArray<Locator> getItemIdentifiers() /*-{
+ return this.getItemIdentifiers();
+ }-*/;
+
+
+ public final native Construct getParent() /*-{
+ return this.getParent();
+ }-*/;
+
+
+ public final native TopicMap getTopicMap() /*-{
+ return this.getTopicMap();
+ }-*/;
+
+
+ public final native void remove() /*-{
+ this.remove();
+ }-*/;
+
+
+ public final native void removeItemIdentifier(Locator itemIdentifier) /*-{
+ this.removeItemIdentifier(itemIdentifier);
+ }-*/;
+
+
+ public final TopicMapsTypes classType(){
+ return TopicMapsTypes.Construct;
+ }
+}
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java Wed Jun 22 15:45:56 2011 (r497)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java Wed Jun 22 17:51:04 2011 (r498)
@@ -2,17 +2,20 @@
import java.util.ArrayList;
import com.google.gwt.core.client.JsArray;
+import com.google.gwt.core.client.JsonUtils;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
-import com.google.gwt.user.client.Window;
+import us.isidor.gdl.anaToMia.TmEngine.Base.ExporterException;
import us.isidor.gdl.anaToMia.TmEngine.Base.FormatException;
import us.isidor.gdl.anaToMia.TmEngine.Base.MissingReference;
import us.isidor.gdl.anaToMia.TmEngine.Base.TmEngine;
import us.isidor.gdl.anaToMia.TmEngine.TopicMaps.Association;
import us.isidor.gdl.anaToMia.TmEngine.TopicMaps.Construct;
+import us.isidor.gdl.anaToMia.TmEngine.TopicMaps.ConstructStub;
+import us.isidor.gdl.anaToMia.TmEngine.TopicMaps.Locator;
import us.isidor.gdl.anaToMia.TmEngine.TopicMaps.Name;
import us.isidor.gdl.anaToMia.TmEngine.TopicMaps.Occurrence;
import us.isidor.gdl.anaToMia.TmEngine.TopicMaps.Role;
@@ -77,8 +80,35 @@
@Override
- public String exportTm(TopicMap tm) {
- return exportJTM11(tm);
+ public String exportTm(Construct construct) throws ExporterException {
+ String value = "";
+ switch(((ConstructStub)construct).classType()) {
+ case Association:
+ value = exportJTM11((Association)construct, null, true);
+ break;
+ case Role:
+ value = exportJTM11((Role)construct, null, true);
+ break;
+ case Topic:
+ value = exportJTM11((Topic)construct, null, true);
+ break;
+ case Name:
+ value = exportJTM11((Name)construct, null, true);
+ break;
+ case Variant:
+ value = exportJTM11((Variant)construct, null, true);
+ break;
+ case Occurrence:
+ value = exportJTM11((Occurrence)construct, null, true);
+ break;
+ case TopicMap:
+ value = exportJTM11((TopicMap)construct, null, true);
+ break;
+ default:
+ throw new ExporterException("only the constructs Association, Role, Topic, Name, Variant, Occurrence and TopicMap can be exported!");
+ }
+
+ return JsonUtils.escapeValue(value);
}
@@ -741,13 +771,140 @@
return role;
}
+
+ private String exportItemType(Construct construct) throws ExporterException{
+ switch(((ConstructStub)construct).classType()) {
+ case Association:
+ return "association";
+ case Role:
+ return "role";
+ case Topic:
+ return "topic";
+ case Name:
+ return "name";
+ case Variant:
+ return "variant";
+ case Occurrence:
+ return "occurrence";
+ case TopicMap:
+ return "topicmap";
+ default:
+ throw new ExporterException("only the constructs Association, Role, Topic, Name, Variant, Occurrence and TopicMap can be exported!");
+ }
+ }
+
+
+ private String exportVersion11(){
+ return "\"version\":\"1.1\"";
+ }
+
+
+ private String exportValue(String jsonValue, String key){
+ return "\"" + key + "\":" + jsonValue;
+ }
+
+
+ private String exportStringValue(String value, String key){
+ return "\"" + key + "\":" + value;
+ }
+
+
+ private String curie(Locator uri, Prefixes prefixes) throws ExporterException{
+ String qualifier = prefixes.getQualifier(uri.getReference());
+ String suffix = uri.getReference().substring(prefixes.getNs(qualifier).length());
+ return "[" + qualifier + ":" + suffix + "]";
+ }
+
+
+ private String exportReference(Topic topic, Prefixes prefixes) throws ExporterException{
+ JsArray<Locator> sis = topic.getSubjectIdentifiers();
+ JsArray<Locator> sls = topic.getSubjectLocators();
+ JsArray<Locator> iis = topic.getItemIdentifiers();
+ if(sis.length() != 0){
+ return "si:" + curie(sis.get(0), prefixes).replaceAll("/", "\\/");
+ } else if(sls.length() != 0){
+ return "sl: " + curie(sls.get(0), prefixes).replaceAll("/", "\\/");
+ } else if(iis.length() != 0){
+ return "ii: " + curie(iis.get(0), prefixes).replaceAll("/", "\\/");
+ } else {
+ throw new ExporterException("topics must have at least one identifier set");
+ }
+ }
+
+
+ private String exportReferences(ArrayList<Topic> topics, Prefixes prefixes) throws ExporterException{
+ String value = "";
+ for(int i = 0; i != topics.size(); ++i){
+ value += exportReference(topics.get(i), prefixes);
+ if(i != topics.size() - 1){
+ value += ",";
+ }
+ }
+
+ if(value.length() == 0){
+ return "null";
+ } else {
+ return value;
+ }
+ }
+
- private String exportJTM11(TopicMap tm){
+ private String exportJTM11(TopicMap tm, Prefixes prefixes, boolean standalone){
+ // TODO: implement
+ return null;
+ }
+
+
+ private String exportJTM11(Topic topic, Prefixes prefixes, boolean standalone){
// TODO: implement
-
return null;
}
+
+ private String exportJTM11(Name name, Prefixes prefixes, boolean standalone){
+ // TODO: implement
+ return null;
+ }
+
+
+ private String exportJTM11(Variant variant, Prefixes prefixes, boolean standalone){
+ // TODO: implement
+ return null;
+ }
+
+
+ private String exportJTM11(Occurrence occurrence, Prefixes prefixes, boolean standalone){
+ // TODO: implement
+ return null;
+ }
+
+
+ private String exportJTM11(Association association, Prefixes prefixes, boolean standalone){
+ // TODO: implement
+ return null;
+ }
+
+
+ private String exportJTM11(Role role, Prefixes prefixes, boolean standalone){
+ // TODO: implement
+
+ // version
+ // prefixes
+ // item_type
+ // item_identifiers
+ // reifier
+ // player
+ // type
+
+ return null;
+ }
+
+
+ public static Prefixes createPrefixes(ArrayList<Construct> constructs){
+ // TODO: implement
+ return null;
+ }
+
private class Prefixes {
private ArrayList<String[]> prefixes = new ArrayList<String[]>();
@@ -790,7 +947,24 @@
return null;
}
-
+
+ public String getQualifier(String uri) throws ExporterException{
+ int idxSlash = uri.lastIndexOf("/");
+ int idxSharp = uri.lastIndexOf("#");
+ int lastPos = idxSlash < idxSharp ? idxSharp : idxSlash;
+ String prefix = uri.substring(0, lastPos);
+
+ for (String[] item : prefixes) {
+ if(item[1].equals(prefix)){
+ return item[0];
+ }
+ }
+
+ // not match => throw an exception
+ throw new ExporterException("could not found a qualifier for the name space \"" + uri + "\"");
+ }
+
+
public String getFullUri(String qualifier, String suffix){
String ns = getNs(qualifier);
if(ns != null){
@@ -799,5 +973,20 @@
return null;
}
}
+
+
+ public String toJSON(){
+ String value = "{";
+ for(int i = 0; i != prefixes.size(); ++i){
+ value += "\"" + prefixes.get(i)[0] + "\":\"" + prefixes.get(i)[1] + "\"";
+ if(i == prefixes.size() - 1){
+ value += "}";
+ } else {
+ value += ",";
+ }
+ }
+
+ return value.replaceAll("/", "\\/");
+ }
}
}
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java Wed Jun 22 15:45:56 2011 (r497)
+++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java Wed Jun 22 17:51:04 2011 (r498)
@@ -11,7 +11,6 @@
@Override
public void onModuleLoad() {
Window.alert(">> TEST !!!");
-
String tmData = "{\"version\":\"1.1\","+
"\"item_type\":\"topicmap\"," +
More information about the Isidorus-cvs
mailing list