Class ManifestElement
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.
- Since:
- 3.0
- Restriction:
- This class is not intended to be subclassed by clients.
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.getAttribute
(String key) Returns the value for the specified attribute ornull
if it does not exist.String[]
getAttributes
(String key) Returns an array of values for the specified attribute ornull
if the attribute does not exist.getDirective
(String key) Returns the value for the specified directive ornull
if it does not exist.Return an enumeration of directive keys for this manifest element ornull
if there are none.String[]
getDirectives
(String key) Returns an array of string values for the specified directives ornull
if it does not exist.getKeys()
Returns an enumeration of attribute keys for this manifest element ornull
if none exist.getValue()
Returns the value of the manifest element.String[]
Returns the value components of the manifest element.parseBundleManifest
(InputStream manifest) Parses a bundle manifest and returns the header/value pairs into as case insensitive map.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.toString()
-
Method Details
-
getValue
Returns the value of the manifest element. The value returned is the complete value up to the first attribute or directive. For example, the following manifest element: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
- Returns:
- the value of the manifest element.
-
getValueComponents
Returns the value components of the manifest element. The value components returned are the complete list of value components up to the first attribute or directive. For example, the following manifest element: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 (';'
).- Returns:
- the String[] of value components
-
getAttribute
Returns the value for the specified attribute ornull
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 casevalue2
will be returned because it is the last value specified for the attributemyattr
.- Parameters:
key
- the attribute key to return the value for- Returns:
- the attribute value or
null
-
getAttributes
Returns an array of values for the specified attribute ornull
if the attribute does not exist.- Parameters:
key
- the attribute key to return the values for- Returns:
- the array of attribute values or
null
- See Also:
-
getKeys
Returns an enumeration of attribute keys for this manifest element ornull
if none exist.- Returns:
- the enumeration of attribute keys or null if none exist.
-
getDirective
Returns the value for the specified directive ornull
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 casevalue2
will be returned because it is the last value specified for the directivemydir
.- Parameters:
key
- the directive key to return the value for- Returns:
- the directive value or
null
-
getDirectives
Returns an array of string values for the specified directives ornull
if it does not exist.- Parameters:
key
- the directive key to return the values for- Returns:
- the array of directive values or
null
- See Also:
-
getDirectiveKeys
Return an enumeration of directive keys for this manifest element ornull
if there are none.- Returns:
- the enumeration of directive keys or
null
-
parseHeader
Parses a manifest header value into an array of ManifestElements. Each ManifestElement returned will have a non-null value returned by getValue().- Parameters:
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.- Returns:
- the array of ManifestElements that are represented by the header value; null will be returned if the value specified is null or if the value does not parse into one or more ManifestElements.
- Throws:
BundleException
- if the header value is invalid
-
getArrayFromList
Returns the result of converting a list of comma-separated tokens into an array.- Parameters:
stringList
- the initial comma-separated string- Returns:
- the array of string tokens or
null
if there are none
-
getArrayFromList
Returns the result of converting a list of tokens into an array. The tokens are split using the specified separator.- Parameters:
stringList
- the initial string listseparator
- the separator to use to split the list into tokens.- Returns:
- the array of string tokens. If there are none then an empty array is returned.
- Since:
- 3.2
-
parseBundleManifest
public static Map<String,String> parseBundleManifest(InputStream manifest) throws IOException, BundleException Parses a bundle manifest and returns the header/value pairs into as case insensitive map. Only the main section of the manifest is parsed (up to the first blank line). All other sections are ignored. If a header is duplicated then only the last value is stored in the map.The supplied input stream is consumed by this method and will be closed.
- Parameters:
manifest
- an input stream for a bundle manifest.- Returns:
- the map with the header/value pairs from the bundle manifest
- Throws:
BundleException
- if the manifest has an invalid syntaxIOException
- if an error occurs while reading the manifest- Since:
- 3.21
-
parseBundleManifest
public static Map<String,String> parseBundleManifest(InputStream manifest, Map<String, String> headers) throws IOException, BundleExceptionParses a bundle manifest and puts the header/value pairs into the supplied Map. Only the main section of the manifest is parsed (up to the first blank line). All other sections are ignored. If a header is duplicated then only the last value is stored in the map.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.
- Parameters:
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.- Returns:
- the map with the header/value pairs from the bundle manifest
- Throws:
BundleException
- if the manifest has an invalid syntaxIOException
- if an error occurs while reading the manifest
-
toString
-