public SitemapSource(ComponentManager manager,
String uri,
Logger logger) throws IOException, ProcessingException {
Environment env = CocoonComponentManager.getCurrentEnvironment();
if ( env == null ) {
throw new MalformedURLException("The cocoon protocol can not be used outside an environment.");
}
this.manager = manager;
this.enableLogging(logger);
boolean rawMode = false;
// remove the protocol
int position = uri.indexOf(':") + 1;
if (position != 0) {
// check for subprotocol
if (uri.startsWith("raw:", position)) {
position += 4;
rawMode = true;
}
}
// does the uri point to this sitemap or to the root sitemap?
if (uri.startsWith("//", position)) {
position += 2;
try {
this.processor = (Processor)this.manager.lookup(Processor.ROLE);
} catch (ComponentException e) {
throw new ProcessingException("Cannot get Processor instance", e);
}
this.prefix = ""; // start at the root
} else if (uri.startsWith("/", position)) {
position ++;
this.prefix = null;
this.processor = CocoonComponentManager.getActiveProcessor(env);
} else {
throw new ProcessingException("Malformed cocoon URI.");
}
// create the queryString (if available)
String queryString = null;
int queryStringPos = uri.indexOf('?", position);
if (queryStringPos != -1) {
queryString = uri.substring(queryStringPos + 1);
uri = uri.substring(position, queryStringPos);
} else if (position > 0) {
uri = uri.substring(position);
}
// build the request uri which is relative to the context
String requestURI = (this.prefix == null ? env.getURIPrefix() + uri : uri);
// create system ID
this.systemId = queryString == null ?
"cocoon://" + requestURI :
"cocoon://" + requestURI + "?" + queryString;
this.environment = new EnvironmentWrapper(env, requestURI, queryString, logger, manager, rawMode);
this.uri = uri;
this.refresh();
}
|