private void import_rule(Stylesheet stylesheet) throws IOException {
//System.out.println("import()");
try {
Token t = next();
if (t == Token.TK_IMPORT_SYM) {
StylesheetInfo info = new StylesheetInfo();
info.setOrigin(stylesheet.getOrigin());
info.setType("text/css");
skip_whitespace();
t = next();
switch (t.getType()) {
case Token.STRING:
case Token.URI:
// first see if we can set URI via URL
try {
info.setUri(new URL(new URL(stylesheet.getURI()), getTokenValue(t)).toString());
} catch (MalformedURLException mue) {
// not a valid URL, may be a custom protocol which the user expects to handle
// in the user agent
//
// FIXME: using URI like this will not work for some cases of parent URI, depends
// on whether the URI class can parse the parent and child correctly
// This can lead to a bug where a stylesheet imported from another stylesheet ends
// up unresolved. This will be fixed in a later release by passing Stylesheet info
// all the way down to the UAC so that the end user can code for it
try {
URI parent = new URI(stylesheet.getURI());
String tokenValue = getTokenValue(t);
String resolvedUri = parent.resolve(tokenValue).toString();
System.out.println("Token: " + tokenValue + " resolved " + resolvedUri);
info.setUri(resolvedUri);
} catch (URISyntaxException use) {
throw new CSSParseException("Invalid URL, " + use.getMessage(), getCurrentLine());
}
}
skip_whitespace();
t = la();
if (t == Token.TK_IDENT) {
info.addMedium(medium());
while (true) {
t = la();
if (t == Token.TK_COMMA) {
next();
skip_whitespace();
t = la();
if (t == Token.TK_IDENT) {
info.addMedium(medium());
} else {
throw new CSSParseException(
t, Token.TK_IDENT, getCurrentLine());
}
} else {
break;
}
}
}
t = next();
if (t == Token.TK_SEMICOLON) {
skip_whitespace();
} else {
push(t);
throw new CSSParseException(
t, Token.TK_SEMICOLON, getCurrentLine());
}
break;
default:
push(t);
throw new CSSParseException(
t, new Token[] { Token.TK_STRING, Token.TK_URI }, getCurrentLine());
}
if (info.getMedia().size() == 0) {
info.addMedium("all");
}
stylesheet.addImportRule(info);
} else {
push(t);
throw new CSSParseException(