Esempio n. 1
0
  private void addEadLevel(
      XMLStreamWriter sw,
      int num,
      DocumentaryUnit subUnit,
      Optional<Description> priorDescOpt,
      String langCode) {
    logger.trace("Adding EAD sublevel: c" + num);
    Optional<Description> descOpt =
        LanguageHelpers.getBestDescription(subUnit, priorDescOpt, langCode);
    String levelTag = String.format("c%02d", num);
    tag(
        sw,
        levelTag,
        getLevelAttrs(descOpt, null),
        () -> {
          descOpt.ifPresent(
              desc -> {
                addDataSection(sw, null, subUnit, desc, langCode);
                addPropertyValues(sw, desc);
                addControlAccess(sw, desc);
              });

          for (DocumentaryUnit child : getOrderedChildren(subUnit)) {
            addEadLevel(sw, num + 1, child, descOpt, langCode);
          }
        });
  }
Esempio n. 2
0
 private void addProfileDesc(XMLStreamWriter sw, Description desc) {
   tag(
       sw,
       "profiledesc",
       () -> {
         tag(
             sw,
             "creation",
             () -> {
               characters(sw, resourceAsString("export-boilerplate.txt"));
               DateTime now = DateTime.now();
               tag(sw, "date", now.toString(), attrs("normal", unitDateNormalFormat.print(now)));
             });
         tag(
             sw,
             "langusage",
             () ->
                 tag(
                     sw,
                     "language",
                     LanguageHelpers.codeToName(desc.getLanguageOfDescription()),
                     attrs("langcode", desc.getLanguageOfDescription())));
         Optional.ofNullable(desc.<String>getProperty(IsadG.rulesAndConventions))
             .ifPresent(value -> tag(sw, "descrules", value, attrs("encodinganalog", "3.7.2")));
       });
 }
Esempio n. 3
0
 private void addFileDesc(
     XMLStreamWriter sw, String langCode, Repository repository, Description desc) {
   tag(
       sw,
       "filedesc",
       () -> {
         tag(sw, "titlestmt", () -> tag(sw, "titleproper", desc.getName()));
         tag(
             sw,
             "publicationstmt",
             () -> {
               LanguageHelpers.getBestDescription(repository, Optional.empty(), langCode)
                   .ifPresent(
                       repoDesc -> {
                         tag(sw, "publisher", repoDesc.getName());
                         for (Address address :
                             repoDesc.as(RepositoryDescription.class).getAddresses()) {
                           tag(
                               sw,
                               "address",
                               () -> {
                                 for (ContactInfo key : addressKeys) {
                                   for (Object v : coerceList(address.getProperty(key))) {
                                     tag(sw, "addressline", v.toString());
                                   }
                                 }
                                 tag(
                                     sw,
                                     "addressline",
                                     LanguageHelpers.countryCodeToName(
                                         repository.getCountry().getId()));
                               });
                         }
                       });
             });
         if (Description.CreationProcess.IMPORT.equals(desc.getCreationProcess())) {
           tag(
               sw,
               ImmutableList.of("notestmt", "note", "p"),
               resourceAsString("creationprocess-boilerplate.txt"));
         }
       });
 }
