Revision: 18252
          http://sourceforge.net/p/gate/code/18252
Author:   markagreenwood
Date:     2014-08-19 15:24:58 +0000 (Tue, 19 Aug 2014)
Log Message:
-----------
adding the HTML5 microdata export support

Added Paths:
-----------
    gate/trunk/plugins/Format_HTML5Microdata/
    gate/trunk/plugins/Format_HTML5Microdata/.classpath
    gate/trunk/plugins/Format_HTML5Microdata/.project
    gate/trunk/plugins/Format_HTML5Microdata/build.xml
    gate/trunk/plugins/Format_HTML5Microdata/creole.xml
    gate/trunk/plugins/Format_HTML5Microdata/resources/
    gate/trunk/plugins/Format_HTML5Microdata/resources/schema.org/
    gate/trunk/plugins/Format_HTML5Microdata/resources/schema.org/ANNIE.xml
    gate/trunk/plugins/Format_HTML5Microdata/src/
    gate/trunk/plugins/Format_HTML5Microdata/src/gate/
    gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/
    gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/
    
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/ItemScope.java
    
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/Microdata.java
    
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/MicrodataExporter.java
    
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/SortedFeatureMap.java
    gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/
    gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/
    gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/
    
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5.svg
    
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5Icon.java

Added: gate/trunk/plugins/Format_HTML5Microdata/.classpath
===================================================================
--- gate/trunk/plugins/Format_HTML5Microdata/.classpath                         
(rev 0)
+++ gate/trunk/plugins/Format_HTML5Microdata/.classpath 2014-08-19 15:24:58 UTC 
(rev 18252)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/GATE"/>
+       <classpathentry kind="output" path="classes"/>
+</classpath>

Added: gate/trunk/plugins/Format_HTML5Microdata/.project
===================================================================
--- gate/trunk/plugins/Format_HTML5Microdata/.project                           
(rev 0)
+++ gate/trunk/plugins/Format_HTML5Microdata/.project   2014-08-19 15:24:58 UTC 
(rev 18252)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>GATE-plugin-Format_HTML5Microdata</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>

Added: gate/trunk/plugins/Format_HTML5Microdata/build.xml
===================================================================
--- gate/trunk/plugins/Format_HTML5Microdata/build.xml                          
(rev 0)
+++ gate/trunk/plugins/Format_HTML5Microdata/build.xml  2014-08-19 15:24:58 UTC 
(rev 18252)
@@ -0,0 +1,77 @@
+<project name="Format_HTML5Microdata" basedir=".">
+       <property file="build.properties" />
+
+       <property name="gate.home" location="../.." />
+       <property name="gate.lib" location="${gate.home}/lib" />
+       <property name="src.dir" location="src" />
+       <property name="classes.dir" location="classes" />
+       <property name="jar.location" location="microdata.jar" />
+       <property name="doc.dir" location="doc" />
+       <property name="javadoc.dir" location="${doc.dir}/javadoc" />
+
+       <!-- Path to compile - includes gate.jar and GATE/lib/*.jar -->
+       <path id="compile.classpath">
+               <pathelement location="${gate.home}/bin/gate.jar" />
+               <fileset dir="${gate.lib}">
+                       <include name="**/*.jar" />
+                       <include name="**/*.zip" />
+               </fileset>
+       </path>
+
+       <!-- create build directory structure -->
+       <target name="prepare">
+               <mkdir dir="${classes.dir}" />
+       </target>
+
+       <!-- compile the source -->
+       <target name="compile" depends="prepare">
+               <javac classpathref="compile.classpath" srcdir="${src.dir}" 
destdir="${classes.dir}" debug="true" debuglevel="lines,source" 
encoding="UTF-8" source="1.7" target="1.7" />
+       </target>
+
+       <target name="resources" depends="prepare">
+               <copy todir="${classes.dir}/gate/resources" 
includeEmptyDirs="true">
+                       <fileset dir="${src.dir}/gate/resources" />
+               </copy>
+       </target>
+
+       <!-- create the JAR file -->
+       <target name="jar" depends="compile, resources">
+               <jar destfile="${jar.location}" update="false" 
basedir="${classes.dir}" />
+       </target>
+
+       <!-- remove the generated .class files -->
+       <target name="clean.classes">
+               <delete dir="${classes.dir}" />
+       </target>
+
+       <!-- Clean up - remove .class and .jar files -->
+       <target name="clean" depends="clean.classes">
+               <delete file="${jar.location}" />
+       </target>
+
+       <!-- Targets used by the main GATE build file:
+         build: build the plugin - just calls "jar" target
+         test : run the unit tests - there aren't any
+         distro.prepare: remove intermediate files that shouldn't be in the
+                         distribution
+       -->
+
+       <!-- Build JavaDoc documentation -->
+       <target name="doc.prepare">
+               <mkdir dir="${javadoc.dir}" />
+       </target>
+
+       <target name="javadoc" depends="doc.prepare">
+               <javadoc destdir="${javadoc.dir}" packagenames="*" 
classpathref="compile.classpath" encoding="UTF-8" windowtitle="Annotations As 
HTML Microdata JavaDoc" source="1.7">
+                       <sourcepath>
+                               <pathelement location="${src.dir}" />
+                       </sourcepath>
+                       <link href="http://java.sun.com/j2se/1.5.0/docs/api/"; />
+                       <link href="http://gate.ac.uk/gate/doc/javadoc/"; />
+               </javadoc>
+       </target>
+
+       <target name="build" depends="jar" />
+       <target name="test" />
+       <target name="distro.prepare" depends="clean.classes" />
+</project>

