public class ManifestElement extends Object
String
value. The String
value may be split up into component values each
separated by a semi-colon (';'). A manifest element may optionally have a set of
attribute and directive values associated with it. The general syntax of a manifest element is as follows:
ManifestElement ::= component (';' component)* (';' parameter)* component ::= ([^;,:="\#x0D#x0A#x00])+ | quoted-string quoted-string::= '"' ( [^"\#x0D#x0A#x00] | '\"'| '\\')* '"' parameter ::= directive | attribute directive ::= token ':=' argument attribute ::= token '=' argument argument ::= extended | quoted-string token ::= ( alphanum | '_' | '-' )+ extended ::= ( alphanum | '_' | '-' | '.' )+
For example, the following is an example of a manifest element to the Export-Package header:
org.osgi.framework; specification-version="1.2"; another-attr="examplevalue"
This manifest element has a value of org.osgi.framework and it has two attributes, specification-version and another-attr.
The following manifest element is an example of a manifest element that has multiple components to its value:
code1.jar;code2.jar;code3.jar;attr1=value1;attr2=value2;attr3=value3
This manifest element has a value of code1.jar;code2.jar;code3.jar. This is an example of a multiple component value. This value has three components: code1.jar, code2.jar, and code3.jar.
If components contain delimiter characters (e.g ';', ',' ':' "=") then it must be a quoted string. For example, the following is an example of a manifest element that has multiple components containing delimiter characters:
"component ; 1"; "component , 2"; "component : 3"; attr1=value1; attr2=value2; attr3=value3
This manifest element has a value of "component ; 1"; "component , 2"; "component : 3". This value has three components: "component ; 1", "component , 2", "component : 3".
This class is not intended to be subclassed by clients.
Modifier and Type | Method and Description |
---|---|
static String[] |
getArrayFromList(String stringList)
Returns the result of converting a list of comma-separated tokens into an array.
|
static String[] |
getArrayFromList(String stringList,
String separator)
Returns the result of converting a list of tokens into an array.
|
String |
getAttribute(String key)
Returns the value for the specified attribute or
null if it does
not exist. |
String[] |
getAttributes(String key)
Returns an array of values for the specified attribute or
null if the attribute does not exist. |
String |
getDirective(String key)
Returns the value for the specified directive or
null if it
does not exist. |
Enumeration<String> |
getDirectiveKeys()
Return an enumeration of directive keys for this manifest element or
null if there are none. |
String[] |
getDirectives(String key)
Returns an array of string values for the specified directives or
null if it does not exist. |
Enumeration<String> |
getKeys()
Returns an enumeration of attribute keys for this manifest element or
null if none exist. |
String |
getValue()
Returns the value of the manifest element.
|
String[] |
getValueComponents()
Returns the value components of the manifest element.
|
static Map<String,String> |
parseBundleManifest(InputStream manifest,
Map<String,String> headers)
Parses a bundle manifest and puts the header/value pairs into the supplied Map.
|
static ManifestElement[] |
parseHeader(String header,
String value)
Parses a manifest header value into an array of ManifestElements.
|
String |
toString() |
public String getValue()
test1.jar;test2.jar;test3.jar;selection-filter="(os.name=Windows XP)"
This manifest element has a value of test1.jar;test2.jar;test3.jar
public String[] getValueComponents()
test1.jar;test2.jar;test3.jar;selection-filter="(os.name=Windows XP)"
This manifest element has the value components array { "test1.jar", "test2.jar", "test3.jar" } Each value component is delemited by a semi-colon (';').
public String getAttribute(String key)
null
if it does
not exist. If the attribute has multiple values specified then the last value
specified is returned. For example the following manifest element:
elementvalue; myattr="value1"; myattr="value2"
specifies two values for the attribute key myattr. In this case value2 will be returned because it is the last value specified for the attribute myattr.
key
- the attribute key to return the value fornull
public String[] getAttributes(String key)
null
if the attribute does not exist.key
- the attribute key to return the values fornull
getAttribute(String)
public Enumeration<String> getKeys()
null
if none exist.public String getDirective(String key)
null
if it
does not exist. If the directive has multiple values specified then the
last value specified is returned. For example the following manifest element:
elementvalue; mydir:="value1"; mydir:="value2"
specifies two values for the directive key mydir. In this case value2 will be returned because it is the last value specified for the directive mydir.
key
- the directive key to return the value fornull
public String[] getDirectives(String key)
null
if it does not exist.key
- the directive key to return the values fornull
getDirective(String)
public Enumeration<String> getDirectiveKeys()
null
if there are none.null
public static ManifestElement[] parseHeader(String header, String value) throws BundleException
header
- the header name to parse. This is only specified to provide error messages
when the header value is invalid.value
- the header value to parse.BundleException
- if the header value is invalidpublic static String[] getArrayFromList(String stringList)
stringList
- the initial comma-separated stringnull
if there are nonepublic static String[] getArrayFromList(String stringList, String separator)
stringList
- the initial string listseparator
- the separator to use to split the list into tokens.public static Map<String,String> parseBundleManifest(InputStream manifest, Map<String,String> headers) throws IOException, BundleException
The supplied input stream is consumed by this method and will be closed. If the supplied Map is null then a Map is created to put the header/value pairs into.
manifest
- an input stream for a bundle manifest.headers
- a map used to put the header/value pairs from the bundle manifest. This value may be null.BundleException
- if the manifest has an invalid syntaxIOException
- if an error occurs while reading the manifestCopyright © 2007–2018 The Apache Software Foundation. All rights reserved.