You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/08/29 20:38:41 UTC
svn commit: r1758299 - in /uima/uimaj/branches/experiment-v3-jcas:
uimaj-ep-cas-editor-ide/
uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/
uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/
uimaj-ep-cas-e...
Author: schor
Date: Mon Aug 29 20:38:41 2016
New Revision: 1758299
URL: http://svn.apache.org/viewvc?rev=1758299&view=rev
Log:
[UIMA-4685] merge from trunk
Removed:
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentFormat.java
Modified:
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/ (props changed)
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/ (props changed)
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/pom.xml (props changed)
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java (contents, props changed)
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ (props changed)
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/plugin.xml
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/pom.xml
uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
Propchange: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 29 20:38:41 2016
@@ -1,4 +1,4 @@
/uima/uimaj/branches/depend-on-july-9-build-tools/uimaj-ep-cas-editor:963167-964468
/uima/uimaj/branches/depend-on-parent-pom-4/uimaj-ep-cas-editor:961329-961745
/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-ep-cas-editor:1436573-1462257
-/uima/uimaj/trunk/uimaj-ep-cas-editor:1690273-1693269
+/uima/uimaj/trunk/uimaj-ep-cas-editor:1690273-1758297
Propchange: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Aug 29 20:38:41 2016
@@ -0,0 +1,4 @@
+/uima/uimaj/branches/2.6.0-json/uimaj-ep-cas-editor-ide:1616936-1617592
+/uima/uimaj/branches/depend-on-july-9-build-tools/uimaj-ep-cas-editor-ide:963167-964468
+/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-ep-cas-editor-ide:1436573-1462257
+/uima/uimaj/trunk/uimaj-ep-cas-editor-ide:1690273-1758297
Propchange: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/pom.xml
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 29 20:38:41 2016
@@ -1,4 +1,4 @@
/uima/uimaj/branches/depend-on-july-9-build-tools/uimaj-ep-cas-editor/pom.xml:963167-964468
/uima/uimaj/branches/depend-on-parent-pom-4/uimaj-ep-cas-editor/pom.xml:961329-961745
/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-ep-cas-editor-ide/pom.xml:1436573-1462257
-/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/pom.xml:1690273-1693269
+/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/pom.xml:1690273-1758297
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java?rev=1758299&r1=1758298&r2=1758299&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java Mon Aug 29 20:38:41 2016
@@ -36,12 +36,12 @@ import org.apache.uima.caseditor.core.mo
import org.apache.uima.caseditor.core.model.dotcorpus.DotCorpusSerializer;
import org.apache.uima.caseditor.editor.AnnotationStyle;
import org.apache.uima.caseditor.editor.CasDocumentProvider;
-import org.apache.uima.caseditor.editor.DocumentFormat;
import org.apache.uima.caseditor.editor.DocumentUimaImpl;
import org.apache.uima.caseditor.editor.ICasDocument;
import org.apache.uima.caseditor.editor.ICasEditor;
import org.apache.uima.caseditor.ide.searchstrategy.ITypeSystemSearchStrategy;
import org.apache.uima.caseditor.ide.searchstrategy.TypeSystemSearchStrategyFactory;
+import org.apache.uima.util.CasIOUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
@@ -315,7 +315,6 @@ public class DefaultCasDocumentProvider
if (styleFile.exists()) {
InputStream styleFileIn = null;
- ;
DotCorpus dotCorpus = null;
try {
styleFileIn = styleFile.getContents();
@@ -403,38 +402,7 @@ public class DefaultCasDocumentProvider
CAS cas = DocumentUimaImpl.getVirginCAS(typeSystemFile);
- DocumentFormat documentFormat;
-
- // Which file format to use ?
- if (casFile.getName().endsWith("xmi")) {
- documentFormat = DocumentFormat.XMI;
- } else if (casFile.getName().endsWith("xcas")) {
- documentFormat = DocumentFormat.XCAS;
- } else {
- throw new CoreException(new Status(IStatus.ERROR, "org.apache.uima.dev",
- "Unkown file format!"));
- }
-
- InputStream casIn = casFile.getContents();
-
- org.apache.uima.caseditor.editor.ICasDocument doc;
-
- try {
- doc = new DocumentUimaImpl(cas, casIn, documentFormat, typeSystemFile.getFullPath().makeRelative().toString());
- } finally {
- try {
- casIn.close();
- } catch (IOException e) {
- // Unable to close file after loading it
- //
- // In the current implementation the user
- // does not notice the error and can just
- // edit the file, tough saving it might fail
- // if the io error persists
-
- CasEditorPlugin.log(e);
- }
- }
+ ICasDocument doc = new DocumentUimaImpl(cas, casFile, typeSystemFile.getFullPath().makeRelative().toString());
elementErrorStatus.remove(element);
Propchange: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 29 20:38:41 2016
@@ -1,3 +1,4 @@
/uima/uimaj/branches/depend-on-july-9-build-tools/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java:963167-964468
/uima/uimaj/branches/depend-on-parent-pom-4/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java:961329-961745
/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java:1436573-1462257
+/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java:1690273-1758297
Propchange: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 29 20:38:41 2016
@@ -1,3 +1,4 @@
/uima/uimaj/branches/depend-on-july-9-build-tools/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/wizards:963167-964468
/uima/uimaj/branches/depend-on-parent-pom-4/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/wizards:961329-961745
/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards:1436573-1462257
+/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards:1690273-1758297
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java?rev=1758299&r1=1758298&r2=1758299&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java Mon Aug 29 20:38:41 2016
@@ -35,121 +35,101 @@ import javax.swing.text.rtf.RTFEditorKit
import org.apache.uima.UIMAFramework;
import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.impl.XCASSerializer;
-import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.cas.SerialFormat;
import org.apache.uima.caseditor.core.TaeError;
-import org.apache.uima.caseditor.editor.DocumentFormat;
import org.apache.uima.internal.util.XMLUtils;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.CasIOUtils;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLInputSource;
import org.apache.uima.util.XMLParser;
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
-import org.xml.sax.SAXException;
/**
*/
final class DocumentImportStructureProvider implements IImportStructureProvider {
- private final String language;
-
- private final String importEncoding; // https://issues.apache.org/jira/browse/UIMA-1808
-
- private final DocumentFormat casFormat;
+ private final String language;
+
+ private final String importEncoding; // https://issues.apache.org/jira/browse/UIMA-1808
+
+ private final SerialFormat casFormat;
+
/**
* Constructs a new DocumentImportStructureProvider object.
*
* @param containerFullPath
*/
public DocumentImportStructureProvider(String language, String importEncoding,
- DocumentFormat casFormat) {
+ SerialFormat casFormat) {
this.language = language;
- this.importEncoding = importEncoding; // https://issues.apache.org/jira/browse/UIMA-1808
- this.casFormat = casFormat;
+ this.importEncoding = importEncoding; // https://issues.apache.org/jira/browse/UIMA-1808
+ this.casFormat = casFormat;
}
-
private static String removeNonXmlChars(String input) {
-
+
char inputChars[] = input.toCharArray();
-
+
StringBuilder cleanedString = new StringBuilder(inputChars.length);
-
+
int startIndex = 0;
- int offendingCharOsset;
- while ((offendingCharOsset = XMLUtils.checkForNonXmlCharacters(
- inputChars, startIndex, inputChars.length - startIndex, false)) != -1) {
- cleanedString.append(inputChars, startIndex, offendingCharOsset - startIndex);
- startIndex = offendingCharOsset + 1;
- }
-
- cleanedString.append(inputChars, startIndex, inputChars.length - startIndex);
-
+ int offendingCharOsset;
+ while ((offendingCharOsset = XMLUtils.checkForNonXmlCharacters(inputChars, startIndex,
+ inputChars.length - startIndex, false)) != -1) {
+ cleanedString.append(inputChars, startIndex, offendingCharOsset - startIndex);
+ startIndex = offendingCharOsset + 1;
+ }
+
+ cleanedString.append(inputChars, startIndex, inputChars.length - startIndex);
+
return cleanedString.toString();
}
-
+
public List<Object> getChildren(Object element) {
return null;
}
- private static CAS createEmtpyCAS()
- {
- XMLInputSource xmlTypeSystemSource = new XMLInputSource(DocumentImportStructureProvider.class
- .getResourceAsStream("ts.xml"), new File(""));
- XMLParser xmlParser = UIMAFramework.getXMLParser();
+ private static CAS createEmtpyCAS() {
+ XMLInputSource xmlTypeSystemSource = new XMLInputSource(
+ DocumentImportStructureProvider.class.getResourceAsStream("ts.xml"), new File(""));
+ XMLParser xmlParser = UIMAFramework.getXMLParser();
- TypeSystemDescription typeSystemDesciptor;
+ TypeSystemDescription typeSystemDesciptor;
- try {
- typeSystemDesciptor = (TypeSystemDescription) xmlParser
- .parse(xmlTypeSystemSource);
- } catch (InvalidXMLException e1) {
- throw new TaeError("Integrated ts.xml typesystem descriptor is not valid!");
- }
+ try {
+ typeSystemDesciptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
+ } catch (InvalidXMLException e1) {
+ throw new TaeError("Integrated ts.xml typesystem descriptor is not valid!");
+ }
- try {
- return CasCreationUtils.createCas(typeSystemDesciptor,
- null, null);
- } catch (ResourceInitializationException e) {
+ try {
+ return CasCreationUtils.createCas(typeSystemDesciptor, null, null);
+ } catch (ResourceInitializationException e) {
- // should not happen
- throw new TaeError("Unexpected exception!");
- }
+ // should not happen
+ throw new TaeError("Unexpected exception!");
+ }
}
- private InputStream getDocument(String fileName, String text, String language, DocumentFormat format) {
+ private InputStream getDocument(String fileName, String text, String language,
+ SerialFormat format) {
String failedToImportLine = "Failed to import: " + fileName + "\n\n";
-
+
CAS cas = createEmtpyCAS();
cas.setDocumentText(removeNonXmlChars(text));
cas.setDocumentLanguage(language);
-
+
ByteArrayOutputStream out = new ByteArrayOutputStream(40000);
- if (DocumentFormat.XCAS.equals(format)) {
- try {
- XCASSerializer.serialize(cas, out);
- } catch (SAXException e) {
- // should not happen
- throw new TaeError(failedToImportLine + e.getMessage(), e);
- } catch (IOException e) {
- // will not happen, writing to memory
- throw new TaeError(failedToImportLine + e.getMessage(), e);
- }
- }
- else if (DocumentFormat.XMI.equals(format)) {
- try {
- XmiCasSerializer.serialize(cas, out);
- } catch (SAXException e) {
- // should not happen
- throw new TaeError(failedToImportLine + e.getMessage(), e);
- }
- } else {
- throw new TaeError(failedToImportLine + "Unkown document type!", null);
+ try {
+ CasIOUtils.save(cas, out, format);
+ } catch (IOException e) {
+ throw new TaeError(failedToImportLine + e.getMessage(), e);
}
return new ByteArrayInputStream(out.toByteArray());
@@ -197,8 +177,8 @@ final class DocumentImportStructureProvi
textStringBuffer.append(new String(readBuffer, 0, length, importEncoding));
}
- return getDocument(fileToImport.getAbsolutePath(), textStringBuffer.toString(),
- language, casFormat);
+ return getDocument(fileToImport.getAbsolutePath(), textStringBuffer.toString(), language,
+ casFormat);
} catch (FileNotFoundException e) {
return null;
} catch (IOException e) {
@@ -251,19 +231,9 @@ final class DocumentImportStructureProvi
if (fileName.endsWith(".rtf") || fileName.endsWith(".txt")) {
int nameWithouEndingLength = fileName.lastIndexOf(".");
String nameWithouEnding = fileName.substring(0, nameWithouEndingLength);
-
- String ending;
- if (DocumentFormat.XMI.equals(casFormat)) {
- ending = "xmi";
- }
- else if (DocumentFormat.XCAS.equals(casFormat)) {
- ending = "xcas";
- }
- else {
- throw new IllegalStateException("Unkown DocumentFormat!");
- }
-
- return nameWithouEnding + "." + ending;
+
+ String ending = casFormat.getDefaultFileExtension();
+ return nameWithouEnding + "." + ending;
} else {
return fileName;
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java?rev=1758299&r1=1758298&r2=1758299&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java Mon Aug 29 20:38:41 2016
@@ -30,8 +30,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.apache.uima.cas.SerialFormat;
import org.apache.uima.caseditor.CasEditorPlugin;
-import org.apache.uima.caseditor.editor.DocumentFormat;
import org.apache.uima.caseditor.ide.CasEditorIdePlugin;
import org.apache.uima.caseditor.ide.CasEditorIdePreferenceConstants;
import org.eclipse.core.resources.IContainer;
@@ -97,7 +97,7 @@ final class ImportDocumentWizardPage ext
private String language;
- private DocumentFormat documentFormat;
+ private SerialFormat documentFormat;
private TableViewer fileTable;
@@ -430,14 +430,19 @@ final class ImportDocumentWizardPage ext
final Combo casFormatCombo = new Combo(importOptions, SWT.READ_ONLY);
casFormatCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- casFormatCombo.setItems(new String[]{DocumentFormat.XMI.toString(), DocumentFormat.XCAS.toString()});
- documentFormat = DocumentFormat.XMI;
+ SerialFormat[] values = SerialFormat.values();
+ String[] stringValues = new String[values.length];
+ for (int i = 0; i < values.length; i++) {
+ stringValues[i] = values[i].toString();
+ }
+ casFormatCombo.setItems(stringValues);
+ documentFormat = SerialFormat.XMI;
casFormatCombo.select(0);
casFormatCombo.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
- documentFormat = DocumentFormat.valueOf(casFormatCombo.getText());
+ documentFormat = SerialFormat.valueOf(casFormatCombo.getText());
}
public void widgetDefaultSelected(SelectionEvent e) {
@@ -477,7 +482,7 @@ final class ImportDocumentWizardPage ext
return language;
}
- DocumentFormat getCasFormat() {
+ SerialFormat getCasFormat() {
return documentFormat;
}
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/plugin.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/plugin.xml?rev=1758299&r1=1758298&r2=1758299&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/plugin.xml (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/plugin.xml Mon Aug 29 20:38:41 2016
@@ -30,7 +30,7 @@
contributorClass="org.apache.uima.caseditor.editor.AnnotationEditorActionContributor"
id="org.apache.uima.caseditor.editor"
default="true"
- extensions="xcas,xmi">
+ extensions="xcas,xmi,bcas,scas">
</editor>
</extension>
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/pom.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/pom.xml?rev=1758299&r1=1758298&r2=1758299&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/pom.xml (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/pom.xml Mon Aug 29 20:38:41 2016
@@ -150,6 +150,13 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>launching</artifactId>
+ <version>[3.3.0,6.0.0)</version>
+ <scope>provided</scope>
+ </dependency>
+
<!-- https://issues.apache.org/jira/browse/UIMA-3510 -->
<dependency>
<groupId>org.eclipse.equinox</groupId>
@@ -223,6 +230,7 @@
org.eclipse.ui.workbench,
org.eclipse.core.runtime,
org.eclipse.core.resources,
+ org.eclipse.jdt.core,
org.junit4;bundle-version="4.5.0";resolution:=optional
</Require-Bundle>
<Import-Package>
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java?rev=1758299&r1=1758298&r2=1758299&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java Mon Aug 29 20:38:41 2016
@@ -19,16 +19,19 @@
package org.apache.uima.caseditor.editor;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
+import java.util.List;
import org.apache.uima.ResourceSpecifierFactory;
import org.apache.uima.UIMAFramework;
@@ -36,77 +39,67 @@ import org.apache.uima.cas.CAS;
import org.apache.uima.cas.FSIndex;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.SerialFormat;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
-import org.apache.uima.cas.impl.XCASDeserializer;
-import org.apache.uima.cas.impl.XCASSerializer;
-import org.apache.uima.cas.impl.XmiCasDeserializer;
-import org.apache.uima.cas.impl.XmiCasSerializer;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.caseditor.CasEditorPlugin;
import org.apache.uima.caseditor.editor.util.StrictTypeConstraint;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.impl.ResourceManager_impl;
import org.apache.uima.resource.metadata.FsIndexDescription;
import org.apache.uima.resource.metadata.TypePriorities;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.resource.metadata.impl.FsIndexDescription_impl;
import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.CasIOUtils;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLInputSource;
import org.apache.uima.util.XMLParser;
-import org.apache.uima.util.XMLSerializer;
+import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.xml.sax.SAXException;
/**
* This document implementation is based on an uima cas object.
*/
public class DocumentUimaImpl extends AbstractDocument {
- // TODO: Remove field not needed anymore
- private final TypeSystem mTypeSystem;
-
+ public static final String JAVA_NATURE = "org.eclipse.jdt.core.javanature";
+
private CAS mCAS;
- private final DocumentFormat format;
+ private SerialFormat format = SerialFormat.XMI;
private final String typeSystemText;
-
- /**
- * Initializes a new instance.
- */
- public DocumentUimaImpl(CAS cas, InputStream in, DocumentFormat format) throws CoreException {
- this(cas, in, format, null);
- }
-
/**
* Initializes a new instance.
*
* @param cas
- * @param in
- * @param format
- * @param typeSystemText type system string
+ * @param casFile
+ * @param typeSystemText
+ * type system string
*/
- public DocumentUimaImpl(CAS cas, InputStream in, DocumentFormat format, String typeSystemText) throws CoreException {
+ public DocumentUimaImpl(CAS cas, IFile casFile, String typeSystemText) throws CoreException {
mCAS = cas;
- mTypeSystem = cas.getTypeSystem();
-
- this.format = format;
-
this.typeSystemText = typeSystemText;
- setContent(in);
+ setContent(casFile);
}
-
-
+
/**
* Retrieves the {@link CAS}.
*/
@@ -118,8 +111,7 @@ public class DocumentUimaImpl extends Ab
public String getTypeSystemText() {
return typeSystemText;
}
-
-
+
/**
* Internally removes an annotation from the {@link CAS}.
*
@@ -128,22 +120,21 @@ public class DocumentUimaImpl extends Ab
private void addFeatureStructureInternal(FeatureStructure featureStructure) {
getCAS().getIndexRepository().addFS(featureStructure);
}
-
+
/**
* Adds the given annotation to the {@link CAS}.
*/
public void addFeatureStructure(FeatureStructure annotation) {
addFeatureStructureInternal(annotation);
-
+
fireAddedFeatureStructure(annotation);
}
-
public void addFeatureStructures(Collection<? extends FeatureStructure> annotations) {
for (FeatureStructure annotation : annotations) {
addFeatureStructureInternal(annotation);
}
-
+
if (annotations.size() > 0) {
fireAddedFeatureStructure(annotations);
}
@@ -207,8 +198,8 @@ public class DocumentUimaImpl extends Ab
StrictTypeConstraint typeConstrain = new StrictTypeConstraint(type);
- FSIterator<AnnotationFS> strictTypeIterator = mCAS.createFilteredIterator(
- annotationIndex.iterator(), typeConstrain);
+ FSIterator<AnnotationFS> strictTypeIterator = mCAS
+ .createFilteredIterator(annotationIndex.iterator(), typeConstrain);
return fsIteratorToCollection(strictTypeIterator);
}
@@ -242,66 +233,23 @@ public class DocumentUimaImpl extends Ab
/**
* Sets the content. The XCAS {@link InputStream} gets parsed.
*/
- private void setContent(InputStream content) throws CoreException {
+ private void setContent(IFile casFile) throws CoreException {
- SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
- saxParserFactory.setValidating(false);
-
- SAXParser saxParser = null;
+ IPreferenceStore store = CasEditorPlugin.getDefault().getPreferenceStore();
+ boolean withPartialTypesystem = store
+ .getBoolean(AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM);
+ URI uri = casFile.getLocationURI();
+ if (casFile.isLinked()) {
+ uri = casFile.getRawLocationURI();
+ }
+ File file = EFS.getStore(uri).toLocalFile(0, new NullProgressMonitor());
try {
- saxParser = saxParserFactory.newSAXParser();
- } catch (ParserConfigurationException e) {
- throwCoreException(e);
- } catch (SAXException e) {
+ format = CasIOUtils.load(file.toURI().toURL(), null, mCAS, withPartialTypesystem);
+ } catch (IOException e) {
throwCoreException(e);
}
- IPreferenceStore store = CasEditorPlugin.getDefault().getPreferenceStore();
- boolean withPartialTypesystem = store
- .getBoolean(AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM);
- if (DocumentFormat.XCAS.equals(format)) {
- 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)) {
- 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,
- "Unkown file format!", null));
- }
}
private void throwCoreException(Exception e) throws CoreException {
@@ -314,35 +262,13 @@ public class DocumentUimaImpl extends Ab
* Serializes the {@link CAS} to the given {@link OutputStream} in the XCAS format.
*/
public void serialize(OutputStream out) throws CoreException {
-
- if (DocumentFormat.XCAS.equals(format)) {
- XCASSerializer xcasSerializer = new XCASSerializer(mCAS.getTypeSystem());
-
- XMLSerializer xmlSerialzer = new XMLSerializer(out, true);
-
- try {
- xcasSerializer.serialize(mCAS, xmlSerialzer.getContentHandler());
- } catch (IOException e) {
- throwCoreException(e);
- } catch (SAXException e) {
- throwCoreException(e);
- }
- } else if (DocumentFormat.XMI.equals(format)) {
- XmiCasSerializer xmiSerializer = new XmiCasSerializer(mCAS.getTypeSystem());
-
- XMLSerializer xmlSerialzer = new XMLSerializer(out, true);
-
- try {
- xmiSerializer.serialize(mCAS, xmlSerialzer.getContentHandler());
- } catch (SAXException e) {
- throwCoreException(e);
- }
- } else {
- throw new CoreException(new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK,
- "Unkown file format!", null));
+ try {
+ CasIOUtils.save(mCAS, out, format);
+ } catch (IOException e) {
+ throwCoreException(e);
}
}
-
+
public static CAS getVirginCAS(IFile typeSystemFile) throws CoreException {
ResourceSpecifierFactory resourceSpecifierFactory = UIMAFramework.getResourceSpecifierFactory();
@@ -356,8 +282,8 @@ public class DocumentUimaImpl extends Ab
return null;
}
- XMLInputSource xmlTypeSystemSource = new XMLInputSource(inTypeSystem, extensionTypeSystemFile
- .getLocation().toFile());
+ XMLInputSource xmlTypeSystemSource = new XMLInputSource(inTypeSystem,
+ extensionTypeSystemFile.getLocation().toFile());
XMLParser xmlParser = UIMAFramework.getXMLParser();
@@ -366,9 +292,19 @@ public class DocumentUimaImpl extends Ab
try {
typeSystemDesciptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
- ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
- String dataPath = typeSystemFile.getProject().getPersistentProperty((new QualifiedName("", "CDEdataPath")));
- if(dataPath != null) {
+ IProject project = typeSystemFile.getProject();
+ ClassLoader classLoader = getProjectClassLoader(project);
+
+ ResourceManager resourceManager = null;
+ if(classLoader != null) {
+ resourceManager = new ResourceManager_impl(classLoader);
+ } else {
+ resourceManager = UIMAFramework.newDefaultResourceManager();
+ }
+
+ String dataPath = project
+ .getPersistentProperty((new QualifiedName("", "CDEdataPath")));
+ if (dataPath != null) {
resourceManager.setDataPath(dataPath);
}
typeSystemDesciptor.resolveImports(resourceManager);
@@ -402,5 +338,24 @@ public class DocumentUimaImpl extends Ab
return cas;
}
+ public static ClassLoader getProjectClassLoader(IProject project) throws CoreException {
+ IProjectNature javaNature = project.getNature(JAVA_NATURE);
+ if (javaNature != null) {
+ JavaProject javaProject = (JavaProject) JavaCore.create(project);
+
+ String[] runtimeClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
+ List<URL> urls = new ArrayList<>();
+ for (int i = 0; i < runtimeClassPath.length; i++) {
+ String cp = runtimeClassPath[i];
+ try {
+ urls.add(Paths.get(cp).toUri().toURL());
+ } catch (MalformedURLException e) {
+ CasEditorPlugin.log(e);
+ }
+ }
+ return new URLClassLoader(urls.toArray(new URL[0]));
+ }
+ return null;
+ }
}