1 16 package org.apache.cocoon.components.url; 17 18 import org.apache.batik.util.AbstractParsedURLProtocolHandler; 19 import org.apache.batik.util.ParsedURL; 20 import org.apache.batik.util.ParsedURLData; 21 22 30 public class ParsedResourceURLProtocolHandler extends AbstractParsedURLProtocolHandler { 31 32 36 public ParsedResourceURLProtocolHandler() { 37 super("resource"); 38 } 39 40 44 public ParsedURLData parseURL(String uri) { 45 ParsedURLData urldata = null; 46 String path = uri.substring("resource:/".length()); 47 urldata = new ParsedURLData(Thread.currentThread().getContextClassLoader().getResource(path)); 48 49 if ("file".equals(urldata.protocol)) { 50 urldata.host = null; 51 urldata.port = -1; 52 } else if (null == urldata.host) { 53 urldata.port = -1; 54 } else if (urldata.port < 0) { 55 urldata.host = null; 56 } 57 58 return urldata; 59 } 60 61 64 public ParsedURLData parseURL(ParsedURL base, String uri) { 65 StringBuffer newURI = new StringBuffer ("resource://"); 66 newURI.append(base.getPath()); 67 68 if ( !newURI.toString().endsWith("/") ) { 69 newURI.append("/"); 70 } 71 72 newURI.append(uri.substring("resource:".length())); 73 74 return this.parseURL(newURI.toString()); 75 } 76 } 77 | Popular Tags |