You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2016/07/18 13:10:57 UTC
svn commit: r1753217 - in /uima/uimaj/trunk:
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-editor/src/main/java/org/apache/uima/caseditor/e...
Author: pkluegl
Date: Mon Jul 18 13:10:56 2016
New Revision: 1753217
URL: http://svn.apache.org/viewvc?rev=1753217&view=rev
Log:
UIMA-4685
- use CasIOUtils in CAS Editor
Removed:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentFormat.java
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java
uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.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-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java?rev=1753217&r1=1753216&r2=1753217&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java Mon Jul 18 13:10:56 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);
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java?rev=1753217&r1=1753216&r2=1753217&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/DocumentImportStructureProvider.java Mon Jul 18 13:10:56 2016
@@ -35,123 +35,125 @@ 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.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.SerializationFormat;
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 SerializationFormat casFormat;
+
/**
* Constructs a new DocumentImportStructureProvider object.
*
* @param containerFullPath
*/
public DocumentImportStructureProvider(String language, String importEncoding,
- DocumentFormat casFormat) {
+ SerializationFormat 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,
+ SerializationFormat 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);
}
+ // 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);
+ // }
+
return new ByteArrayInputStream(out.toByteArray());
}
@@ -197,8 +199,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 +253,17 @@ 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";
+ if (SerializationFormat.XMI.equals(casFormat)) {
+ ending = "xmi";
+ } else if (SerializationFormat.XCAS.equals(casFormat)) {
+ ending = "xcas";
+ } else {
+ ending = "bcas";
}
- else {
- throw new IllegalStateException("Unkown DocumentFormat!");
- }
-
- return nameWithouEnding + "." + ending;
+
+ return nameWithouEnding + "." + ending;
} else {
return fileName;
}
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java?rev=1753217&r1=1753216&r2=1753217&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/wizards/ImportDocumentWizardPage.java Mon Jul 18 13:10:56 2016
@@ -31,9 +31,9 @@ import java.util.List;
import java.util.Set;
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.apache.uima.util.SerializationFormat;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -97,7 +97,7 @@ final class ImportDocumentWizardPage ext
private String language;
- private DocumentFormat documentFormat;
+ private SerializationFormat 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;
+ SerializationFormat[] values = SerializationFormat.values();
+ String[] stringValues = new String[values.length];
+ for (int i = 0; i < values.length; i++) {
+ stringValues[i] = values[i].toString();
+ }
+ casFormatCombo.setItems(stringValues);
+ documentFormat = SerializationFormat.XMI;
casFormatCombo.select(0);
casFormatCombo.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
- documentFormat = DocumentFormat.valueOf(casFormatCombo.getText());
+ documentFormat = SerializationFormat.valueOf(casFormatCombo.getText());
}
public void widgetDefaultSelected(SelectionEvent e) {
@@ -477,7 +482,7 @@ final class ImportDocumentWizardPage ext
return language;
}
- DocumentFormat getCasFormat() {
+ SerializationFormat getCasFormat() {
return documentFormat;
}
}
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=1753217&r1=1753216&r2=1753217&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 Mon Jul 18 13:10:56 2016
@@ -19,17 +19,15 @@
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.util.Collection;
import java.util.LinkedList;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
import org.apache.uima.ResourceSpecifierFactory;
import org.apache.uima.UIMAFramework;
import org.apache.uima.cas.CAS;
@@ -38,10 +36,6 @@ import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.FeatureStructure;
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;
@@ -52,61 +46,47 @@ import org.apache.uima.resource.metadata
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.SerializationFormat;
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.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.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;
-
private CAS mCAS;
- private final DocumentFormat format;
+ private SerializationFormat format = SerializationFormat.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 +98,7 @@ public class DocumentUimaImpl extends Ab
public String getTypeSystemText() {
return typeSystemText;
}
-
-
+
/**
* Internally removes an annotation from the {@link CAS}.
*
@@ -128,22 +107,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 +185,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 +220,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, 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 +249,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 +269,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();
@@ -367,8 +280,9 @@ public class DocumentUimaImpl extends Ab
typeSystemDesciptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
- String dataPath = typeSystemFile.getProject().getPersistentProperty((new QualifiedName("", "CDEdataPath")));
- if(dataPath != null) {
+ String dataPath = typeSystemFile.getProject()
+ .getPersistentProperty((new QualifiedName("", "CDEdataPath")));
+ if (dataPath != null) {
resourceManager.setDataPath(dataPath);
}
typeSystemDesciptor.resolveImports(resourceManager);
@@ -402,5 +316,6 @@ public class DocumentUimaImpl extends Ab
return cas;
}
+
}