public void save()

in ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java [643:749]


  public void save() {
    AnnotationCheckTreeNode root = (AnnotationCheckTreeNode) treeView.getInput();
    AnnotationCheckTreeNode[] children = root.getChildren();
    List<CheckDocument> docs = new ArrayList<CheckDocument>(oldDocs);
    TypeSystemDescription tsd = getTypeSystemDescription();
    CAS casSource = null;
    CAS cas = null;
    try {
      cas = CasCreationUtils.createCas(tsd, null, new FsIndexDescription[0]);
      casSource = CasCreationUtils.createCas(tsd, null, new FsIndexDescription[0]);
    } catch (ResourceInitializationException e) {
      RutaAddonsPlugin.error(e);
    }
    String goldFolderLocation = documentSink.getText();
    for (AnnotationCheckTreeNode each : children) {
      CheckDocument cd = (CheckDocument) each.getElement();
      if (cd.checked && cd.keep) {
        cas.reset();
        casSource.reset();
        File oldFile = new File(cd.source);
        File goldFile = new File(goldFolderLocation, oldFile.getName());

        try {
          XmiCasDeserializer.deserialize(new FileInputStream(oldFile), casSource, true);
        } catch (FileNotFoundException e) {
          RutaAddonsPlugin.error(e);
        } catch (SAXException e) {
          RutaAddonsPlugin.error(e);
        } catch (IOException e) {
          RutaAddonsPlugin.error(e);
        }

        try {
          if (goldFile.exists()) {
            XmiCasDeserializer.deserialize(new FileInputStream(goldFile), cas, false);
          } else {
            String documentText = casSource.getDocumentText();
            cas.setDocumentText(documentText);
          }
        } catch (FileNotFoundException e) {
          RutaAddonsPlugin.error(e);
        } catch (SAXException e) {
          RutaAddonsPlugin.error(e);
        } catch (IOException e) {
          RutaAddonsPlugin.error(e);
        }
        CasCopier cc = new CasCopier(casSource, cas);

        for (String uncheckedTypeName : typesToTransferUnchecked) {
          Type type = cas.getTypeSystem().getType(uncheckedTypeName);
          if (type != null) {
            for (AnnotationFS annot : casSource.getAnnotationIndex(type)) {
              FeatureStructure copyFs = cc.copyFs(annot);
              cas.addFsToIndexes(copyFs);
            }
          }
        }
        AnnotationCheckTreeNode[] annotationNodes = each.getChildren();
        for (AnnotationCheckTreeNode eachAN : annotationNodes) {
          CheckAnnotation ca = (CheckAnnotation) eachAN.getElement();
          if (ca.checked && ca.keep) {
            TypeSystem ts = casEditor.getDocument().getCAS().getTypeSystem();
            Type type = ts.getType(ca.getTypeName());
            if (type != null) {
              AnnotationFS annotFS = ca.toAnnotationFS(cas, type);
              if (eachAN.hasChildren()) {
                FeatureCheckTreeNode[] featureNodes = (FeatureCheckTreeNode[]) eachAN.getChildren();
                for (FeatureCheckTreeNode featureNode : featureNodes) {
                  Feature feature = featureNode.getFeature();
                  try {
                    annotFS.setFeatureValueFromString(feature, featureNode.getValue());
                  } catch (Exception e) {
                    continue;
                  }
                }
              }
              cas.addFsToIndexes(annotFS);
            }
          }
        }
        try {
          CheckAnnotationUtils.writeXmi(cas, goldFile);
        } catch (Exception e) {
          RutaAddonsPlugin.error(e);
        }
        cd.checkedTypes.addAll(typesToCheck.keySet());
        if (!docs.contains(cd)) {
          docs.add(cd);
        }
      }
      File dataFile = new File(goldFolderLocation, "data.xml");
      try {
        CheckDocumentXMLUtils.write(docs, dataFile);
      } catch (IOException e) {
        RutaAddonsPlugin.error(e);
      }
    }

    IPath goldPath = Path.fromOSString(goldFolderLocation);
    IContainer containerForLocation = ResourcesPlugin.getWorkspace().getRoot()
            .getContainerForLocation(goldPath);
    try {
      containerForLocation.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
    } catch (CoreException e) {
      RutaAddonsPlugin.error(e);
    }
  }