You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2011/08/30 00:06:19 UTC

svn commit: r1163037 - /incubator/opennlp/sandbox/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java

Author: joern
Date: Mon Aug 29 22:06:19 2011
New Revision: 1163037

URL: http://svn.apache.org/viewvc?rev=1163037&view=rev
Log:
OPENNLP-252 Added support to save a CAS back to the server, based on Cas Editor code.

Modified:
    incubator/opennlp/sandbox/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java

Modified: incubator/opennlp/sandbox/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java?rev=1163037&r1=1163036&r2=1163037&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java (original)
+++ incubator/opennlp/sandbox/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java Mon Aug 29 22:06:19 2011
@@ -20,6 +20,7 @@
 package org.apache.opennlp.corpus_server.caseditor;
 
 import java.awt.Color;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -190,8 +191,45 @@ public class DefaultCasDocumentProvider 
   protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document,
           boolean overwrite) throws CoreException {
     
-    // TODO: Add support to save changes back to the server, what to do, if there is already a newer version?
-    //       A dialog could ask if it should be overwritten, or not.
+    
+    fireElementStateChanging(element);
+
+    if (element instanceof CorpusServerCasEditorInput) {
+      
+      CorpusServerCasEditorInput casInput = (CorpusServerCasEditorInput) element;
+
+      // TODO: What to do if there is already a newer version?
+      //       A dialog could ask if it should be overwritten, or not.
+      
+      if (document instanceof AnnotationDocument) {
+        
+        AnnotationDocument annotationDocument = (AnnotationDocument) document;
+        DocumentUimaImpl documentImpl = (DocumentUimaImpl) annotationDocument.getDocument();
+        
+        ByteArrayOutputStream outStream = new ByteArrayOutputStream(40000); 
+        documentImpl.serialize(outStream);
+        
+        Client client = Client.create();
+        WebResource webResource = client.resource(casInput.getServerUrl());
+        
+        byte xmiBytes[] = outStream.toByteArray();
+        
+        ClientResponse response = webResource
+                .path(casInput.getName())
+                .accept(MediaType.TEXT_XML)
+                // TODO: How to fix this? Shouldn't accept do it?
+                .header("Content-Type", MediaType.TEXT_XML)
+                .put(ClientResponse.class, xmiBytes);
+        
+        // TODO: Check resposne for error
+        
+        // TODO: Is it writing in the UI thread?
+      }
+    }
+
+    // tell everyone that the element changed and is not
+    // dirty any longer
+    fireElementDirtyStateChanged(element, false);
     
   }