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.rules.impl;
018:
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.ArrayList;
022: import java.util.StringTokenizer;
023:
024: import org.apache.jetspeed.rewriter.rules.Rule;
025:
026: /**
027: * Rule
028: *
029: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
030: * @version $Id: RuleImpl.java 517121 2007-03-12 07:45:49Z ate $
031: */
032: public class RuleImpl extends IdentifiedImpl implements Rule {
033: private boolean useBase = true;
034: private boolean popup = false;
035: private String suffix = null;
036: private String prefixes = null;
037: private List ignorePrefixes = null;
038:
039: public String toString() {
040: return id;
041: }
042:
043: /* (non-Javadoc)
044: * @see org.apache.jetspeed.cps.rewriter.rules.Rule#getPopup()
045: */
046: public boolean getPopup() {
047: return popup;
048: }
049:
050: /* (non-Javadoc)
051: * @see org.apache.jetspeed.cps.rewriter.rules.Rule#getSuffix()
052: */
053: public String getSuffix() {
054: return suffix;
055: }
056:
057: /* (non-Javadoc)
058: * @see org.apache.jetspeed.cps.rewriter.rules.Rule#getUseBase()
059: */
060: public boolean getUseBase() {
061: return useBase;
062: }
063:
064: /* (non-Javadoc)
065: * @see org.apache.jetspeed.cps.rewriter.rules.Rule#setPopup(boolean)
066: */
067: public void setPopup(boolean b) {
068: popup = b;
069: }
070:
071: /* (non-Javadoc)
072: * @see org.apache.jetspeed.cps.rewriter.rules.Rule#setSuffix(java.lang.String)
073: */
074: public void setSuffix(String string) {
075: suffix = string;
076: }
077:
078: /* (non-Javadoc)
079: * @see org.apache.jetspeed.cps.rewriter.rules.Rule#setUseBase(boolean)
080: */
081: public void setUseBase(boolean b) {
082: useBase = b;
083: }
084:
085: public void setIgnorePrefixes(String prefixes) {
086: this .prefixes = prefixes;
087: }
088:
089: public String getIgnorePrefixes() {
090: return this .prefixes;
091: }
092:
093: public boolean shouldRewrite(String url) {
094: if (prefixes == null) {
095: return true;
096: }
097: if (ignorePrefixes == null) {
098: ignorePrefixes = new ArrayList();
099: StringTokenizer tokenizer = new StringTokenizer(prefixes,
100: ",");
101: while (tokenizer.hasMoreTokens()) {
102: String token = tokenizer.nextToken();
103: ignorePrefixes.add(token);
104: }
105:
106: }
107:
108: Iterator list = ignorePrefixes.iterator();
109: while (list.hasNext()) {
110: String prefix = (String) list.next();
111: if (url.startsWith(prefix)) {
112: return false;
113: }
114: }
115: return true;
116: }
117:
118: }
|