Added: gate/trunk/plugins/Format_HTML5Microdata/creole.xml
===================================================================
--- gate/trunk/plugins/Format_HTML5Microdata/creole.xml                         
(rev 0)
+++ gate/trunk/plugins/Format_HTML5Microdata/creole.xml 2014-08-19 15:24:58 UTC 
(rev 18252)
@@ -0,0 +1,3 @@
+<CREOLE-DIRECTORY>
+  <JAR SCAN="true">microdata.jar</JAR>
+</CREOLE-DIRECTORY>

Added: gate/trunk/plugins/Format_HTML5Microdata/resources/schema.org/ANNIE.xml
===================================================================
--- gate/trunk/plugins/Format_HTML5Microdata/resources/schema.org/ANNIE.xml     
                        (rev 0)
+++ gate/trunk/plugins/Format_HTML5Microdata/resources/schema.org/ANNIE.xml     
2014-08-19 15:24:58 UTC (rev 18252)
@@ -0,0 +1,60 @@
+<microdata>
+  <itemscope>
+    <annotation>Person</annotation>
+    <itemtype>http://schema.org/Person</itemtype>
+    <itemprop>name</itemprop>
+    <metadata>
+      <content itemprop="gender">gender</content>
+    </metadata>
+  </itemscope>
+  <itemscope>
+    <annotation>Organization</annotation>
+    <itemtype>http://schema.org/Organization</itemtype>
+    <itemprop>name</itemprop>
+  </itemscope>
+  <itemscope>
+    <annotation>Location</annotation>
+    <restrictions>
+      <feature name="locType">country</feature>
+    </restrictions>
+    <itemtype>http://schema.org/Country</itemtype>
+    <itemprop>name</itemprop>
+  </itemscope>
+  <itemscope>
+    <annotation>Location</annotation>
+    <restrictions>
+      <feature name="locType">city</feature>
+    </restrictions>
+    <itemtype>http://schema.org/City</itemtype>
+    <itemprop>name</itemprop>
+  </itemscope>
+  <itemscope>
+    <annotation>Location</annotation>
+    <restrictions>
+      <feature name="locType">airport</feature>
+    </restrictions>
+    <itemtype>http://schema.org/Airport</itemtype>
+    <itemprop>name</itemprop>
+  </itemscope>
+  <itemscope>
+    <annotation>Location</annotation>
+    <itemtype>http://schema.org/Place</itemtype>
+    <itemprop>name</itemprop>
+  </itemscope>
+  <itemscope>
+    <annotation>Address</annotation>
+    <restrictions>
+      <feature name="kind">email</feature>
+    </restrictions>
+    <itemtype>http://schema.org/ContactPoint</itemtype>
+    <itemprop>email</itemprop>
+  </itemscope>
+  <itemscope>
+    <annotation>Address</annotation>
+    <restrictions>
+      <feature name="kind">phone</feature>
+    </restrictions>
+    <itemtype>http://schema.org/ContactPoint</itemtype>
+    <itemprop>telephone</itemprop>
+  </itemscope>
+</microdata>

Added: 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/ItemScope.java
===================================================================
--- 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/ItemScope.java
                           (rev 0)
+++ 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/ItemScope.java
   2014-08-19 15:24:58 UTC (rev 18252)
