Author: pkluegl
Date: Thu Nov 10 15:43:58 2011
New Revision: 1200386

URL: http://svn.apache.org/viewvc?rev=1200386&view=rev
Log:
UIMA-2011
Added preference and logic to load CASs leniently. Preference was added to the 
annotation editor preference page since the logic was placed in 
DocumentUimaImpl. Deactivated by default.

Modified:
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java?rev=1200386&r1=1200385&r2=1200386&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
 Thu Nov 10 15:43:58 2011
@@ -29,5 +29,7 @@ public class AnnotationEditorPreferenceC
   public static final String EDITOR_LINE_LENGTH_HINT = 
           "EDITOR_LINE_LENGTH_HINT";
 
+  public static final String ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM = 
"ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM";
+
 
 }

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java?rev=1200386&r1=1200385&r2=1200386&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
 Thu Nov 10 15:43:58 2011
@@ -29,5 +29,6 @@ public class AnnotationEditorPreferenceI
                IPreferenceStore store = 
CasEditorPlugin.getDefault().getPreferenceStore();
                
store.setDefault(AnnotationEditorPreferenceConstants.EDITOR_LINE_LENGTH_HINT, 
80);
                
store.setDefault(AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_TEXT_SIZE,
 13);
+    
store.setDefault(AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM,
 false);
        }
 }

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java?rev=1200386&r1=1200385&r2=1200386&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java
 Thu Nov 10 15:43:58 2011
@@ -20,6 +20,7 @@
 package org.apache.uima.caseditor.editor;
 
 import org.apache.uima.caseditor.CasEditorPlugin;
+import org.eclipse.jface.preference.BooleanFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
 import org.eclipse.jface.preference.IntegerFieldEditor;
 import org.eclipse.ui.IWorkbench;
@@ -33,6 +34,7 @@ public class AnnotationEditorPreferenceP
 
   private IntegerFieldEditor mEditorLineLengthHint;
   private IntegerFieldEditor mEditorTextSize;
+  private BooleanFieldEditor mEditorPartialTypeystem;
   
   public AnnotationEditorPreferencePage() {
     setPreferenceStore(CasEditorPlugin.getDefault().getPreferenceStore());
@@ -53,6 +55,13 @@ public class AnnotationEditorPreferenceP
             AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_TEXT_SIZE,
             "Editor Text Size", getFieldEditorParent());
     addField(mEditorTextSize);
