From 8a85ff4bcb78283848a3d4ca0ea223ee334f2f88 Mon Sep 17 00:00:00 2001 From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de> Date: Wed, 29 May 2013 16:22:11 +0000 Subject: [PATCH] Cache base name for each entry git-svn-id: https://develop.sub.uni-goettingen.de/repos/textgrid/trunk/services/aggregator@14117 7c539038-3410-0410-b1ec-0f2a7bf1c452 --- .../aggregator/tree/AggregationEntry.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java index f414387..0cfd336 100644 --- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java +++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java @@ -22,6 +22,8 @@ public class AggregationEntry { protected final Optional<Aggregation> parent; + private String baseName; + protected AggregationEntry(final ObjectType metadata) { this(metadata, null); } @@ -32,9 +34,6 @@ protected AggregationEntry(final ObjectType metadata, this.parent = Optional.fromNullable(parent); if (this.parent.isPresent()) { parent.add(this); - logger.info(MessageFormat.format("{0} has parent {1}", this, parent)); - } else { - logger.info(MessageFormat.format("{0} has no parent", this)); } } @@ -53,13 +52,14 @@ public ObjectType getMetadata() { * whether to append a content type specific extension. */ protected String getSimpleFileName(final boolean withExtension) { - final String baseName = - FilenamePolicy.getTransliterator().transliterate( - getMetadata().getGeneric().getProvided().getTitle().get(0)) - .concat(".") - .concat(URI.create( - getMetadata().getGeneric().getGenerated().getTextgridUri() - .getValue()).getSchemeSpecificPart()); + if (baseName == null) { + baseName = FilenamePolicy.getTransliterator().transliterate( + getMetadata().getGeneric().getProvided().getTitle().get(0)) + .concat(".") + .concat(URI.create( + getMetadata().getGeneric().getGenerated().getTextgridUri() + .getValue()).getSchemeSpecificPart()); + } if (withExtension) return FileExtensionMap.getInstance().addExtension(baseName, getFormat()); @@ -72,9 +72,9 @@ public String getFormat() { } public Optional<URI> getBase() { - if (getParent().isPresent()) { + if (getParent().isPresent()) return Optional.of(URI.create(getParent().get().getFileName(false).concat("/"))); - } else + else return Optional.absent(); } @@ -87,7 +87,7 @@ public Optional<URI> getBase() { * component of the path. */ protected File getFile(final boolean withExtension) { - Optional<Aggregation> parent = getParent(); + final Optional<Aggregation> parent = getParent(); if (parent.isPresent()) return new File(parent.get().getFile(false), getSimpleFileName(withExtension)); @@ -101,7 +101,7 @@ protected File getFile(final boolean withExtension) { * {@code {@linkplain #getFile(boolean) getFileName(true)}}. * @param withExtension TODO */ - public String getFileName(boolean withExtension) { + public String getFileName(final boolean withExtension) { return baseURI.relativize(getFile(withExtension).toURI()).toString(); } -- GitLab