*/
public static ManifestElement[] parseHeader(String header, String value) throws BundleException {
if (value == null)
return (null);
ArrayList headerElements = new ArrayList(10);
Tokenizer tokenizer = new Tokenizer(value);
parseloop: while (true) {
String next = tokenizer.getString(";,"); //$NON-NLS-1$
if (next == null)
throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
ArrayList headerValues = new ArrayList();
StringBuffer headerValue = new StringBuffer(next);
headerValues.add(next);
if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
Debug.print("parseHeader: " + next); //$NON-NLS-1$
boolean directive = false;
char c = tokenizer.getChar();
// Header values may be a list of ';' separated values. Just append them all into one value until the first '=' or ','
while (c == ';') {
next = tokenizer.getString(";,=:"); //$NON-NLS-1$
if (next == null)
throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
c = tokenizer.getChar();
while (c == ':') { // may not really be a :=
c = tokenizer.getChar();
if (c != '=') {
String restOfNext = tokenizer.getToken(";,=:"); //$NON-NLS-1$
if (restOfNext == null)
throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
next += ":" + c + restOfNext; //$NON-NLS-1$
c = tokenizer.getChar();
} else
directive = true;
}
if (c == ';' || c == ',' || c == '\0') /* more */{
headerValues.add(next);
headerValue.append(";").append(next); //$NON-NLS-1$
if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
Debug.print(";" + next); //$NON-NLS-1$
}
}
// found the header value create a manifestElement for it.
ManifestElement manifestElement = new ManifestElement();
manifestElement.value = headerValue.toString();
manifestElement.valueComponents = (String[]) headerValues.toArray(new String[headerValues.size()]);
// now add any attributes/directives for the manifestElement.
while (c == '=' || c == ':') {
while (c == ':') { // may not really be a :=
c = tokenizer.getChar();
if (c != '=') {
String restOfNext = tokenizer.getToken("=:"); //$NON-NLS-1$
if (restOfNext == null)
throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
next += ":" + c + restOfNext; //$NON-NLS-1$
c = tokenizer.getChar();
} else
directive = true;
}
String val = tokenizer.getString(";,"); //$NON-NLS-1$
if (val == null)
throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
Debug.print(";" + next + "=" + val); //$NON-NLS-1$ //$NON-NLS-2$
try {
if (directive)
manifestElement.addDirective(next, val);
else
manifestElement.addAttribute(next, val);
directive = false;
} catch (Exception e) {
throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR, e);
}
c = tokenizer.getChar();
if (c == ';') /* more */{
next = tokenizer.getToken("=:"); //$NON-NLS-1$
if (next == null)
throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
c = tokenizer.getChar();
}
}
headerElements.add(manifestElement);
if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
Debug.println(""); //$NON-NLS-1$