forked from Netflix/photon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicMapProfileV2MappedFileSet.java
122 lines (111 loc) · 4.62 KB
/
BasicMapProfileV2MappedFileSet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
*
* Copyright 2015 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netflix.imflibrary.st0429_9;
import com.netflix.imflibrary.IMFErrorLogger;
import com.netflix.imflibrary.IMFErrorLoggerImpl;
import com.netflix.imflibrary.exceptions.IMFException;
import com.netflix.imflibrary.utils.ErrorLogger;
import com.netflix.imflibrary.utils.FileLocator;
import org.xml.sax.SAXException;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import javax.xml.bind.JAXBException;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
/**
* This class is an immutable implementation of the Mapped File Set concept defined in Section A.1 in Annex A of st0429-9:2014.
* A BasicMapProfilev2MappedFileSet object can only be constructed if the constraints specified in Section A.1 in Annex A of st0429-9:2014 are
* satisfied
*/
@Immutable
public final class BasicMapProfileV2MappedFileSet
{
public static final String ASSETMAP_FILE_NAME = "ASSETMAP.xml";
private final AssetMap assetMap;
private final URI absoluteAssetMapURI;
private final IMFErrorLogger imfErrorLogger;
/**
* Constructor for a MappedFileSet object from a file representing the root of a directory tree
* @param rootFileLocator the directory which serves as the tree root of the Mapped File Set
* @throws IOException - forwarded from {@link AssetMap#AssetMap(FileLocator) AssetMap} constructor
*/
public BasicMapProfileV2MappedFileSet(FileLocator rootFileLocator) throws IOException
{
imfErrorLogger = new IMFErrorLoggerImpl();
if (!rootFileLocator.isDirectory())
{
String message = String.format("Root file %s corresponding to the mapped file set is not a " +
"directory", rootFileLocator.getAbsolutePath());
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR, IMFErrorLogger.IMFErrors
.ErrorLevels.FATAL,
message);
throw new IMFException(message, imfErrorLogger);
}
FilenameFilter filenameFilter = new FilenameFilter()
{
@Override
public boolean accept(File rootFile, String name)
{
return name.equals(BasicMapProfileV2MappedFileSet.ASSETMAP_FILE_NAME);
}
};
FileLocator[] files = rootFileLocator.listFiles(filenameFilter);
if ((files == null) || (files.length != 1))
{
String message = String.format("Found %d files with name %s in mapped file set rooted at %s, " +
"exactly 1 is allowed", (files == null) ? 0 : files.length, BasicMapProfileV2MappedFileSet
.ASSETMAP_FILE_NAME, rootFileLocator.getAbsolutePath());
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR, IMFErrorLogger.IMFErrors
.ErrorLevels.FATAL,
message);
throw new IMFException(message, imfErrorLogger);
}
this.assetMap = new AssetMap(files[0]);
this.absoluteAssetMapURI = files[0].toURI();
}
/**
* Getter for the {@link com.netflix.imflibrary.st0429_9.AssetMap AssetMap} object that represents the single AssetMap document
* corresponding to this Mapped File Set
* @return the AssetMap object
*/
public AssetMap getAssetMap()
{
return this.assetMap;
}
/**
* Getter for the absolute, hierarchical URI with a scheme equal to <tt>"file"</tt> URI corresponding to the {@link com.netflix.imflibrary.st0429_9.AssetMap AssetMap}
* object associated with this Mapped File Set
* @return file-based URI for the AssetMap object
*/
public URI getAbsoluteAssetMapURI()
{
return this.absoluteAssetMapURI;
}
/**
* Getter for the errors in Composition
*
* @return List of errors in Composition.
*/
public List<ErrorLogger.ErrorObject> getErrors() {
return imfErrorLogger.getErrors();
}
}