Esempio n. 4
0
  private void addDataSection(
      XMLStreamWriter sw,
      Repository repository,
      DocumentaryUnit subUnit,
      Description desc,
      String langCode) {
    tag(
        sw,
        "did",
        () -> {
          tag(sw, "unitid", subUnit.getIdentifier());
          tag(sw, "unittitle", desc.getName(), attrs("encodinganalog", "3.1.2"));

          for (DatePeriod datePeriod : desc.as(DocumentaryUnitDescription.class).getDatePeriods()) {
            if (DatePeriod.DatePeriodType.creation.equals(datePeriod.getDateType())) {
              String start = datePeriod.getStartDate();
              String end = datePeriod.getEndDate();
              if (start != null && end != null) {
                DateTime startDateTime = new DateTime(start);
                DateTime endDateTime = new DateTime(end);
                String normal =
                    String.format(
                        "%s/%s",
                        unitDateNormalFormat.print(startDateTime),
                        unitDateNormalFormat.print(endDateTime));
                String text =
                    String.format("%s/%s", startDateTime.year().get(), endDateTime.year().get());
                tag(sw, "unitdate", text, attrs("normal", normal, "encodinganalog", "3.1.3"));
              } else if (start != null) {
                DateTime startDateTime = new DateTime(start);
                String normal = String.format("%s", unitDateNormalFormat.print(startDateTime));
                String text = String.format("%s", startDateTime.year().get());
                tag(sw, "unitdate", text, attrs("normal", normal, "encodinganalog", "3.1.3"));
              }
            }
          }

          Set<String> propertyKeys = desc.getPropertyKeys();
          for (Map.Entry<IsadG, String> pair : textDidMappings.entrySet()) {
            if (propertyKeys.contains(pair.getKey().name())) {
              for (Object v : coerceList(desc.getProperty(pair.getKey()))) {
                tag(sw, pair.getValue(), v.toString(), textFieldAttrs(pair.getKey()));
              }
            }
          }

          if (propertyKeys.contains(IsadG.languageOfMaterial.name())) {
            tag(
                sw,
                "langmaterial",
                () -> {
                  for (Object v : coerceList(desc.getProperty(IsadG.languageOfMaterial))) {
                    String langName = LanguageHelpers.codeToName(v.toString());
                    if (v.toString().length() != 3) {
                      tag(sw, "language", langName, textFieldAttrs(IsadG.languageOfMaterial));
                    } else {
                      tag(
                          sw,
                          "language",
                          langName,
                          textFieldAttrs(IsadG.languageOfMaterial, "langcode", v.toString()));
                    }
                  }
                });
          }

          Optional.ofNullable(repository)
              .ifPresent(
                  repo -> {
                    LanguageHelpers.getBestDescription(repo, Optional.empty(), langCode)
                        .ifPresent(
                            repoDesc ->
                                tag(
                                    sw,
                                    "repository",
                                    () -> tag(sw, "corpname", repoDesc.getName())));
                  });
        });
  }
Esempio n. 5
0
  @Override
  public void export(XMLStreamWriter sw, DocumentaryUnit unit, String langCode) {

    root(
        sw,
        "ead",
        DEFAULT_NAMESPACE,
        attrs(),
        NAMESPACES,
        () -> {
          attribute(
              sw,
              "http://www.w3.org/2001/XMLSchema-instance",
              "schemaLocation",
              DEFAULT_NAMESPACE + " http://www.loc.gov/ead/ead.xsd");

          Repository repository = unit.getRepository();
          Optional<Description> descOpt =
              LanguageHelpers.getBestDescription(unit, Optional.empty(), langCode);

          tag(
              sw,
              "eadheader",
              attrs(
                  "relatedencoding",
                  "DC",
                  "scriptencoding",
                  "iso15924",
                  "repositoryencoding",
                  "iso15511",
                  "dateencoding",
                  "iso8601",
                  "countryencoding",
                  "iso3166-1"),
              () -> {
                tag(sw, "eadid", unit.getId());
                descOpt.ifPresent(
                    desc -> {
                      addFileDesc(sw, langCode, repository, desc);
                      addProfileDesc(sw, desc);
                    });
                addRevisionDesc(sw, unit);
              });

          descOpt.ifPresent(
              desc -> {
                tag(
                    sw,
                    "archdesc",
                    getLevelAttrs(descOpt, "collection"),
                    () -> {
                      addDataSection(sw, repository, unit, desc, langCode);
                      addPropertyValues(sw, desc);
                      Iterable<DocumentaryUnit> orderedChildren = getOrderedChildren(unit);
                      if (orderedChildren.iterator().hasNext()) {
                        tag(
                            sw,
                            "dsc",
                            () -> {
                              for (DocumentaryUnit child : orderedChildren) {
                                addEadLevel(sw, 1, child, descOpt, langCode);
                              }
                            });
                      }
                      addControlAccess(sw, desc);
                    });
              });
        });
  }