@@ -0,0 +1,121 @@
+/*
+ * ItemScope
+ * 
+ * Copyright (c) 2011-2014, The University of Sheffield.
+ * 
+ * This file is part of GATE (see http://gate.ac.uk/), and is free software,
+ * licenced under the GNU Library General Public License, Version 3, June 2007
+ * (in the distribution as file licence.html, and also available at
+ * http://gate.ac.uk/gate/licence.html).
+ * 
+ * Mark A. Greenwood, 11/06/2011
+ */
+
+package gate.creole.microdata;
+
+import gate.Annotation;
+import gate.AnnotationSet;
+import gate.Factory;
+import gate.FeatureMap;
+import gate.Utils;
+import gate.util.InvalidOffsetException;
+
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class ItemScope {
+
+  private String annotation;
+
+  private Map<String, String> restrictions;
+
+  private URI itemtype = null;
+
+  private String itemprop = null;
+
+  private String itemid = null;
+
+  private Map<String, String> metadata;
+
+  public ItemScope(String annotationType, URI itemType) {
+    this.annotation = annotationType;
+    this.itemtype = itemType;
+  }
+
+  public String getAnnotationType() {
+    return annotation;
+  }
+
+  public void setAnnotationType(String annotationType) {
+    this.annotation = annotationType;
+  }
+
+  public URI getItemType() {
+    return itemtype;
+  }
+
+  public void setItemType(URI itemType) {
+    this.itemtype = itemType;
+  }
+
+  public String getItemProp() {
+    return itemprop;
+  }
+
+  public void setItemProp(String itemProp) {
+    this.itemprop = itemProp;
+  }
+
+  public AnnotationSet getMatchingAnnotations(AnnotationSet annotations) {
+    FeatureMap params = Factory.newFeatureMap();
+    if(restrictions != null) params.putAll(restrictions);
+    return annotations.get(annotation, params);
+  }
+
+  public Set<Integer> addMicrodata(Annotation annotation, Boolean nameAsMeta,
+          AnnotationSet outputAS) throws InvalidOffsetException {
+    
+    Set<Integer> created = new HashSet<Integer>();
+    
+    FeatureMap params = new SortedFeatureMap("itemscope", "itemtype", 
"itemid");
+    params.put("itemscope", "itemscope");
+    params.put("itemtype", itemtype.toString());
+    if(itemid != null && annotation.getFeatures().containsKey(itemid)) {
+      params.put("itemid", annotation.getFeatures().get(itemid).toString());
+    }
+    
+    created.add(outputAS.add(annotation.getStartNode().getOffset(), 
annotation.getEndNode()
+            .getOffset(), "span", params));
+
+    if(metadata != null) {
+      for(Map.Entry<String, String> entry : metadata.entrySet()) {
+        if(annotation.getFeatures().containsKey(entry.getKey())) {
+          params = Factory.newFeatureMap();
+          params.put("itemprop", entry.getValue());
+          params.put("content",
+                  "" + annotation.getFeatures().get(entry.getKey()));
+          created.add(outputAS.add(annotation.getStartNode().getOffset(), 
annotation
+                  .getStartNode().getOffset(), "meta", params));
+        }
+      }
+    }
+
+    if(itemprop != null) {
+      params = Factory.newFeatureMap();
+      params.put("itemprop", itemprop);
+      if(!nameAsMeta) {
+        created.add(outputAS.add(annotation.getStartNode().getOffset(), 
annotation
+                .getEndNode().getOffset(), "span", params));
+      } else {
+        params.put("content",
+                Utils.contentFor(outputAS.getDocument(), 
annotation).toString());
+        created.add(outputAS.add(annotation.getStartNode().getOffset(), 
annotation
+                .getStartNode().getOffset(), "meta", params));
+      }
+    }
+    
+    return created;
+  }
+}

Added: 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/Microdata.java
===================================================================
--- 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/Microdata.java
                           (rev 0)
+++ 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/Microdata.java
   2014-08-19 15:24:58 UTC (rev 18252)
@@ -0,0 +1,127 @@
+/*
+ * Microdata
+ * 
+ * Copyright (c) 2011-2014, The University of Sheffield.
+ * 
+ * This file is part of GATE (see http://gate.ac.uk/), and is free software,
+ * licenced under the GNU Library General Public License, Version 3, June 2007
+ * (in the distribution as file licence.html, and also available at
+ * http://gate.ac.uk/gate/licence.html).
+ * 
+ * Mark A. Greenwood, 11/06/2011
+ */
+
+package gate.creole.microdata;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+public class Microdata {
+
+  private List<ItemScope> itemscopes = new ArrayList<ItemScope>();
+
+  /**
+   * Get the list (note order is important) of the ItemScope instances that
+   * describe how GATE annotations are converted into HTML Microdata
+   * 
+   * @return an ordered list of ItemScope instances
+   */
+  public List<ItemScope> getItemscopes() {
+    return itemscopes;
+  }
+
+  /**
+   * Create an instance of this class from an XML configuration file.
+   * 
+   * @param url
+   *          the location of the configuration file
+   * @return a Microdata instance describing the annotations to embed
+   * @throws IOException
+   *           if a problem occurs loading the configuration
+   */
+  protected static Microdata load(URL url) throws IOException {
+    // just use XStream to re-create an instance of this class from the XML 
file
+    return (Microdata)xstream.fromXML(url.openStream());
+  }
+
+  private static XStream xstream = null;
+
+  static {
+    xstream = new XStream();
+    xstream.setClassLoader(Microdata.class.getClassLoader());
+    xstream.alias("itemscope", ItemScope.class);
+    xstream.alias("microdata", Microdata.class);
+    xstream.addImplicitCollection(Microdata.class, "itemscopes");
+    xstream.registerConverter(new AbstractSingleValueConverter() {
+      public boolean canConvert(@SuppressWarnings("rawtypes") Class clazz) {
+        return clazz.equals(URI.class);
+      }
+
+      public Object fromString(String str) {
+        try {
+          return new URI(str);
+        } catch(Exception e) {
+          throw new RuntimeException(e);
+        }
+      }
+    });
+
+    xstream.registerConverter(new Converter() {
+      @SuppressWarnings("rawtypes")
+      public boolean canConvert(Class type) {
+        return type.equals(HashMap.class);
+      }
+
+      public void marshal(Object source, HierarchicalStreamWriter writer,
+              MarshallingContext context) {
+        throw new RuntimeException(
+                "Writing config files is not currently supported!");
+      }
+
+      @SuppressWarnings({"rawtypes", "unchecked"})
+      public Object unmarshal(HierarchicalStreamReader reader,
+              UnmarshallingContext context) {
+        HashMap map = new HashMap();
+        while(reader.hasMoreChildren()) {
+
+          try {
+            if(reader.getNodeName().equals("restrictions")) {
+              // Elements in this map look like
+              // <feature name="locType">city</feature>
+
+              String feature = reader.getAttribute("name");
+              reader.moveDown();
+              String value = reader.getValue();
+              reader.moveUp();
+              map.put(feature, value);
+            } else if(reader.getNodeName().equals("metadata")) {
+              // Elements in this map look like
+              // <content itemprop="gender">gender</word>
+
+              String itemprop = reader.getAttribute("itemprop");
+              reader.moveDown();
+              String feature = reader.getValue().toLowerCase();
+              reader.moveUp();
+              map.put(feature, itemprop);
+            }
+          } catch(Exception e) {
+            e.printStackTrace();
+          }
+        }
+        return map;
+      }
+    });
+  }
+}

