CssTree.Import importNode, URI baseUri, int depth, UriFetcher fetcher,
MessageQueue mq, MutableParseTreeNode.Mutation mut)
throws ParseException {
CssTree.UriLiteral uriNode = importNode.getUri();
// Compute the URI to import
ExternalReference importUrl = null;
URI absUri = null;
URI relUri = null;
try {
relUri = new URI(uriNode.getValue());
absUri = UriUtil.resolve(baseUri, uriNode.getValue());
} catch (URISyntaxException ex) {
// handled below.
}
if (absUri != null) {
importUrl = new ExternalReference(
absUri, baseUri, relUri, uriNode.getFilePosition());
}
if (importUrl == null) {
mq.addMessage(
PluginMessageType.MALFORMED_URL,
uriNode.getFilePosition(),
MessagePart.Factory.valueOf(uriNode.getValue()));
return;
}
assert absUri != null; // because absUri == null -> importUrl == null
// Import it and recursively import its imports
CharProducer cp;
try {
cp = fetcher.fetch(importUrl, "text/css").getTextualContent();
} catch (UriFetcher.UriFetchException ex) {
mq.addMessage(PluginMessageType.FAILED_TO_LOAD_EXTERNAL_URL,
MessageLevel.ERROR, ex.ref.getReferencePosition(),
MessagePart.Factory.valueOf(ex.ref.getUri().toString()));
return;
} catch (UnsupportedEncodingException ex) {
mq.addMessage(PluginMessageType.FAILED_TO_LOAD_EXTERNAL_URL,
MessageLevel.ERROR, importUrl.getReferencePosition(),
MessagePart.Factory.valueOf(absUri.toString()));
return;
}
CssTree.StyleSheet importedSs = parseCss(cp, mq);
inlineImports(importedSs, importUrl.getUri(), depth - 1, fetcher, mq);
// Create a set of blocks to import by taking the union of media types on
// the import block and the media blocks in the style-sheet.
List<CssTree.Medium> media = importNode.getMedia();
if (!media.isEmpty()) {