+    
+    // load CAS with partial type system
+    mEditorPartialTypeystem = new BooleanFieldEditor(
+            
AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM,
+            "Load CAS leniently (WARNING: only for experienced users)", 
getFieldEditorParent());
+    addField(mEditorPartialTypeystem);
+    
   }
 
   public void init(IWorkbench workbench) {

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java?rev=1200386&r1=1200385&r2=1200386&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
 Thu Nov 10 15:43:58 2011
@@ -58,6 +58,7 @@ import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.preference.IPreferenceStore;
 import org.xml.sax.SAXException;
 
 /**
@@ -224,59 +225,56 @@ public class DocumentUimaImpl extends Ab
     SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
     saxParserFactory.setValidating(false);
 
-    SAXParser saxParser;
+    SAXParser saxParser = null;
 
     try {
       saxParser = saxParserFactory.newSAXParser();
     } catch (ParserConfigurationException e) {
-      String message = e.getMessage() != null ? e.getMessage() : "";
-
-      IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-      throw new CoreException(s);
+      throwCoreException(e);
     } catch (SAXException e) {
-      String message = e.getMessage() != null ? e.getMessage() : "";
-
-      IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-      throw new CoreException(s);
+      throwCoreException(e);
     }
 
+    IPreferenceStore store = CasEditorPlugin.getDefault().getPreferenceStore();
+    boolean withPartialTypesystem = store
+            
.getBoolean(AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM);
     if (DocumentFormat.XCAS.equals(format)) {
-      XCASDeserializer dezerializer = new XCASDeserializer(mTypeSystem);
-
-      try {
-        saxParser.parse(content, dezerializer.getXCASHandler(mCAS));
-      } catch (IOException e) {
-        String message = e.getMessage() != null ? e.getMessage() : "";
-
-        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-        throw new CoreException(s);
-      } catch (SAXException e) {
-        String message = e.getMessage() != null ? e.getMessage() : "";
-
-        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-        throw new CoreException(s);
+      if(withPartialTypesystem) {
+        try {
+          XCASDeserializer.deserialize(content, mCAS, true);
+        } catch (SAXException e) {
+          throwCoreException(e);
+        } catch (IOException e) {
+          throwCoreException(e);
+        }
+      } else {
+        XCASDeserializer dezerializer = new XCASDeserializer(mTypeSystem);
+        try {
+          saxParser.parse(content, dezerializer.getXCASHandler(mCAS));
+        } catch (IOException e) {
+          throwCoreException(e);
+        } catch (SAXException e) {
+          throwCoreException(e);
+        }
       }
     } else if (DocumentFormat.XMI.equals(format)) {
-      XmiCasDeserializer dezerializer = new XmiCasDeserializer(mTypeSystem);
-
-      try {
-        saxParser.parse(content, dezerializer.getXmiCasHandler(mCAS));
-      } catch (IOException e) {
-        String message = e.getMessage() != null ? e.getMessage() : "";
-
-        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-        throw new CoreException(s);
-      } catch (SAXException e) {
-        String message = e.getMessage() != null ? e.getMessage() : "";
-
-        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-        throw new CoreException(s);
+      if (withPartialTypesystem) {
+        try {
+          XmiCasDeserializer.deserialize(content, mCAS, true);
+        } catch (SAXException e) {
+          throwCoreException(e);
+        } catch (IOException e) {
+          throwCoreException(e);
+        }
+      } else {
+        try {
+          XmiCasDeserializer dezerializer = new 
XmiCasDeserializer(mTypeSystem);
+          saxParser.parse(content, dezerializer.getXmiCasHandler(mCAS));
+        } catch (IOException e) {
+          throwCoreException(e);
+        } catch (SAXException e) {
+          throwCoreException(e);
+        }
       }
     } else {
       throw new CoreException(new Status(IStatus.ERROR, CasEditorPlugin.ID, 
IStatus.OK,
@@ -284,6 +282,12 @@ public class DocumentUimaImpl extends Ab
     }
   }
 
+  private void throwCoreException(Exception e) throws CoreException {
+    String message = e.getMessage() != null ? e.getMessage() : "";
+    IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
+    throw new CoreException(s);
+  }
+
   /**
    * Serializes the {@link CAS} to the given {@link OutputStream} in the XCAS 
format.
    */
@@ -297,17 +301,9 @@ public class DocumentUimaImpl extends Ab
       try {
         xcasSerializer.serialize(mCAS, xmlSerialzer.getContentHandler());
       } catch (IOException e) {
-        String message = e.getMessage() != null ? e.getMessage() : "";
-
-        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-        throw new CoreException(s);
+        throwCoreException(e);
       } catch (SAXException e) {
-        String message = e.getMessage() != null ? e.getMessage() : "";
-
-        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-        throw new CoreException(s);
+        throwCoreException(e);
       }
     } else if (DocumentFormat.XMI.equals(format)) {
       XmiCasSerializer xmiSerializer = new 
XmiCasSerializer(mCAS.getTypeSystem());
@@ -317,11 +313,7 @@ public class DocumentUimaImpl extends Ab
       try {
         xmiSerializer.serialize(mCAS, xmlSerialzer.getContentHandler());
       } catch (SAXException e) {
-        String message = e.getMessage() != null ? e.getMessage() : "";
-
-        IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, 
message, e);
-
-        throw new CoreException(s);
+        throwCoreException(e);
       }
     } else {
       throw new CoreException(new Status(IStatus.ERROR, CasEditorPlugin.ID, 
IStatus.OK,


Reply via email to