Added: 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/MicrodataExporter.java
===================================================================
--- 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/MicrodataExporter.java
                           (rev 0)
+++ 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/MicrodataExporter.java
   2014-08-19 15:24:58 UTC (rev 18252)
@@ -0,0 +1,118 @@
+/*
+ * MicrodataExporter.java
+ * 
+ * Copyright (c) 2011-2014, The University of Sheffield.
+ * 
+ * This file is part of GATE (see http://gate.ac.uk/), and is free software,
+ * licenced under the GNU Library General Public License, Version 3, June 2007
+ * (in the distribution as file licence.html, and also available at
+ * http://gate.ac.uk/gate/licence.html).
+ * 
+ * Mark A. Greenwood, 11/06/2011
+ */
+
+package gate.creole.microdata;
+
+import gate.Annotation;
+import gate.AnnotationSet;
+import gate.Document;
+import gate.DocumentExporter;
+import gate.FeatureMap;
+import gate.GateConstants;
+import gate.creole.metadata.AutoInstance;
+import gate.creole.metadata.CreoleParameter;
+import gate.creole.metadata.CreoleResource;
+import gate.creole.metadata.Optional;
+import gate.creole.metadata.RunTime;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+@SuppressWarnings("serial")
+@CreoleResource(name = "HTML5 Microdata Exporter", comment = "Exports 
Annotations as HTML5 Microdata", tool = true, autoinstances = @AutoInstance, 
icon="HTML5")
+public class MicrodataExporter extends DocumentExporter {
+
+  private URL configURL;
+  private String annotationSetName;
+
+  public URL getConfigURL() {
+    return configURL;
+  }
+  
+  @RunTime
+  @CreoleParameter(defaultValue = "resources/schema.org/ANNIE.xml")
+  public void setConfigURL(URL configURL) {
+    this.configURL = configURL;
+  }
+  
+  public String getAnnotationSetName() {
+    return annotationSetName;
+  }
+  
+  @RunTime
+  @Optional
+  @CreoleParameter
+  public void setAnnotationSetName(String annotationSetName) {
+    this.annotationSetName = annotationSetName;
+  }
+  
+  public MicrodataExporter() {
+    super("HTML5 Microdata","html","text/html");
+  }
+
+  @Override
+  public void export(Document document, OutputStream out, FeatureMap options)
+    throws IOException {
+
+    Microdata microdata = Microdata.load((URL)options.get("configURL"));
+    AnnotationSet inputAS = 
document.getAnnotations((String)options.get("annotationSetName"));
+    
+    PrintStream pout = new PrintStream(out);
+    
+    boolean itempropAsMeta = true;
+
+    // TODO list
+    // 1. deal with co-reference (each itemscope can have multiple entries but
+    // may need to use ids and itemref from the microdata format)
+
+    AnnotationSet originalMarkups =
+      document.getAnnotations(GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
+
+    AnnotationSet body = originalMarkups.get("html");
+    if(body.size() != 1) return;
+    body = originalMarkups.get("body");
+    if(body.size() != 1) return;
+
+    inputAS =
+      inputAS.get(body.firstNode().getOffset(), body.lastNode().getOffset());
+
+    Set<Integer> used = new HashSet<Integer>();
+    Set<Integer> created = new HashSet<Integer>();
+
+    try {
+      for(ItemScope scope : microdata.getItemscopes()) {
+        for(Annotation a : scope.getMatchingAnnotations(inputAS)) {
+          if(!used.contains(a.getId())) {
+            created.addAll(scope.addMicrodata(a, itempropAsMeta,
+              originalMarkups));
+            used.add(a.getId());
+          }
+        }
+      }
+      
+      pout.println(document.toXml(null, false));
+      
+    } catch(Exception e) {
+      throw new IOException(e);
+    }
+    finally {
+      for(Integer id : created) {
+        originalMarkups.remove(originalMarkups.get(id));
+      }
+    }    
+  }
+}

Added: 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/SortedFeatureMap.java
===================================================================
--- 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/SortedFeatureMap.java
                            (rev 0)
+++ 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/creole/microdata/SortedFeatureMap.java
    2014-08-19 15:24:58 UTC (rev 18252)
@@ -0,0 +1,71 @@
+/*
+ * SortedFeatureMap
+ * 
+ * Copyright (c) 2011-2014, The University of Sheffield.
+ * 
+ * This file is part of GATE (see http://gate.ac.uk/), and is free software,
+ * licenced under the GNU Library General Public License, Version 3, June 2007
+ * (in the distribution as file licence.html, and also available at
+ * http://gate.ac.uk/gate/licence.html).
+ * 
+ * Mark A. Greenwood, 11/06/2011
+ */
+
+package gate.creole.microdata;
+
+import gate.util.SimpleFeatureMapImpl;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * A FeatureMap implementation that provides a way of ensuring that the keys
+ * (when accessed with the keySet) are sorted into a given order.
+ * 
+ * @author Mark A. Greenwood
+ */
+public class SortedFeatureMap extends SimpleFeatureMapImpl {
+
+  private static final long serialVersionUID = 8673641740013486436L;
+
+  private Comparator<Object> comparator = null;
+
+  public SortedFeatureMap(final String... keyOrder) {
+    comparator = createComparator(keyOrder);
+  }
+
+  public SortedFeatureMap(Comparator<Object> comparator) {
+    this.comparator = comparator;
+  }
+
+  @Override
+  public Set<Object> keySet() {
+    SortedSet<Object> keys = new TreeSet<Object>(comparator);
+    keys.addAll(super.keySet());
+    return keys;
+  }
+
+  public static Comparator<Object> createComparator(final String[] keyOrder) {
+    return new Comparator<Object>() {
+
+      List<String> order = Arrays.asList(keyOrder);
+
+      @Override
+      public int compare(Object o1, Object o2) {
+
+        Integer i1 = order.indexOf(o1);
+        Integer i2 = order.indexOf(o2);
+
+        int a = i1.compareTo(i2);
+
+        if(a != 0) return a;
+
+        return o1.toString().compareTo(o2.toString());
+      }
+    };
+  }
+}

Added: 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5.svg
===================================================================
--- 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5.svg   
                            (rev 0)
+++ 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5.svg   
    2014-08-19 15:24:58 UTC (rev 18252)
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 
6.00 Build 0)  -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/";
+   xmlns:cc="http://creativecommons.org/ns#";
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+   xmlns:svg="http://www.w3.org/2000/svg";
+   xmlns="http://www.w3.org/2000/svg";
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
+   version="1.1"
+   id="Layer_1"
+   x="0px"
+   y="0px"
+   width="48"
+   height="48"
+   viewBox="108.5 0 48 48"
+   enable-background="new 108.5 0 783 700"
+   xml:space="preserve"
+   inkscape:version="0.48.4 r9939"
+   sodipodi:docname="microdata.svg"><metadata
+     id="metadata29"><rdf:RDF><cc:Work
+         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage"; 
/></cc:Work></rdf:RDF></metadata><defs
+     id="defs27" /><sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1440"
+     inkscape:window-height="876"
+     id="namedview25"
+     showgrid="false"
+     fit-margin-top="1"
+     fit-margin-left="1"
+     fit-margin-right="1"
+     fit-margin-bottom="1"
+     inkscape:zoom="15.257344"
+     inkscape:cx="25.204692"
+     inkscape:cy="27.435438"
+     inkscape:window-x="0"
+     inkscape:window-y="24"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="Layer_1" /><title
+     id="title3">HTML5 Logo</title><g
+     id="g3006"
+     transform="translate(2.71976,-3.17071e-6)"><polygon
+       transform="matrix(0.08178737,0,0,0.08178737,88.886555,-10.251157)"
+       style="fill:#e44d26"
+       id="polygon5"
+       points="702.782,643.698 499.696,700 297.169,643.777 252.037,137.566 
747.963,137.566 " /><polygon
+       transform="matrix(0.08178737,0,0,0.08178737,88.886555,-10.251157)"
+       style="fill:#f16529"
+       id="polygon7"
+       points="702.713,178.957 500,178.957 500,656.965 664.104,611.469 " 
/><polygon
+       transform="matrix(0.08178737,0,0,0.08178737,88.886555,-10.251157)"
+       style="fill:#ebebeb"
+       id="polygon9"
+       points="361.066,428.787 500,428.787 500,366.703 417.846,366.703 
412.172,303.127 500,303.127 500,241.042 499.785,241.042 344.321,241.042 
345.807,257.698 " /><polygon
+       transform="matrix(0.08178737,0,0,0.08178737,88.886555,-10.251157)"
+       style="fill:#ebebeb"
+       id="polygon11"
+       points="500,527.943 499.728,528.016 430.584,509.346 426.164,459.83 
392.565,459.83 363.84,459.83 372.539,557.313 499.714,592.617 500,592.538 " 
/><polygon
+       transform="matrix(0.08178737,0,0,0.08178737,88.886555,-10.251157)"
+       style="fill:#ffffff"
+       id="polygon21"
+       points="627.996,546.823 642.585,383.374 644.101,366.703 627.37,366.703 
499.785,366.703 499.785,428.787 576.235,428.787 569.029,509.306 499.785,527.995 
499.785,592.587 627.063,557.313 " /><polygon
+       transform="matrix(0.08178737,0,0,0.08178737,88.886555,-10.251157)"
+       style="fill:#ffffff"
+       id="polygon23"
+       points="653.823,257.698 655.309,241.042 499.785,241.042 499.785,279.602 
499.785,302.976 499.785,303.127 649.55,303.127 649.55,303.127 649.749,303.127 
650.995,289.172 " /></g></svg>
\ No newline at end of file

