Package ugh.fileformats.mets

Examples of ugh.fileformats.mets.MetsModsImportExport


    /* prüfen, welches Format die Metadaten haben (Mets, xstream oder rdf */
    String type = MetadatenHelper.getMetaFileType(getMetadataFilePath());
    myLogger.debug("current meta.xml file type for id " + getId() + ": " + type);
    Fileformat ff = null;
    if (type.equals("metsmods")) {
      ff = new MetsModsImportExport(this.regelsatz.getPreferences());
    } else if (type.equals("mets")) {
      ff = new MetsMods(this.regelsatz.getPreferences());
    } else if (type.equals("xstream")) {
      ff = new XStream(this.regelsatz.getPreferences());
    } else {
View Full Code Here


  public Fileformat readMetadataFile(String metadataFile, Prefs prefs) throws IOException, PreferencesException, ReadException {
    /* prüfen, welches Format die Metadaten haben (Mets, xstream oder rdf */
    String type = MetadatenHelper.getMetaFileType(metadataFile);
    Fileformat ff = null;
    if (type.equals("metsmods")) {
      ff = new MetsModsImportExport(prefs);
    } else if (type.equals("mets")) {
      ff = new MetsMods(prefs);
    } else if (type.equals("xstream")) {
      ff = new XStream(prefs);
    } else {
View Full Code Here

    try {
      gdzfile = myProzess.readMetadataFile();
      switch (MetadataFormat.findFileFormatsHelperByName(myProzess
          .getProjekt().getFileFormatDmsExport())) {
      case METS:
        newfile = new MetsModsImportExport(this.myPrefs);
        break;

      case METS_AND_RDF:
        newfile = new RDFFile(this.myPrefs);
        break;
View Full Code Here

       this.fi = new FolderInformation(process.getId(), process.getTitle());
      String metadataPath = this.fi.getMetadataFilePath();
      gdzfile = process.readMetadataFile(metadataPath, this.myPrefs);
      switch (MetadataFormat.findFileFormatsHelperByName(this.project.getFileFormatDmsExport())) {
      case METS:
        newfile = new MetsModsImportExport(this.myPrefs);
        break;

      case METS_AND_RDF:
        newfile = new RDFFile(this.myPrefs);
        break;
View Full Code Here

  protected boolean writeMetsFile(Prozess myProzess, String targetFileName, Fileformat gdzfile, boolean writeLocalFilegroup)
      throws PreferencesException, WriteException, IOException, InterruptedException, SwapException, DAOException,
      TypeNotAllowedForParentException {

    MetsModsImportExport mm = new MetsModsImportExport(this.myPrefs);
    mm.setWriteLocal(writeLocalFilegroup);
    String imageFolderPath = myProzess.getImagesDirectory();
    File imageFolder = new File(imageFolderPath);
    /*
     * before creating mets file, change relative path to absolute -
     */
    DigitalDocument dd = gdzfile.getDigitalDocument();
    if (dd.getFileSet() == null) {
      Helper.setMeldung(myProzess.getTitel() + ": digital document does not contain images; temporarily adding them for mets file creation");

      MetadatenImagesHelper mih = new MetadatenImagesHelper(this.myPrefs, dd);
      mih.createPagination(myProzess, null);
    }

    /*
     * get the topstruct element of the digital document depending on anchor property
     */
    DocStruct topElement = dd.getLogicalDocStruct();
    if (this.myPrefs.getDocStrctTypeByName(topElement.getType().getName()).isAnchor()) {
      if (topElement.getAllChildren() == null || topElement.getAllChildren().size() == 0) {
        throw new PreferencesException(myProzess.getTitel()
            + ": the topstruct element is marked as anchor, but does not have any children for physical docstrucs");
      } else {
        topElement = topElement.getAllChildren().get(0);
      }
    }

    /*
     * -------------------------------- if the top element does not have any image related, set them all --------------------------------
     */
    if (topElement.getAllToReferences("logical_physical") == null || topElement.getAllToReferences("logical_physical").size() == 0) {
      if (dd.getPhysicalDocStruct() != null && dd.getPhysicalDocStruct().getAllChildren() != null) {
        Helper.setMeldung(myProzess.getTitel()
            + ": topstruct element does not have any referenced images yet; temporarily adding them for mets file creation");
        for (DocStruct mySeitenDocStruct : dd.getPhysicalDocStruct().getAllChildren()) {
          topElement.addReferenceTo(mySeitenDocStruct, "logical_physical");
        }
      } else {
        Helper.setFehlerMeldung(myProzess.getTitel() + ": could not found any referenced images, export aborted");
        dd = null;
        return false;
      }
    }

    for (ContentFile cf : dd.getFileSet().getAllFiles()) {
      String location = cf.getLocation();
      // If the file's location string shoes no sign of any protocol,
      // use the file protocol.
      if (!location.contains("://")) {
        location = "file://" + location;
      }
      URL url = new URL(location);
      File f = new File(imageFolder, url.getFile());
      cf.setLocation(f.toURI().toString());
    }

    mm.setDigitalDocument(dd);

    /*
     * -------------------------------- wenn Filegroups definiert wurden, werden diese jetzt in die Metsstruktur übernommen
     * --------------------------------
     */
    // Replace all paths with the given VariableReplacer, also the file
    // group paths!
    VariableReplacer vp = new VariableReplacer(mm.getDigitalDocument(), this.myPrefs, myProzess, null);
    Set<ProjectFileGroup> myFilegroups = myProzess.getProjekt().getFilegroups();

    if (myFilegroups != null && myFilegroups.size() > 0) {
      for (ProjectFileGroup pfg : myFilegroups) {
        // check if source files exists
        if (pfg.getFolder() != null && pfg.getFolder().length() > 0) {
          File folder = new File(myProzess.getMethodFromName(pfg.getFolder()));
          if (folder != null && folder.exists() && folder.list().length > 0) {
            VirtualFileGroup v = new VirtualFileGroup();
            v.setName(pfg.getName());
            v.setPathToFiles(vp.replace(pfg.getPath()));
            v.setMimetype(pfg.getMimetype());
            v.setFileSuffix(pfg.getSuffix());
            mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
          }
        } else {

          VirtualFileGroup v = new VirtualFileGroup();
          v.setName(pfg.getName());
          v.setPathToFiles(vp.replace(pfg.getPath()));
          v.setMimetype(pfg.getMimetype());
          v.setFileSuffix(pfg.getSuffix());
          mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
        }
      }
    }

    // Replace rights and digiprov entries.
    mm.setRightsOwner(vp.replace(myProzess.getProjekt().getMetsRightsOwner()));
    mm.setRightsOwnerLogo(vp.replace(myProzess.getProjekt().getMetsRightsOwnerLogo()));
    mm.setRightsOwnerSiteURL(vp.replace(myProzess.getProjekt().getMetsRightsOwnerSite()));
    mm.setRightsOwnerContact(vp.replace(myProzess.getProjekt().getMetsRightsOwnerMail()));
    mm.setDigiprovPresentation(vp.replace(myProzess.getProjekt().getMetsDigiprovPresentation()));
    mm.setDigiprovReference(vp.replace(myProzess.getProjekt().getMetsDigiprovReference()));
    mm.setDigiprovPresentationAnchor(vp.replace(myProzess.getProjekt().getMetsDigiprovPresentationAnchor()));
    mm.setDigiprovReferenceAnchor(vp.replace(myProzess.getProjekt().getMetsDigiprovReferenceAnchor()));

    mm.setPurlUrl(vp.replace(myProzess.getProjekt().getMetsPurl()));
    mm.setContentIDs(vp.replace(myProzess.getProjekt().getMetsContentIDs()));

    String pointer = myProzess.getProjekt().getMetsPointerPath();
    pointer = vp.replace(pointer);
    mm.setMptrUrl(pointer);

    String anchor = myProzess.getProjekt().getMetsPointerPathAnchor();
    pointer = vp.replace(anchor);
    mm.setMptrAnchorUrl(pointer);

    // if (!ConfigMain.getParameter("ImagePrefix", "\\d{8}").equals("\\d{8}")) {
    List<String> images = new ArrayList<String>();
    if (ConfigMain.getBooleanParameter("ExportValidateImages", true)) {
      try {
        // TODO andere Dateigruppen nicht mit image Namen ersetzen
        images = new MetadatenImagesHelper(this.myPrefs, dd).getDataFiles(myProzess);
        int sizeOfPagination = dd.getPhysicalDocStruct().getAllChildren().size();
        if (images != null) {
          int sizeOfImages = images.size();
          if (sizeOfPagination == sizeOfImages) {
            dd.overrideContentFiles(images);
          } else {
            List<String> param = new ArrayList<String>();
            param.add(String.valueOf(sizeOfPagination));
            param.add(String.valueOf(sizeOfImages));
            Helper.setFehlerMeldung(Helper.getTranslation("imagePaginationError", param));
            return false;
          }
        }
      } catch (IndexOutOfBoundsException e) {
        myLogger.error(e);
        return false;
      } catch (InvalidImagesException e) {
        myLogger.error(e);
        return false;
      }
    } else {
      // create pagination out of virtual file names
      dd.addAllContentFiles();

    }
    mm.write(targetFileName);
    Helper.setMeldung(null, myProzess.getTitel() + ": ", "ExportFinished");
    return true;
  }
View Full Code Here

    Fileformat newfile;
    try {
      gdzfile = myProzess.readMetadataFile();
      switch (MetadataFormat.findFileFormatsHelperByName(myProzess.getProjekt().getFileFormatDmsExport())) {
      case METS:
        newfile = new MetsModsImportExport(this.myPrefs);
        break;

      case METS_AND_RDF:
        newfile = new RDFFile(this.myPrefs);
        break;
View Full Code Here

      throws PreferencesException, WriteException, IOException, InterruptedException, SwapException, DAOException,
      TypeNotAllowedForParentException {
    this.fi = new FolderInformation(process.getId(), process.getTitle());
    this.myPrefs = ProcessManager.getRuleset(process.getRulesetId()).getPreferences();
    this.project = ProjectManager.getProjectById(process.getProjekteID());
    MetsModsImportExport mm = new MetsModsImportExport(this.myPrefs);
    mm.setWriteLocal(writeLocalFilegroup);
    String imageFolderPath = this.fi.getImagesDirectory();
    File imageFolder = new File(imageFolderPath);
    /*
     * before creating mets file, change relative path to absolute -
     */
    DigitalDocument dd = gdzfile.getDigitalDocument();
    if (dd.getFileSet() == null) {
      Helper.setFehlerMeldung(process.getTitle() + ": digital document does not contain images; aborting");
      return false;
    }

    /*
     * get the topstruct element of the digital document depending on anchor property
     */
    DocStruct topElement = dd.getLogicalDocStruct();
    if (this.myPrefs.getDocStrctTypeByName(topElement.getType().getName()).isAnchor()) {
      if (topElement.getAllChildren() == null || topElement.getAllChildren().size() == 0) {
        throw new PreferencesException(process.getTitle()
            + ": the topstruct element is marked as anchor, but does not have any children for physical docstrucs");
      } else {
        topElement = topElement.getAllChildren().get(0);
      }
    }

    /*
     * -------------------------------- if the top element does not have any image related, set them all --------------------------------
     */
    if (topElement.getAllToReferences("logical_physical") == null || topElement.getAllToReferences("logical_physical").size() == 0) {
      if (dd.getPhysicalDocStruct() != null && dd.getPhysicalDocStruct().getAllChildren() != null) {
        Helper.setMeldung(process.getTitle()
            + ": topstruct element does not have any referenced images yet; temporarily adding them for mets file creation");
        for (DocStruct mySeitenDocStruct : dd.getPhysicalDocStruct().getAllChildren()) {
          topElement.addReferenceTo(mySeitenDocStruct, "logical_physical");
        }
      } else {
        Helper.setFehlerMeldung(process.getTitle() + ": could not found any referenced images, export aborted");
        dd = null;
        return false;
      }
    }

    if (dd != null) {
      for (ContentFile cf : dd.getFileSet().getAllFiles()) {
        String location = cf.getLocation();
        // If the file's location string shoes no sign of any protocol,
        // use the file protocol.
        if (!location.contains("://")) {
          location = "file://" + location;
        }
        URL url = new URL(location);
        File f = new File(imageFolder, url.getFile());
        cf.setLocation(f.toURI().toString());
      }

      mm.setDigitalDocument(dd);

      /*
       * -------------------------------- wenn Filegroups definiert wurden, werden diese jetzt in die Metsstruktur übernommen
       * --------------------------------
       */
      // Replace all paths with the given VariableReplacer, also the file
      // group paths!
      VariableReplacerWithoutHibernate vp = new VariableReplacerWithoutHibernate(mm.getDigitalDocument(), this.myPrefs, process, null);
      List<ProjectFileGroup> myFilegroups = ProjectManager.getFilegroupsForProjectId(this.project.getId());

      if (myFilegroups != null && myFilegroups.size() > 0) {
        for (ProjectFileGroup pfg : myFilegroups) {
          // check if source files exists
          if (pfg.getFolder() != null && pfg.getFolder().length() > 0) {
            File folder = new File(this.fi.getMethodFromName(pfg.getFolder()));
            if (folder != null && folder.exists() && folder.list().length > 0) {
              VirtualFileGroup v = new VirtualFileGroup();
              v.setName(pfg.getName());
              v.setPathToFiles(vp.replace(pfg.getPath()));
              v.setMimetype(pfg.getMimetype());
              v.setFileSuffix(pfg.getSuffix());
              mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
            }
          } else {

            VirtualFileGroup v = new VirtualFileGroup();
            v.setName(pfg.getName());
            v.setPathToFiles(vp.replace(pfg.getPath()));
            v.setMimetype(pfg.getMimetype());
            v.setFileSuffix(pfg.getSuffix());
            mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
          }
        }
      }

      // Replace rights and digiprov entries.
      mm.setRightsOwner(vp.replace(this.project.getMetsRightsOwner()));
      mm.setRightsOwnerLogo(vp.replace(this.project.getMetsRightsOwnerLogo()));
      mm.setRightsOwnerSiteURL(vp.replace(this.project.getMetsRightsOwnerSite()));
      mm.setRightsOwnerContact(vp.replace(this.project.getMetsRightsOwnerMail()));
      mm.setDigiprovPresentation(vp.replace(this.project.getMetsDigiprovPresentation()));
      mm.setDigiprovReference(vp.replace(this.project.getMetsDigiprovReference()));
      mm.setDigiprovPresentationAnchor(vp.replace(this.project.getMetsDigiprovPresentationAnchor()));
      mm.setDigiprovReferenceAnchor(vp.replace(this.project.getMetsDigiprovReferenceAnchor()));

      mm.setPurlUrl(vp.replace(this.project.getMetsPurl()));
      mm.setContentIDs(vp.replace(this.project.getMetsContentIDs()));

      String pointer = this.project.getMetsPointerPath();
      pointer = vp.replace(pointer);
      mm.setMptrUrl(pointer);

      String anchor = this.project.getMetsPointerPathAnchor();
      pointer = vp.replace(anchor);
      mm.setMptrAnchorUrl(pointer);

      List<String> images = new ArrayList<String>();
      try {
        // TODO andere Dateigruppen nicht mit image Namen ersetzen
        images = this.fi.getDataFiles();
        if (images != null) {
          int sizeOfPagination = dd.getPhysicalDocStruct().getAllChildren().size();
          int sizeOfImages = images.size();
          if (sizeOfPagination == sizeOfImages) {
            dd.overrideContentFiles(images);
          } else {
            List<String> param = new ArrayList<String>();
            param.add(String.valueOf(sizeOfPagination));
            param.add(String.valueOf(sizeOfImages));
            Helper.setFehlerMeldung(Helper.getTranslation("imagePaginationError", param));
            return false;
          }
        }
      } catch (IndexOutOfBoundsException e) {

        myLogger.error(e);
      } catch (InvalidImagesException e) {
        myLogger.error(e);
      }
      mm.write(targetFileName);
      Helper.setMeldung(null, process.getTitle() + ": ", "ExportFinished");
    }
    return true;
  }
View Full Code Here

TOP

Related Classes of ugh.fileformats.mets.MetsModsImportExport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.