Revision: 14932
http://gate.svn.sourceforge.net/gate/?rev=14932&view=rev
Author: markagreenwood
Date: 2012-01-08 17:29:25 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
moved the source for the old Swing based HTML document format out into it's
plugin folder -- to do this I've now changed the code to check for a HTML mime
type instead of a subclass of HtmlDocumentFormat
Modified Paths:
--------------
gate/trunk/plugins/Obsolete/html-documentformat/creole.xml
gate/trunk/src/gate/corpora/DocumentImpl.java
gate/trunk/src/gate/corpora/NekoHtmlDocumentFormat.java
gate/trunk/src/gate/html/TestHtml.java
Added Paths:
-----------
gate/trunk/plugins/Obsolete/html-documentformat/build.xml
gate/trunk/plugins/Obsolete/html-documentformat/src/gate/corpora/HtmlDocumentFormat.java
Removed Paths:
-------------
gate/trunk/src/gate/corpora/HtmlDocumentFormat.java
Added: gate/trunk/plugins/Obsolete/html-documentformat/build.xml
===================================================================
--- gate/trunk/plugins/Obsolete/html-documentformat/build.xml
(rev 0)
+++ gate/trunk/plugins/Obsolete/html-documentformat/build.xml 2012-01-08
17:29:25 UTC (rev 14932)
@@ -0,0 +1,86 @@
+<project name="HTML Document Format" basedir="." >
+ <!-- Prevent Ant from warning about includeantruntime not being set -->
+ <property name="build.sysclasspath" value="ignore" />
+
+ <property file="build.properties" />
+
+ <property name="gate.home" location="../.." />
+ <property name="gate.lib" location="${gate.home}/lib" />
+ <property name="gate.jar" location="${gate.home}/bin/gate.jar" />
+ <property name="src.dir" location="src" />
+ <property name="classes.dir" location="classes" />
+ <property name="jar.location" location="HTMLDocumentFormat.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.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"
+ source="1.5" target="1.5" />
+ </target>
+
+ <!-- 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="${plugin.name} JavaDoc"
+ source="1.5">
+ <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>
+
+
+ <!-- create the JAR file -->
+ <target name="jar" depends="compile" >
+ <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
+ -->
+ <target name="build" depends="jar" />
+ <target name="test" />
+ <target name="distro.prepare" depends="clean.classes" />
+</project>
Modified: gate/trunk/plugins/Obsolete/html-documentformat/creole.xml
===================================================================
--- gate/trunk/plugins/Obsolete/html-documentformat/creole.xml 2012-01-08
16:37:22 UTC (rev 14931)
+++ gate/trunk/plugins/Obsolete/html-documentformat/creole.xml 2012-01-08
17:29:25 UTC (rev 14932)
@@ -7,6 +7,7 @@
that depend on its behaviour.
-->
<CREOLE-DIRECTORY>
+ <JAR>HTMLDocumentFormat.jar</JAR>
<CREOLE>
<!-- creole.xml for the old HTML document format -->
<RESOURCE>
Copied:
gate/trunk/plugins/Obsolete/html-documentformat/src/gate/corpora/HtmlDocumentFormat.java
(from rev 14931, gate/trunk/src/gate/corpora/HtmlDocumentFormat.java)
===================================================================
---
gate/trunk/plugins/Obsolete/html-documentformat/src/gate/corpora/HtmlDocumentFormat.java
(rev 0)
+++
gate/trunk/plugins/Obsolete/html-documentformat/src/gate/corpora/HtmlDocumentFormat.java
2012-01-08 17:29:25 UTC (rev 14932)
@@ -0,0 +1,131 @@
+/*
+ * HtmlDocumentFormat.java
+ *
+ * Copyright (c) 1995-2010, The University of Sheffield. See the file
+ * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ * This file is part of GATE (see http://gate.ac.uk/), and is free
+ * software, licenced under the GNU Library General Public License,
+ * Version 2, June 1991 (in the distribution as file licence.html,
+ * and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ * Cristian URSU, 26/May/2000
+ *
+ * $Id$
+ */
+
+package gate.corpora;
+
+import java.io.*;
+import java.net.URLConnection;
+
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.parser.ParserDelegator;
+
+import gate.Document;
+import gate.Resource;
+import gate.creole.ResourceInstantiationException;
+import gate.event.StatusListener;
+import gate.html.HtmlDocumentHandler;
+import gate.util.DocumentFormatException;
+
+//import org.w3c.www.mime.*;
+
+/** The format of Documents. Subclasses of DocumentFormat know about
+ * particular MIME types and how to unpack the information in any
+ * markup or formatting they contain into GATE annotations. Each MIME
+ * type has its own subclass of DocumentFormat, e.g. XmlDocumentFormat,
+ * RtfDocumentFormat, MpegDocumentFormat. These classes register themselves
+ * with a static index residing here when they are constructed. Static
+ * getDocumentFormat methods can then be used to get the appropriate
+ * format class for a particular document.
+ */
+public class HtmlDocumentFormat extends TextualDocumentFormat
+{
+
+ /** Debug flag */
+ private static final boolean DEBUG = false;
+
+ /** Default construction */
+ public HtmlDocumentFormat() { super(); }
+
+ /** We could collect repositioning information during XML parsing */
+ public Boolean supportsRepositioning() {
+ return new Boolean(true);
+ } // supportsRepositioning
+
+ /** Old style of unpackMarkup (without collecting of RepositioningInfo) */
+ public void unpackMarkup(Document doc) throws DocumentFormatException {
+ unpackMarkup(doc, (RepositioningInfo) null, (RepositioningInfo) null);
+ } // unpackMarkup
+
+ /** Unpack the markup in the document. This converts markup from the
+ * native format (e.g. HTML) into annotations in GATE format.
+ * Uses the markupElementsMap to determine which elements to convert, and
+ * what annotation type names to use.
+ * It always tryes to parse te doc's content. It doesn't matter if the
+ * sourceUrl is null or not.
+ *
+ * @param doc The gate document you want to parse.
+ *
+ */
+ public void unpackMarkup(Document doc, RepositioningInfo repInfo,
+ RepositioningInfo ampCodingInfo) throws DocumentFormatException{
+ Reader reader = null;
+ URLConnection conn = null;
+ PrintWriter out = null;
+ HTMLEditorKit.Parser parser = new ParserDelegator();
+
+ if ( doc == null || doc.getContent() == null ){
+ throw new DocumentFormatException(
+ "GATE document is null or no content found. Nothing to parse!");
+ }// End if
+
+ reader = new StringReader(doc.getContent().toString());
+
+ // create a new Htmldocument handler
+ HtmlDocumentHandler htmlDocHandler = new
+ HtmlDocumentHandler(doc, this.markupElementsMap);
+ // Create a Status Listener
+ StatusListener statusListener = new StatusListener(){
+ public void statusChanged(String text){
+ fireStatusChanged(text);
+ }
+ };
+ // Register the listener with htmlDocHandler
+ htmlDocHandler.addStatusListener(statusListener);
+ // set repositioning object
+ htmlDocHandler.setRepositioningInfo(repInfo);
+ // set the object with ampersand coding positions
+ htmlDocHandler.setAmpCodingInfo(ampCodingInfo);
+
+ try{
+ // parse the HTML document
+ parser.parse(reader, htmlDocHandler, true);
+ } catch (IOException e){
+ throw new DocumentFormatException(e);
+ }finally{
+ if (htmlDocHandler != null)
+ htmlDocHandler.removeStatusListener(statusListener);
+ }// End try
+ }//unpackMarkup(doc)
+
+ /** Initialise this resource, and return it. */
+ public Resource init() throws ResourceInstantiationException{
+ // Register HTML mime type
+ MimeType mime = new MimeType("text","html");
+ // Register the class handler for this mime type
+ mimeString2ClassHandlerMap.put(mime.getType()+ "/" + mime.getSubtype(),
+
this);
+ // Register the mime type with mine string
+ mimeString2mimeTypeMap.put(mime.getType() + "/" + mime.getSubtype(), mime);
+ // Register file sufixes for this mime type
+ suffixes2mimeTypeMap.put("html",mime);
+ suffixes2mimeTypeMap.put("htm",mime);
+ // Register magic numbers for this mime type
+ magic2mimeTypeMap.put("<html",mime);
+ // Set the mimeType for this language resource
+ setMimeType(mime);
+ return this;
+ }// init()
+}// class HtmlDocumentFormat
Modified: gate/trunk/src/gate/corpora/DocumentImpl.java
===================================================================
--- gate/trunk/src/gate/corpora/DocumentImpl.java 2012-01-08 16:37:22 UTC
(rev 14931)
+++ gate/trunk/src/gate/corpora/DocumentImpl.java 2012-01-08 17:29:25 UTC
(rev 14932)
@@ -254,7 +254,7 @@
boolean shouldCorrectCR = docFormat instanceof XmlDocumentFormat;
collectInformationForAmpCodding(origContent, ampCodingInfo,
shouldCorrectCR);
- if(docFormat instanceof HtmlDocumentFormat) {
+ if(docFormat.getMimeType().equals(new MimeType("text","html"))) {
collectInformationForWS(origContent, ampCodingInfo);
} // if
} // if
Deleted: gate/trunk/src/gate/corpora/HtmlDocumentFormat.java
===================================================================
--- gate/trunk/src/gate/corpora/HtmlDocumentFormat.java 2012-01-08 16:37:22 UTC
(rev 14931)
+++ gate/trunk/src/gate/corpora/HtmlDocumentFormat.java 2012-01-08 17:29:25 UTC
(rev 14932)
@@ -1,131 +0,0 @@
-/*
- * HtmlDocumentFormat.java
- *
- * Copyright (c) 1995-2010, The University of Sheffield. See the file
- * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
- *
- * This file is part of GATE (see http://gate.ac.uk/), and is free
- * software, licenced under the GNU Library General Public License,
- * Version 2, June 1991 (in the distribution as file licence.html,
- * and also available at http://gate.ac.uk/gate/licence.html).
- *
- * Cristian URSU, 26/May/2000
- *
- * $Id$
- */
-
-package gate.corpora;
-
-import java.io.*;
-import java.net.URLConnection;
-
-import javax.swing.text.html.HTMLEditorKit;
-import javax.swing.text.html.parser.ParserDelegator;
-
-import gate.Document;
-import gate.Resource;
-import gate.creole.ResourceInstantiationException;
-import gate.event.StatusListener;
-import gate.html.HtmlDocumentHandler;
-import gate.util.DocumentFormatException;
-
-//import org.w3c.www.mime.*;
-
-/** The format of Documents. Subclasses of DocumentFormat know about
- * particular MIME types and how to unpack the information in any
- * markup or formatting they contain into GATE annotations. Each MIME
- * type has its own subclass of DocumentFormat, e.g. XmlDocumentFormat,
- * RtfDocumentFormat, MpegDocumentFormat. These classes register themselves
- * with a static index residing here when they are constructed. Static
- * getDocumentFormat methods can then be used to get the appropriate
- * format class for a particular document.
- */
-public class HtmlDocumentFormat extends TextualDocumentFormat
-{
-
- /** Debug flag */
- private static final boolean DEBUG = false;
-
- /** Default construction */
- public HtmlDocumentFormat() { super(); }
-
- /** We could collect repositioning information during XML parsing */
- public Boolean supportsRepositioning() {
- return new Boolean(true);
- } // supportsRepositioning
-
- /** Old style of unpackMarkup (without collecting of RepositioningInfo) */
- public void unpackMarkup(Document doc) throws DocumentFormatException {
- unpackMarkup(doc, (RepositioningInfo) null, (RepositioningInfo) null);
- } // unpackMarkup
-
- /** Unpack the markup in the document. This converts markup from the
- * native format (e.g. HTML) into annotations in GATE format.
- * Uses the markupElementsMap to determine which elements to convert, and
- * what annotation type names to use.
- * It always tryes to parse te doc's content. It doesn't matter if the
- * sourceUrl is null or not.
- *
- * @param doc The gate document you want to parse.
- *
- */
- public void unpackMarkup(Document doc, RepositioningInfo repInfo,
- RepositioningInfo ampCodingInfo) throws DocumentFormatException{
- Reader reader = null;
- URLConnection conn = null;
- PrintWriter out = null;
- HTMLEditorKit.Parser parser = new ParserDelegator();
-
- if ( doc == null || doc.getContent() == null ){
- throw new DocumentFormatException(
- "GATE document is null or no content found. Nothing to parse!");
- }// End if
-
- reader = new StringReader(doc.getContent().toString());
-
- // create a new Htmldocument handler
- HtmlDocumentHandler htmlDocHandler = new
- HtmlDocumentHandler(doc, this.markupElementsMap);
- // Create a Status Listener
- StatusListener statusListener = new StatusListener(){
- public void statusChanged(String text){
- fireStatusChanged(text);
- }
- };
- // Register the listener with htmlDocHandler
- htmlDocHandler.addStatusListener(statusListener);
- // set repositioning object
- htmlDocHandler.setRepositioningInfo(repInfo);
- // set the object with ampersand coding positions
- htmlDocHandler.setAmpCodingInfo(ampCodingInfo);
-
- try{
- // parse the HTML document
- parser.parse(reader, htmlDocHandler, true);
- } catch (IOException e){
- throw new DocumentFormatException(e);
- }finally{
- if (htmlDocHandler != null)
- htmlDocHandler.removeStatusListener(statusListener);
- }// End try
- }//unpackMarkup(doc)
-
- /** Initialise this resource, and return it. */
- public Resource init() throws ResourceInstantiationException{
- // Register HTML mime type
- MimeType mime = new MimeType("text","html");
- // Register the class handler for this mime type
- mimeString2ClassHandlerMap.put(mime.getType()+ "/" + mime.getSubtype(),
-
this);
- // Register the mime type with mine string
- mimeString2mimeTypeMap.put(mime.getType() + "/" + mime.getSubtype(), mime);
- // Register file sufixes for this mime type
- suffixes2mimeTypeMap.put("html",mime);
- suffixes2mimeTypeMap.put("htm",mime);
- // Register magic numbers for this mime type
- magic2mimeTypeMap.put("<html",mime);
- // Set the mimeType for this language resource
- setMimeType(mime);
- return this;
- }// init()
-}// class HtmlDocumentFormat
Modified: gate/trunk/src/gate/corpora/NekoHtmlDocumentFormat.java
===================================================================
--- gate/trunk/src/gate/corpora/NekoHtmlDocumentFormat.java 2012-01-08
16:37:22 UTC (rev 14931)
+++ gate/trunk/src/gate/corpora/NekoHtmlDocumentFormat.java 2012-01-08
17:29:25 UTC (rev 14932)
@@ -36,7 +36,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.cyberneko.html.HTMLConfiguration;
@@ -50,15 +49,10 @@
* and script tags is ignored completely, though the set of tags treated
* in this way is configurable via a CREOLE parameter.
* </p>
- * <p>
- * This class extends {@link HtmlDocumentFormat} to cause DocumentImpl
- * to put the necessary whitespace normalization information into the
- * format's ampCodingInfo.
- * </p>
*/
@CreoleResource(name = "GATE HTML Document Format", isPrivate = true,
autoinstances = {@AutoInstance(hidden = true)})
-public class NekoHtmlDocumentFormat extends HtmlDocumentFormat {
+public class NekoHtmlDocumentFormat extends TextualDocumentFormat {
/** Debug flag */
private static final boolean DEBUG = false;
Modified: gate/trunk/src/gate/html/TestHtml.java
===================================================================
--- gate/trunk/src/gate/html/TestHtml.java 2012-01-08 16:37:22 UTC (rev
14931)
+++ gate/trunk/src/gate/html/TestHtml.java 2012-01-08 17:29:25 UTC (rev
14932)
@@ -16,13 +16,16 @@
package gate.html;
+import gate.Gate;
+import gate.corpora.MimeType;
+
import java.util.Map;
-import junit.framework.*;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
-import gate.Gate;
-
/** Test class for HTML facilities
*/
public class TestHtml extends TestCase
@@ -59,7 +62,7 @@
doc, doc.getSourceUrl()
);
assertTrue( "Bad document Format was produced. HtmlDocumentFormat was
expected",
- docFormat instanceof gate.corpora.HtmlDocumentFormat
+ docFormat.getMimeType().equals(new MimeType("text","html"))
);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs