001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.rewriter;
018:
019: import java.io.Reader;
020: import java.io.Writer;
021: import java.net.URL;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025:
026: /**
027: * AbstractRewriter
028: *
029: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
030: * @version $Id: AbstractRewriter.java 516448 2007-03-09 16:25:47Z ate $
031: */
032: public abstract class AbstractRewriter implements Rewriter {
033: protected final static Log log = LogFactory
034: .getLog(AbstractRewriter.class);
035:
036: private String baseUrl = null;
037: private boolean useProxy = false;
038:
039: /* (non-Javadoc)
040: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#rewrite(ParserAdaptor, java.io.Reader)
041: */
042: public void parse(ParserAdaptor adaptor, Reader reader)
043: throws RewriterException {
044: adaptor.parse(this , reader);
045: }
046:
047: /* (non-Javadoc)
048: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#rewrite(ParserAdaptor, java.io.Reader, java.io.Writer)
049: */
050: public void rewrite(ParserAdaptor adaptor, Reader reader,
051: Writer writer) throws RewriterException {
052: adaptor.rewrite(this , reader, writer);
053: }
054:
055: /* (non-Javadoc)
056: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#rewriteUrl(java.lang.String, java.lang.String, java.lang.String)
057: */
058: public abstract String rewriteUrl(String url, String tag,
059: String attribute);
060:
061: /* (non-Javadoc)
062: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#setBaseUrl(java.lang.String)
063: */
064: public void setBaseUrl(String base) {
065: this .baseUrl = base;
066: }
067:
068: /* (non-Javadoc)
069: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#getBaseUrl()
070: */
071: public String getBaseUrl() {
072: return baseUrl;
073: }
074:
075: public String getBaseRelativeUrl(String relativeUrl) {
076: try {
077: String baseUrl = getBaseUrl();
078: if (baseUrl != null) {
079: URL xlate = new URL(new URL(baseUrl), relativeUrl);
080: return xlate.toString();
081: }
082: } catch (Exception e) {
083: log
084: .error(
085: "Unable to translate URL relative to base URL",
086: e);
087: }
088: return relativeUrl;
089: }
090:
091: /* (non-Javadoc)
092: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#getUseProxy()
093: */
094: public boolean getUseProxy() {
095: return useProxy;
096: }
097:
098: /* (non-Javadoc)
099: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#setUseProxy(boolean)
100: */
101: public void setUseProxy(boolean useProxy) {
102: this .useProxy = useProxy;
103: }
104:
105: /* (non-Javadoc)
106: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#enterSimpleTagEvent(java.lang.String, MutableAttributes)
107: */
108: public boolean enterSimpleTagEvent(String tag,
109: MutableAttributes attrs) {
110: return true;
111: }
112:
113: /* (non-Javadoc)
114: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#exitSimpleTagEvent(java.lang.String, MutableAttributes)
115: */
116: public String exitSimpleTagEvent(String tag, MutableAttributes attrs) {
117: return null;
118: }
119:
120: /* (non-Javadoc)
121: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#enterStartTagEvent(java.lang.String, MutableAttributes)
122: */
123: public boolean enterStartTagEvent(String tag,
124: MutableAttributes attrs) {
125: return true;
126: }
127:
128: /* (non-Javadoc)
129: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#exitStartTagEvent(java.lang.String, MutableAttributes)
130: */
131: public String exitStartTagEvent(String tag, MutableAttributes attrs) {
132: return null;
133: }
134:
135: /* (non-Javadoc)
136: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#enterEndTagEvent(java.lang.String)
137: */
138: public boolean enterEndTagEvent(String tag) {
139: return true;
140: }
141:
142: /* (non-Javadoc)
143: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#exitEndTagEvent(java.lang.String)
144: */
145: public String exitEndTagEvent(String tag) {
146: return null;
147: }
148:
149: /* (non-Javadoc)
150: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#enterText(char[], int)
151: */
152: public boolean enterText(char[] values, int param) {
153: return true;
154: }
155:
156: /* (non-Javadoc)
157: * @see org.apache.jetspeed.syndication.services.crawler.rewriter.Rewriter#convertTagEvent(java.lang.String, MutableAttributes)
158: */
159: public void enterConvertTagEvent(String tag, MutableAttributes attrs) {
160: }
161: }
|