Added: 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5Icon.java
===================================================================
--- 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5Icon.java
                          (rev 0)
+++ 
gate/trunk/plugins/Format_HTML5Microdata/src/gate/resources/img/svg/HTML5Icon.java
  2014-08-19 15:24:58 UTC (rev 18252)
@@ -0,0 +1,341 @@
+package gate.resources.img.svg;
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.awt.image.*;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import javax.imageio.ImageIO;
+
+/**
+ * This class has been automatically generated using <a
+ * 
href="http://englishjavadrinker.blogspot.com/search/label/SVGRoundTrip";>SVGRoundTrip</a>.
+ */
+@SuppressWarnings("unused")
+public class HTML5Icon implements
+               javax.swing.Icon {
+       /**
+        * Paints the transcoded SVG image on the specified graphics context. 
You
+        * can install a custom transformation on the graphics context to scale 
the
+        * image.
+        * 
+        * @param g
+        *            Graphics context.
+        */
+       public static void paint(Graphics2D g) {
+        Shape shape = null;
+        Paint paint = null;
+        Stroke stroke = null;
+        Area clip = null;
+         
+        float origAlpha = 1.0f;
+        Composite origComposite = g.getComposite();
+        if (origComposite instanceof AlphaComposite) {
+            AlphaComposite origAlphaComposite = 
+                (AlphaComposite)origComposite;
+            if (origAlphaComposite.getRule() == AlphaComposite.SRC_OVER) {
+                origAlpha = origAlphaComposite.getAlpha();
+            }
+        }
+        
+           Shape clip_ = g.getClip();
+AffineTransform defaultTransform_ = g.getTransform();
+//  is CompositeGraphicsNode
+float alpha__0 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0 = g.getClip();
+AffineTransform defaultTransform__0 = g.getTransform();
+g.transform(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, -108.5f, -0.0f));
+clip = new Area(g.getClip());
+clip.intersect(new Area(new Rectangle2D.Double(108.5,0.0,48.0,48.0)));
+g.setClip(clip);
+// _0 is CompositeGraphicsNode
+float alpha__0_0 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0_0 = g.getClip();
+AffineTransform defaultTransform__0_0 = g.getTransform();
+g.transform(new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, 2.719759941101074f, 
-3.17070998789859E-6f));
+// _0_0 is CompositeGraphicsNode
+float alpha__0_0_0 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0_0_0 = g.getClip();
+AffineTransform defaultTransform__0_0_0 = g.getTransform();
+g.transform(new AffineTransform(0.08178737014532089f, 0.0f, 0.0f, 
0.08178737014532089f, 88.88655853271484f, -10.2511568069458f));
+// _0_0_0 is ShapeNode
+paint = new Color(228, 77, 38, 255);
+shape = new GeneralPath();
+((GeneralPath)shape).moveTo(702.782, 643.698);
+((GeneralPath)shape).lineTo(499.696, 700.0);
+((GeneralPath)shape).lineTo(297.169, 643.777);
+((GeneralPath)shape).lineTo(252.037, 137.566);
+((GeneralPath)shape).lineTo(747.963, 137.566);
+((GeneralPath)shape).closePath();
+g.setPaint(paint);
+g.fill(shape);
+origAlpha = alpha__0_0_0;
+g.setTransform(defaultTransform__0_0_0);
+g.setClip(clip__0_0_0);
+float alpha__0_0_1 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0_0_1 = g.getClip();
+AffineTransform defaultTransform__0_0_1 = g.getTransform();
+g.transform(new AffineTransform(0.08178737014532089f, 0.0f, 0.0f, 
0.08178737014532089f, 88.88655853271484f, -10.2511568069458f));
+// _0_0_1 is ShapeNode
+paint = new Color(241, 101, 41, 255);
+shape = new GeneralPath();
+((GeneralPath)shape).moveTo(702.713, 178.957);
+((GeneralPath)shape).lineTo(500.0, 178.957);
+((GeneralPath)shape).lineTo(500.0, 656.965);
+((GeneralPath)shape).lineTo(664.104, 611.469);
+((GeneralPath)shape).closePath();
+g.setPaint(paint);
+g.fill(shape);
+origAlpha = alpha__0_0_1;
+g.setTransform(defaultTransform__0_0_1);
+g.setClip(clip__0_0_1);
+float alpha__0_0_2 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0_0_2 = g.getClip();
+AffineTransform defaultTransform__0_0_2 = g.getTransform();
+g.transform(new AffineTransform(0.08178737014532089f, 0.0f, 0.0f, 
0.08178737014532089f, 88.88655853271484f, -10.2511568069458f));
+// _0_0_2 is ShapeNode
+paint = new Color(235, 235, 235, 255);
+shape = new GeneralPath();
+((GeneralPath)shape).moveTo(361.066, 428.787);
+((GeneralPath)shape).lineTo(500.0, 428.787);
+((GeneralPath)shape).lineTo(500.0, 366.703);
+((GeneralPath)shape).lineTo(417.846, 366.703);
+((GeneralPath)shape).lineTo(412.172, 303.127);
+((GeneralPath)shape).lineTo(500.0, 303.127);
+((GeneralPath)shape).lineTo(500.0, 241.042);
+((GeneralPath)shape).lineTo(499.785, 241.042);
+((GeneralPath)shape).lineTo(344.321, 241.042);
+((GeneralPath)shape).lineTo(345.807, 257.698);
+((GeneralPath)shape).closePath();
+g.setPaint(paint);
+g.fill(shape);
+origAlpha = alpha__0_0_2;
+g.setTransform(defaultTransform__0_0_2);
+g.setClip(clip__0_0_2);
+float alpha__0_0_3 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0_0_3 = g.getClip();
+AffineTransform defaultTransform__0_0_3 = g.getTransform();
+g.transform(new AffineTransform(0.08178737014532089f, 0.0f, 0.0f, 
0.08178737014532089f, 88.88655853271484f, -10.2511568069458f));
+// _0_0_3 is ShapeNode
+paint = new Color(235, 235, 235, 255);
+shape = new GeneralPath();
+((GeneralPath)shape).moveTo(500.0, 527.943);
+((GeneralPath)shape).lineTo(499.728, 528.016);
+((GeneralPath)shape).lineTo(430.584, 509.346);
+((GeneralPath)shape).lineTo(426.164, 459.83);
+((GeneralPath)shape).lineTo(392.565, 459.83);
+((GeneralPath)shape).lineTo(363.84, 459.83);
+((GeneralPath)shape).lineTo(372.539, 557.313);
+((GeneralPath)shape).lineTo(499.714, 592.617);
+((GeneralPath)shape).lineTo(500.0, 592.538);
+((GeneralPath)shape).closePath();
+g.setPaint(paint);
+g.fill(shape);
+origAlpha = alpha__0_0_3;
+g.setTransform(defaultTransform__0_0_3);
+g.setClip(clip__0_0_3);
+float alpha__0_0_4 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0_0_4 = g.getClip();
+AffineTransform defaultTransform__0_0_4 = g.getTransform();
+g.transform(new AffineTransform(0.08178737014532089f, 0.0f, 0.0f, 
0.08178737014532089f, 88.88655853271484f, -10.2511568069458f));
+// _0_0_4 is ShapeNode
+paint = new Color(255, 255, 255, 255);
+shape = new GeneralPath();
+((GeneralPath)shape).moveTo(627.996, 546.823);
+((GeneralPath)shape).lineTo(642.585, 383.374);
+((GeneralPath)shape).lineTo(644.101, 366.703);
+((GeneralPath)shape).lineTo(627.37, 366.703);
+((GeneralPath)shape).lineTo(499.785, 366.703);
+((GeneralPath)shape).lineTo(499.785, 428.787);
+((GeneralPath)shape).lineTo(576.235, 428.787);
+((GeneralPath)shape).lineTo(569.029, 509.306);
+((GeneralPath)shape).lineTo(499.785, 527.995);
+((GeneralPath)shape).lineTo(499.785, 592.587);
+((GeneralPath)shape).lineTo(627.063, 557.313);
+((GeneralPath)shape).closePath();
+g.setPaint(paint);
+g.fill(shape);
+origAlpha = alpha__0_0_4;
+g.setTransform(defaultTransform__0_0_4);
+g.setClip(clip__0_0_4);
+float alpha__0_0_5 = origAlpha;
+origAlpha = origAlpha * 1.0f;
+g.setComposite(AlphaComposite.getInstance(3, origAlpha));
+Shape clip__0_0_5 = g.getClip();
+AffineTransform defaultTransform__0_0_5 = g.getTransform();
+g.transform(new AffineTransform(0.08178737014532089f, 0.0f, 0.0f, 
0.08178737014532089f, 88.88655853271484f, -10.2511568069458f));
+// _0_0_5 is ShapeNode
+paint = new Color(255, 255, 255, 255);
+shape = new GeneralPath();
+((GeneralPath)shape).moveTo(653.823, 257.698);
+((GeneralPath)shape).lineTo(655.309, 241.042);
+((GeneralPath)shape).lineTo(499.785, 241.042);
+((GeneralPath)shape).lineTo(499.785, 279.602);
+((GeneralPath)shape).lineTo(499.785, 302.976);
+((GeneralPath)shape).lineTo(499.785, 303.127);
+((GeneralPath)shape).lineTo(649.55, 303.127);
+((GeneralPath)shape).lineTo(649.55, 303.127);
+((GeneralPath)shape).lineTo(649.749, 303.127);
+((GeneralPath)shape).lineTo(650.995, 289.172);
+((GeneralPath)shape).closePath();
+g.setPaint(paint);
+g.fill(shape);
+origAlpha = alpha__0_0_5;
+g.setTransform(defaultTransform__0_0_5);
+g.setClip(clip__0_0_5);
+origAlpha = alpha__0_0;
+g.setTransform(defaultTransform__0_0);
+g.setClip(clip__0_0);
+origAlpha = alpha__0;
+g.setTransform(defaultTransform__0);
+g.setClip(clip__0);
+g.setTransform(defaultTransform_);
+g.setClip(clip_);
+
+       }
+       
+       public Image getImage() {
+               BufferedImage image =
+            new BufferedImage(getIconWidth(), getIconHeight(),
+                    BufferedImage.TYPE_INT_ARGB);
+       Graphics2D g = image.createGraphics();
+       paintIcon(null, g, 0, 0);
+       g.dispose();
+       return image;
+       }
+
+    /**
+     * Returns the X of the bounding box of the original SVG image.
+     * 
+     * @return The X of the bounding box of the original SVG image.
+     */
+    public static int getOrigX() {
+        return 4;
+    }
+
+    /**
+     * Returns the Y of the bounding box of the original SVG image.
+     * 
+     * @return The Y of the bounding box of the original SVG image.
+     */
+    public static int getOrigY() {
+        return 2;
+    }
+
+       /**
+        * Returns the width of the bounding box of the original SVG image.
+        * 
+        * @return The width of the bounding box of the original SVG image.
+        */
+       public static int getOrigWidth() {
+               return 48;
+       }
+
+       /**
+        * Returns the height of the bounding box of the original SVG image.
+        * 
+        * @return The height of the bounding box of the original SVG image.
+        */
+       public static int getOrigHeight() {
+               return 48;
+       }
+
+       /**
+        * The current width of this resizable icon.
+        */
+       int width;
+
+       /**
+        * The current height of this resizable icon.
+        */
+       int height;
+
+       /**
+        * Creates a new transcoded SVG image.
+        */
+       public HTML5Icon() {
+        this.width = getOrigWidth();
+        this.height = getOrigHeight();
+       }
+       
+       /**
+        * Creates a new transcoded SVG image with the given dimensions.
+        *
+        * @param size the dimensions of the icon
+        */
+       public HTML5Icon(Dimension size) {
+       this.width = size.width;
+       this.height = size.width;
+       }
+
+       public HTML5Icon(int width, int height) {
+       this.width = width;
+       this.height = height;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see javax.swing.Icon#getIconHeight()
+        */
+    @Override
+       public int getIconHeight() {
+               return height;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see javax.swing.Icon#getIconWidth()
+        */
+    @Override
+       public int getIconWidth() {
+               return width;
+       }
+
+       public void setDimension(Dimension newDimension) {
+               this.width = newDimension.width;
+               this.height = newDimension.height;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see javax.swing.Icon#paintIcon(java.awt.Component, 
java.awt.Graphics,
+        * int, int)
+        */
+    @Override
+       public void paintIcon(Component c, Graphics g, int x, int y) {
+               Graphics2D g2d = (Graphics2D) g.create();
+               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                               RenderingHints.VALUE_ANTIALIAS_ON);
+               g2d.translate(x, y);
+                                               
+               Area clip = new Area(new Rectangle(0, 0, this.width, 
this.height));             
+               if (g2d.getClip() != null) clip.intersect(new 
Area(g2d.getClip()));             
+               g2d.setClip(clip);
+
+               double coef1 = (double) this.width / (double) getOrigWidth();
+               double coef2 = (double) this.height / (double) getOrigHeight();
+               double coef = Math.min(coef1, coef2);
+               g2d.scale(coef, coef);
+               paint(g2d);
+               g2d.dispose();
+       }
+}
+

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to