01: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.utils;
07:
08: import org.xml.sax.Attributes;
09: import org.xml.sax.ContentHandler;
10: import org.xml.sax.SAXException;
11: import org.xml.sax.helpers.AttributesImpl;
12:
13: /**
14: * Replaces all relative URLs with absolute URLs in
15: * an XHTML document
16: * @author Ken Weiner, kweiner@unicon.net
17: * @version $Revision: 34796 $
18: */
19: public class XHTMLURLFilter extends AbsoluteURLFilter {
20:
21: /**
22: * A constructor which receives a ContentHandler to which
23: * filtered SAX events are passed
24: * @param handler the ContentHandler to which filtered SAX events are passed
25: */
26: protected XHTMLURLFilter(ContentHandler handler) {
27: super (handler);
28: }
29:
30: public void startElement(String uri, String localName,
31: String qName, Attributes atts) throws SAXException {
32: AttributesImpl attsImpl = new AttributesImpl(atts);
33:
34: if (qName.equals("base")) {
35: super .setBaseUrl(atts.getValue("href"));
36: return; // do not include base element in channel output
37: } else if (atts.getValue("src") != null) {
38: fixURL("img", "src", qName, atts, attsImpl);
39: fixURL("input", "src", qName, atts, attsImpl);
40: fixURL("script", "src", qName, atts, attsImpl);
41: fixURL("frame", "src", qName, atts, attsImpl);
42: fixURL("iframe", "src", qName, atts, attsImpl);
43: } else if (atts.getValue("href") != null) {
44: fixURL("a", "href", qName, atts, attsImpl);
45: fixURL("area", "href", qName, atts, attsImpl);
46: fixURL("map", "href", qName, atts, attsImpl);
47: fixURL("link", "href", qName, atts, attsImpl);
48: } else if (atts.getValue("action") != null) {
49: fixURL("form", "action", qName, atts, attsImpl);
50: }
51: super .startElement(uri, localName, qName, attsImpl);
52: }
53:
54: public void endElement(String uri, String localName, String qName)
55: throws SAXException {
56: if (qName.equals("base"))
57: return; // do not include base element in channel output
58: else
59: super.endElement(uri, localName, qName);
60: }
61: }
|