1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.document;
20
21 import java.io.File;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.util.Collections;
25
26 public class ArchiveEntryName extends DocumentName {
27
28 private final DocumentName archiveFileName;
29
30 private static DocumentName.Builder prepareBuilder(final DocumentName archiveFileName, final String archiveEntryName) {
31 String root = archiveFileName.getName() + "#";
32 FSInfo fsInfo = new FSInfo("archiveEntry", "/", true, Collections.singletonList(root));
33 return DocumentName.builder(fsInfo)
34 .setRoot(root)
35 .setBaseName(root + "/")
36 .setName(archiveEntryName);
37 }
38 public ArchiveEntryName(final DocumentName archiveFileName, final String archiveEntryName) {
39 super(prepareBuilder(archiveFileName, archiveEntryName));
40 this.archiveFileName = archiveFileName;
41 }
42
43 @Override
44 public File asFile() {
45 return archiveFileName.asFile();
46 }
47
48 @Override
49 public Path asPath() {
50 return Paths.get(archiveFileName.asPath().toString(), "#", super.asPath().toString());
51 }
52
53 @Override
54 public DocumentName resolve(final String child) {
55 return new ArchiveEntryName(this.archiveFileName, super.resolve(child).localized());
56 }
57
58 @Override
59 public String getBaseName() {
60 return archiveFileName.getName() + "#";
61 }
62
63 @Override
64 boolean startsWithRootOrSeparator(final String candidate, final String root, final String separator) {
65 return super.startsWithRootOrSeparator(candidate, root, separator);
66 }
67
68 @Override
69 public String localized(final String dirSeparator) {
70 String superLocal = super.localized(dirSeparator);
71 superLocal = superLocal.substring(superLocal.lastIndexOf("#") + 1);
72 return archiveFileName.localized(dirSeparator) + "#" + superLocal;
73 }
74 }