- java.lang.Object
-
- org.arakhne.afc.inputoutput.xml.XMLResources
-
- All Implemented Interfaces:
Comparator<Object>
public class XMLResources extends Object implements Comparator<Object>
Class that store a collection of resources (URL, files and raw data) and their associated identifiers within a XML file. An object of this type may be used as a repository of resources that are defined within an XML file.MIME types are string and not
MimeNamebecause this enumeration does not exhaustively contains all the MIME types on the World. Use a string is more generic in this case.- Since:
- 15.0
- Version:
- 17.0 2020-01-04 14:41:40
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- inputoutput
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classXMLResources.EntryEntry in a XMLResourceClassifier.
-
Field Summary
Fields Modifier and Type Field Description static StringIDENTIFIER_PREFIXPrefix used to create string-representation of an identifier.
-
Constructor Summary
Constructors Constructor Description XMLResources(PathBuilder pathBuilder)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringadd(byte[] rawData)Add the given embedded data into this classifier and replies the string representation of the given embedded data.Stringadd(byte[] rawData, String mimeType)Add the given embedded data into this classifier and replies the string representation of the given embedded data.Stringadd(long identifier, byte[] rawData, String mimeType)Add a embedded data in the classifier.Stringadd(long identifier, File file, String mimeType)Add a file in the classifier.Stringadd(long identifier, URL url, String mimeType)Add an URL in the classifier.Stringadd(File file)Add the given file into this classifier and replies the string representation of the given file.Stringadd(File file, String mimeType)Add the given File into this classifier and replies the string representation of the given file.Stringadd(URL url)Add the given URL into this classifier and replies the string representation of the given URL.Stringadd(URL url, String mimeType)Add the given URL into this classifier and replies the string representation of the given URL.voidclear()Clear all the register file and URL.intcompare(Object o1, Object o2)longcomputeNextIdentifier()Compute the next available identifier for a resource.longgetIdentifier(byte[] rawData)Replies the identifier of the given embedded data.longgetIdentifier(File file)Replies the identifier of the given file.longgetIdentifier(URL url)Replies the identifier of the given url.protected LonggetIdentifierFromResource(Object resource)Replies the identifier that is corresponding to the given URL.static longgetNumericalIdentifier(String identifier)Replies the numerical identifier for the given string-identifier.Map<Long,XMLResources.Entry>getPairs()Replies the content of this classifier.XMLResources.EntrygetResource(long identifier)Replies the resource.protected XMLResources.EntrygetResourceFromIdentifier(long id)Replies the identifier that is corresponding to the given URL.URLgetResourceURL(long identifier)Replies the resource URL.static StringgetStringIdentifier(long identifier)Replies a string-representation of the given identifier.static booleanisStringIdentifier(String str)Replies if the given string is a string-representation of a resource identifier.voidremove(byte[] rawData)Remove the given embedded data from this classifier.voidremove(long identifier)Remove the resource with the given identifier.voidremove(File file)Remove the given file from this classifier.voidremove(URL url)Remove the given url from this classifier.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Field Detail
-
IDENTIFIER_PREFIX
public static final String IDENTIFIER_PREFIX
Prefix used to create string-representation of an identifier.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMLResources
public XMLResources(PathBuilder pathBuilder)
Constructor.- Parameters:
pathBuilder- is the path builder to use to build the paths of the resources in order to compare the them.
-
-
Method Detail
-
compare
@Pure public int compare(Object o1, Object o2)
- Specified by:
comparein interfaceComparator<Object>
-
getStringIdentifier
@Pure public static String getStringIdentifier(long identifier)
Replies a string-representation of the given identifier.The function add the prefix
IDENTIFIER_PREFIXto the string representation of the given identifier.- Parameters:
identifier- the identifier to convert.- Returns:
- the string-representation of the given identifier.
- See Also:
getNumericalIdentifier(String),isStringIdentifier(String)
-
isStringIdentifier
@Pure public static boolean isStringIdentifier(String str)
Replies if the given string is a string-representation of a resource identifier.A string is an identifier if it starts with
IDENTIFIER_PREFIX.- Parameters:
str- the string to test.- Returns:
trueif the given string is the string-representation of an identifier; otherwisefalse.- See Also:
getNumericalIdentifier(String),getStringIdentifier(long)
-
getNumericalIdentifier
@Pure public static long getNumericalIdentifier(String identifier)
Replies the numerical identifier for the given string-identifier.- Parameters:
identifier- the identifier to convert.- Returns:
- the numerical-representation of the given identifier.
- See Also:
getStringIdentifier(long),isStringIdentifier(String)
-
add
public String add(long identifier, URL url, String mimeType)
Add an URL in the classifier.- Parameters:
identifier- the identifier of the URL.url- the value of the URL.mimeType- may benull- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
-
add
public String add(long identifier, File file, String mimeType)
Add a file in the classifier.- Parameters:
identifier- the identifier of the file.file- the name of the file.mimeType- may benull- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
-
add
public String add(long identifier, byte[] rawData, String mimeType)
Add a embedded data in the classifier.- Parameters:
identifier- the identifier of the data.rawData- the value of the data.mimeType- may benull- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
-
add
public final String add(URL url) throws IOException
Add the given URL into this classifier and replies the string representation of the given URL. Try to simplify the given URL with the path builder and to use a reference registered through the file classifier.- Parameters:
url- is the URL to treat.- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
- Throws:
IOException- in case of error.
-
add
public final String add(URL url, String mimeType) throws IOException
Add the given URL into this classifier and replies the string representation of the given URL. Try to simplify the given URL with the path builder and to use a reference registered through the file classifier.- Parameters:
url- is the URL to treat.mimeType- is the mime type associated to the file.- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
- Throws:
IOException- in case of error.
-
add
public final String add(File file) throws IOException
Add the given file into this classifier and replies the string representation of the given file. Try to simplify the given file with the path builder and to use a reference registered through the file classifier.- Parameters:
file- is the file to treat.- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
- Throws:
IOException- in case of error.
-
add
public final String add(File file, String mimeType) throws IOException
Add the given File into this classifier and replies the string representation of the given file. Try to simplify the given file with the path builder and to use a reference registered through the file classifier.- Parameters:
file- is the file to treat.mimeType- is the mime type associated to the file.- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
- Throws:
IOException- in case of error.
-
add
public final String add(byte[] rawData) throws IOException
Add the given embedded data into this classifier and replies the string representation of the given embedded data.- Parameters:
rawData- is the embedded data to treat.- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
- Throws:
IOException- in case of error.
-
add
public final String add(byte[] rawData, String mimeType) throws IOException
Add the given embedded data into this classifier and replies the string representation of the given embedded data.- Parameters:
rawData- is the embedded data to treat.mimeType- is the mime type associated to the embedded data.- Returns:
- the string representation, basically the reference to the resource given by the file classifier.
- Throws:
IOException- in case of error.
-
computeNextIdentifier
public long computeNextIdentifier()
Compute the next available identifier for a resource.- Returns:
- an identifier for a resource.
-
getIdentifierFromResource
@Pure protected Long getIdentifierFromResource(Object resource)
Replies the identifier that is corresponding to the given URL.- Parameters:
resource- is the resource to search for.- Returns:
- the identifier; or
nullif not found.
-
getResourceFromIdentifier
@Pure protected XMLResources.Entry getResourceFromIdentifier(long id)
Replies the identifier that is corresponding to the given URL.- Parameters:
id- is the identifier to search for.- Returns:
- the resource; or
nullif not found.
-
getIdentifier
@Pure public final long getIdentifier(URL url)
Replies the identifier of the given url.- Parameters:
url- the url to search for.- Returns:
- the identifier or
-1if the url was not found.
-
getIdentifier
@Pure public final long getIdentifier(File file)
Replies the identifier of the given file.- Parameters:
file- the file to search for.- Returns:
- the identifier or
-1if the file was not found.
-
getIdentifier
@Pure public final long getIdentifier(byte[] rawData)
Replies the identifier of the given embedded data.- Parameters:
rawData- the data to search for.- Returns:
- the identifier or
-1if the data was not found.
-
getResourceURL
@Pure public final URL getResourceURL(long identifier)
Replies the resource URL.- Parameters:
identifier- the identifier to search for.- Returns:
- the URL or
null
-
getResource
@Pure public final XMLResources.Entry getResource(long identifier)
Replies the resource.- Parameters:
identifier- the identifier to search for.- Returns:
- the URL or
null
-
remove
public void remove(URL url)
Remove the given url from this classifier.- Parameters:
url- the url to remove.
-
remove
public void remove(File file)
Remove the given file from this classifier.- Parameters:
file- the file to remove.
-
remove
public void remove(byte[] rawData)
Remove the given embedded data from this classifier.- Parameters:
rawData- the data to remove.
-
remove
public void remove(long identifier)
Remove the resource with the given identifier.- Parameters:
identifier- the identifier to remove.
-
getPairs
@Pure public Map<Long,XMLResources.Entry> getPairs()
Replies the content of this classifier.- Returns:
- the resource-identifier pairs.
-
clear
public void clear()
Clear all the register file and URL.
-
-