You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2014/08/18 00:58:19 UTC
svn commit: r1618527 [3/3] - in /portals/applications/webcontent/trunk: ./
portlets/
portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/
portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/
portle...
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Rule.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Rule.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Rule.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Rule.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules;
+
+/**
+ * Rule
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: Rule.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public interface Rule extends Identified
+{
+ /**
+ * Flag indicating whether to use the Base URL for this rewriter.
+ * The default setting is true, use the rewriter's Base URL.
+ *
+ * @return true if this rule uses the Base URL
+ */
+ boolean getUseBase();
+
+ /**
+ * Flag indicating whether to use the Base URL for this rewriter.
+ * The default setting is true, use the rewriter's Base URL.
+ *
+ * @param true if this rule uses the Base URL
+ */
+ void setUseBase(boolean flag);
+
+ /**
+ * Suffix string to append to the rewritten URL.
+ *
+ * @return the value of the suffix string.
+ */
+ String getSuffix();
+
+ /**
+ * Suffix string to append to the rewritten URL.
+ *
+ * @param the value of the suffix string.
+ */
+ void setSuffix(String suffix);
+
+ /**
+ * Flag indicating whether to rewrite links as popups.
+ * The default setting is false, do not rewrite as a popup.
+ *
+ * @return true if this rule rewrites links as popups
+ */
+ boolean getPopup();
+
+ /**
+ * Flag indicating whether to rewrite links as popups.
+ * The default setting is false, do not rewrite as a popup.
+ *
+ * @param true if this rule rewrites links as popups
+ */
+ void setPopup(boolean flag);
+
+ /**
+ * Checks to see if a URL should be rewritten or not.
+ *
+ * @param url
+ */
+ boolean shouldRewrite(String url);
+
+
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Ruleset.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Ruleset.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Ruleset.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Ruleset.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules;
+
+import java.util.Collection;
+
+/**
+ * Ruleset
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: Ruleset.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public interface Ruleset extends Identified
+{
+ /**
+ * Get the remove comments flag for removing comments from the markup source.
+ *
+ * @return true True if comments should be removed.
+ */
+ public boolean getRemoveComments();
+
+ /**
+ * Set the remove comments flag for removing comments from the markup source.
+ *
+ * @param flag True if comments should be removed.
+ */
+ public void setRemoveComments(boolean flag);
+
+ /**
+ * Given a tag identifier, lookup and return a tag object.
+ *
+ * @param tagId the unique tag identifier
+ * @return the tag object for the given identifier
+ */
+ Tag getTag(String tagId);
+
+ /**
+ * Given a rule identifier, lookup and return a rule object.
+ *
+ * @param ruleId the unique rule identifier
+ * @return the rule object for the given identifier
+ */
+ Rule getRule(String ruleId);
+
+
+ /**
+ * Get a collection of rules for this rule set.
+ *
+ * @return A collection of rules.
+ */
+ Collection getRules();
+
+ /**
+ * Get a collection of markup tags for this rule set.
+ *
+ * @return A collection of markup tags.
+ */
+ public Collection getTags();
+
+ /**
+ * Synchronize the Ruleset
+ *
+ */
+ void sync();
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Tag.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Tag.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Tag.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/Tag.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules;
+
+import java.util.Collection;
+
+/**
+ * Tag
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: Tag.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public interface Tag extends Identified
+{
+ /**
+ * Get a collection of attributes for the given Tag.
+ *
+ * @return A collection of attributes.
+ */
+ Collection getAttributes();
+
+
+ /**
+ * Represents whether this tag is to be removed during rewrite phase.
+ * Removing a tag only removes the tag but not the contents in
+ * between the start and end tag.
+ *
+ * @return true if this tag should be removed
+ */
+ public boolean getRemove();
+
+ /**
+ * Represents whether this tag is to be removed during rewrite phase.
+ * Removing a tag only removes the tag but not the contents in
+ * between the start and end tag.
+ *
+ * @param flag true if this tag should be removed
+ */
+ public void setRemove(boolean flag);
+
+ /**
+ * Represents whether this tag is to be removed during rewrite phase.
+ * Stripping tags removes the start and end tag, plus all tags
+ * and content in between the start and end tag.
+ *
+ * @return true if this tag should be stripped.
+ */
+ public boolean getStrip();
+
+ /**
+ * Represents whether this tag is to be removed during rewrite phase.
+ * Stripping tags removes the start and end tag, plus all tags
+ * and content in between the start and end tag.
+ *
+ * @param flag true if this tag should be stripped.
+ */
+ public void setStrip(boolean flag);
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/AttributeImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/AttributeImpl.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/AttributeImpl.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/AttributeImpl.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl;
+
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Attribute;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Rule;
+
+/**
+ * Attribute
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: AttributeImpl.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public class AttributeImpl extends IdentifiedImpl implements Attribute
+{
+ private Rule rule;
+ private String ruleId;
+
+ public void setId(String id)
+ {
+ if (id != null)
+ {
+ this.id = id.toUpperCase();
+ }
+ }
+
+ public Rule getRule()
+ {
+ return this.rule;
+ }
+
+ public void setRule(Rule rule)
+ {
+ this.rule = rule;
+ }
+
+ /**
+ * Castor setter to set the rule id.
+ *
+ * @param ruleId The rule identifier.
+ */
+ public void setRuleId(String ruleId)
+ {
+ this.ruleId = ruleId;
+ }
+
+ /**
+ * Castor accessor to get the rule id.
+ *
+ * @return The rule identifier.
+ */
+ public String getRuleId()
+ {
+ return this.ruleId;
+ }
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/IdentifiedImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/IdentifiedImpl.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/IdentifiedImpl.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/IdentifiedImpl.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl;
+
+/**
+ * IdentifiedImpl
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: IdentifiedImpl.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public class IdentifiedImpl
+{
+ protected String id;
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId(String id)
+ {
+ if (id != null)
+ {
+ this.id = id;
+ }
+ }
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RuleImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RuleImpl.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RuleImpl.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RuleImpl.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Rule;
+
+/**
+ * Rule
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: RuleImpl.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public class RuleImpl extends IdentifiedImpl implements Rule
+{
+ private boolean useBase = true;
+ private boolean popup = false;
+ private String suffix = null;
+ private String prefixes = null;
+ private List ignorePrefixes = null;
+
+ public String toString()
+ {
+ return id;
+ }
+
+ public boolean getPopup()
+ {
+ return popup;
+ }
+
+ public String getSuffix()
+ {
+ return suffix;
+ }
+
+ public boolean getUseBase()
+ {
+ return useBase;
+ }
+
+ public void setPopup(boolean b)
+ {
+ popup = b;
+ }
+
+ public void setSuffix(String string)
+ {
+ suffix = string;
+ }
+
+ public void setUseBase(boolean b)
+ {
+ useBase = b;
+ }
+
+ public void setIgnorePrefixes(String prefixes)
+ {
+ this.prefixes = prefixes;
+ }
+
+ public String getIgnorePrefixes()
+ {
+ return this.prefixes;
+ }
+
+ public boolean shouldRewrite(String url)
+ {
+ if (prefixes == null)
+ {
+ return true;
+ }
+ if (ignorePrefixes == null)
+ {
+ ignorePrefixes = new ArrayList();
+ StringTokenizer tokenizer = new StringTokenizer(prefixes, ",");
+ while (tokenizer.hasMoreTokens())
+ {
+ String token = tokenizer.nextToken();
+ ignorePrefixes.add(token);
+ }
+
+ }
+
+ Iterator list = ignorePrefixes.iterator();
+ while (list.hasNext())
+ {
+ String prefix = (String)list.next();
+ if (url.startsWith(prefix))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RulesetImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RulesetImpl.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RulesetImpl.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/RulesetImpl.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Attribute;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Rule;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Ruleset;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Tag;
+
+/**
+ * RulesetImpl
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: RulesetImpl.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+/**
+ * Ruleset
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: RulesetImpl.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public class RulesetImpl extends IdentifiedImpl implements Ruleset
+{
+ private Collection rules = new ArrayList();
+ private Collection tags = new ArrayList();
+ private Map ruleMap = new HashMap();
+ private Map tagMap = new HashMap();
+ private boolean removeComments = false;
+
+ public Tag getTag(String tagId)
+ {
+ return (Tag)tagMap.get(tagId);
+ }
+
+ public Rule getRule(String ruleId)
+ {
+ return (Rule)ruleMap.get(ruleId);
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer("Ruleset:" + id);
+ if (rules.size() == 0)
+ {
+ buffer.append(", no rules defined, ");
+ }
+ else
+ {
+ buffer.append(", rules: ");
+ Iterator it = rules.iterator();
+ while (it.hasNext())
+ {
+ RuleImpl rule = (RuleImpl)it.next();
+ buffer.append(rule.toString());
+ buffer.append(", ");
+ }
+ }
+ if (tags.size() == 0)
+ {
+ buffer.append(" no tags defined.");
+ }
+ else
+ {
+ buffer.append("tags: ");
+ Iterator it = tags.iterator();
+ while (it.hasNext())
+ {
+ TagImpl tag = (TagImpl)it.next();
+ buffer.append(tag.toString());
+ buffer.append(", ");
+ }
+ }
+ return buffer.toString();
+ }
+
+ public void sync()
+ {
+ ruleMap.clear();
+ Iterator it = rules.iterator();
+ while (it.hasNext())
+ {
+ Rule rule = (Rule)it.next();
+ ruleMap.put(rule.getId(), rule);
+ }
+
+ tagMap.clear();
+ it = tags.iterator();
+ while (it.hasNext())
+ {
+ Tag tag = (Tag)it.next();
+ tagMap.put(tag.getId(), tag);
+ Iterator attributes = tag.getAttributes().iterator();
+ while (attributes.hasNext())
+ {
+ Attribute attribute = (Attribute)attributes.next();
+ if (attribute instanceof AttributeImpl)
+ {
+ String ruleId = ((AttributeImpl)attribute).getRuleId();
+ Rule rule = (Rule)ruleMap.get(ruleId);
+ if (rule != null)
+ {
+ attribute.setRule(rule);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Castor setter
+ *
+ * @param rules
+ */
+ public void setRules(Collection rules)
+ {
+ this.rules = rules;
+ }
+
+ public Collection getRules()
+ {
+ return this.rules;
+ }
+
+ /**
+ * Castor setter
+ *
+ * @param rules
+ */
+ public void setTags(Collection tags)
+ {
+ this.tags = tags;
+ }
+
+ public Collection getTags()
+ {
+ return this.tags;
+ }
+
+ public boolean getRemoveComments()
+ {
+ return removeComments;
+ }
+
+ public void setRemoveComments(boolean b)
+ {
+ removeComments = b;
+ }
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/TagImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/TagImpl.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/TagImpl.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/rules/impl/TagImpl.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Tag;
+
+/**
+ * Tag
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: TagImpl.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public class TagImpl extends IdentifiedImpl implements Tag
+{
+ private boolean remove = false;
+ private boolean strip = false;
+ private Collection attributes = new ArrayList();
+
+ public void setId(String id)
+ {
+ if (id != null)
+ {
+ this.id = id.toUpperCase();
+ }
+ }
+
+ public boolean getRemove()
+ {
+ return remove;
+ }
+
+ public void setRemove(boolean b)
+ {
+ remove = b;
+ }
+
+ public String toString()
+ {
+ return id;
+ }
+
+ /**
+ * Castor setter to set attributes for a Tag.
+ *
+ * @param attributes
+ */
+ public void setAttributes(Collection attributes)
+ {
+ this.attributes = attributes;
+ }
+
+ /**
+ * Castor getter to get attributes for a Tag.
+ *
+ * @param attributes
+ */
+ public Collection getAttributes()
+ {
+ return this.attributes;
+ }
+
+
+ /**
+ * @return
+ */
+ public boolean getStrip()
+ {
+ return strip;
+ }
+
+ /**
+ * @param b
+ */
+ public void setStrip(boolean b)
+ {
+ strip = b;
+ }
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/util/Streams.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/util/Streams.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/util/Streams.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/util/Streams.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Utility functions related to Streams.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: Streams.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public class Streams
+{
+ static final int BLOCK_SIZE=4096;
+
+ public static void drain(InputStream r,OutputStream w) throws IOException
+ {
+ byte[] bytes=new byte[BLOCK_SIZE];
+ try
+ {
+ int length=r.read(bytes);
+ while(length!=-1)
+ {
+ if(length!=0)
+ {
+ w.write(bytes,0,length);
+ }
+ length=r.read(bytes);
+ }
+ }
+ finally
+ {
+ bytes=null;
+ }
+
+ }
+
+ public static void drain(Reader r,Writer w) throws IOException
+ {
+ char[] bytes=new char[BLOCK_SIZE];
+ try
+ {
+ int length=r.read(bytes);
+ while(length!=-1)
+ {
+ if(length!=0)
+ {
+ w.write(bytes,0,length);
+ }
+ length=r.read(bytes);
+ }
+ }
+ finally
+ {
+ bytes=null;
+ }
+
+ }
+
+ public static void drain(Reader r,OutputStream os) throws IOException
+ {
+ Writer w=new OutputStreamWriter(os);
+ drain(r,w);
+ w.flush();
+ }
+
+ public static void drain(InputStream is, Writer w) throws IOException
+ {
+ Reader r = new InputStreamReader(is);
+ drain(r,w);
+ w.flush();
+ }
+
+ public static byte[] drain(InputStream r) throws IOException
+ {
+ ByteArrayOutputStream bytes=new ByteArrayOutputStream();
+ drain(r,bytes);
+ return bytes.toByteArray();
+ }
+
+ public static String getAsString(InputStream is)
+ {
+ int c=0;
+ char lineBuffer[]=new char[128], buf[]=lineBuffer;
+ int room= buf.length, offset=0;
+ try
+ {
+ loop: while (true)
+ {
+ // read chars into a buffer which grows as needed
+ switch (c = is.read() )
+ {
+ case -1: break loop;
+
+ default: if (--room < 0)
+ {
+ buf = new char[offset + 128];
+ room = buf.length - offset - 1;
+ System.arraycopy(lineBuffer, 0,
+ buf, 0, offset);
+ lineBuffer = buf;
+ }
+ buf[offset++] = (char) c;
+ break;
+ }
+ }
+ }
+ catch(IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ if ((c == -1) && (offset == 0))
+ {
+ return null;
+ }
+ return String.copyValueOf(buf, 0, offset);
+ }
+
+
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/xml/SaxParserAdaptor.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/xml/SaxParserAdaptor.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/xml/SaxParserAdaptor.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/rewriter/xml/SaxParserAdaptor.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,342 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.portals.applications.webcontent2.portlet.rewriter.MutableAttributes;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.ParserAdaptor;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.Rewriter;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.RewriterException;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.util.Streams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * SaxParserAdaptor
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: SaxParserAdaptor.java 891414 2009-12-16 20:19:02Z rwatler $
+ */
+public class SaxParserAdaptor implements ParserAdaptor
+{
+ protected final static Logger log = LoggerFactory.getLogger(SaxParserAdaptor.class);
+ private String lineSeparator;
+
+ private Rewriter rewriter;
+
+
+
+
+ public SaxParserAdaptor()
+ {
+ lineSeparator = System.getProperty("line.separator", "\r\n");
+ }
+
+ public void parse(Rewriter rewriter, Reader reader)
+ throws RewriterException
+ {
+ try
+ {
+ this.rewriter = rewriter;
+ SAXParser sp = getParser();
+ sp.parse(new InputSource(reader), new SaxFormatHandler(null));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new RewriterException(e);
+ }
+
+ }
+
+ public void rewrite(Rewriter rewriter, Reader reader, Writer writer)
+ throws RewriterException
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * Get a Parser from the SAX Parser factory
+ *
+ * @return A SAXParser
+ */
+ protected SAXParser getParser()
+ throws ParserConfigurationException, SAXException
+ {
+ SAXParserFactory spf = SAXParserFactory.newInstance ();
+ spf.setValidating(false);
+
+ return spf.newSAXParser ();
+ }
+
+ /**
+ * Inner class to handle SAX parsing of XML files
+ */
+ public class SaxFormatHandler extends DefaultHandler
+ {
+ private int elementCount = 0;
+ private boolean emit = true;
+ private Writer writer = null;
+ private Stack tagStack = new Stack();
+
+ public SaxFormatHandler(Writer writer)
+ {
+ super();
+ this.writer = writer;
+ }
+
+ private void write(String text)
+ throws IOException
+ {
+ if (writer != null)
+ {
+ writer.write(text);
+ }
+ }
+
+ public void characters(char[] values, int start, int length)
+ {
+ if (false == emit)
+ return;
+
+ if (false == rewriter.enterText(values, start))
+ return;
+
+ if (!tagStack.isEmpty())
+ {
+ String tag = (String)tagStack.peek();
+ String convertedValues = convertText(tag, new String(values, start, length));
+ if (convertedValues != null)
+ {
+ values = convertedValues.toCharArray();
+ }
+ }
+
+ if (writer != null)
+ {
+ try
+ {
+ writer.write(values);
+ }
+ catch(IOException e)
+ {
+ }
+ }
+ }
+
+ public void startElement(String uri, String localName, String qName, MutableAttributes attributes)
+ throws SAXException
+ {
+// System.out.println("qName = " + qName);
+// System.out.println("localName = " + localName);
+// System.out.println("uri = " + uri);
+ String tag = qName;
+ tagStack.push(tag);
+
+ if (false == rewriter.enterStartTagEvent(tag.toString(), attributes))
+ return;
+
+ try
+ {
+ appendTagToResult(tag, attributes);
+ write(lineSeparator);
+ String appended = rewriter.exitStartTagEvent(tag.toString(), attributes);
+ if (null != appended)
+ {
+ write(appended);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Start tag parsing error", e);
+ }
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException
+ {
+ String tag = qName;
+ if (!tagStack.isEmpty() && tag.equals(tagStack.peek()))
+ {
+ tagStack.pop();
+ }
+ elementCount++;
+ if (false == rewriter.enterEndTagEvent(tag.toString()))
+ return;
+
+ try
+ {
+ addToResult("</").addToResult(tag).addToResult(">");
+
+ write(lineSeparator);
+ String appended = rewriter.exitEndTagEvent(tag.toString());
+ if (null != appended)
+ {
+ write(appended);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("End tag parsing error", e);
+ }
+
+ }
+
+ /*
+ * Writes output to the final stream for all attributes of a given tag.
+ *
+ * @param tag The HTML tag being output.
+ * @param attrs The mutable HTML attribute set for the current HTML tag.
+ */
+ private void appendTagToResult(String tag, MutableAttributes attrs)
+ {
+ convertURLS(tag, attrs);
+ addToResult("<").addToResult(tag);
+ for (int ix = 0; ix < attrs.getLength(); ix++)
+ {
+ String value = attrs.getValue(ix);
+ addToResult(" ").addToResult(value).addToResult("=\"").
+ addToResult(value).addToResult("\"");
+ }
+ addToResult(">");
+ }
+
+ /*
+ * Used to write tag and attribute objects to the output stream.
+ * Returns a reference to itself so that these calls can be chained.
+ *
+ * @param txt Any text to be written out to stream with toString method.
+ * The object being written should implement its toString method.
+ * @return A handle to the this, the callback, for chaining results.
+ *
+ */
+ private SaxFormatHandler addToResult(Object txt)
+ {
+ // to allow for implementation using Stringbuffer or StringWriter
+ // I don't know yet, which one is better in this case
+ // if (ignoreLevel > 0 ) return this;
+
+ try
+ {
+ write(txt.toString());
+ }
+ catch (Exception e)
+ {
+ System.err.println("Error parsing:" + e);
+ }
+ return this;
+ }
+
+ /*
+ * Determines which HTML Tag/Element is being inspected, and calls the
+ * appropriate converter for that context. This method contains all the
+ * logic for determining how tags are rewritten.
+ *
+ * TODO: it would be better to drive this logic off a state table that is not
+ * tied to the Hot Java parser.
+ *
+ * @param tag TAG from the Callback-Interface.
+ * @param attrs The mutable HTML attribute set for the current HTML element.
+ */
+
+ private void convertURLS(String tag, MutableAttributes attrs)
+ {
+ rewriter.enterConvertTagEvent(tag.toString(), attrs);
+ }
+
+ /*
+ * Determines which HTML Tag/Element is being inspected, and calls the
+ * appropriate converter for that context. This method contains all the
+ * logic for determining how text is rewritten.
+ *
+ * @param tag TAG from the Callback-Interface.
+ * @param text The text for the current HTML element.
+ */
+
+ private String convertText(String tag, String text)
+ {
+ return rewriter.enterConvertTextEvent(tag.toString(), text);
+ }
+
+ public InputSource resolveEntity (String publicId, String systemId)
+ {
+
+ try
+ {
+ Map dtds = getDtds();
+ byte[] dtd = (byte[])dtds.get(systemId);
+ if (dtd == null)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ URL url = new URL(systemId);
+ Streams.drain(url.openStream(), baos);
+ dtd = baos.toByteArray();
+ dtds.put(systemId, dtd);
+ }
+
+ if (dtd != null)
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(dtd);
+ InputSource is = new InputSource(bais);
+ is.setPublicId( publicId );
+ is.setSystemId( systemId );
+
+ return is;
+ }
+ }
+ catch(Throwable t ) // java.io.IOException x
+ {
+ t.printStackTrace();
+ log.error("failed to get URL input source", t);
+ }
+
+ // forces to get dtd over internet
+ return null;
+ }
+
+ }
+
+ // DTD Map
+ static private Map dtds = new HashMap();
+
+ public static Map getDtds()
+ {
+ return dtds;
+ }
+
+ public static void clearDtdCache()
+ {
+ dtds.clear();
+ }
+
+}
Added: portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/AbstractRewriterTestCase.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/AbstractRewriterTestCase.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/AbstractRewriterTestCase.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/AbstractRewriterTestCase.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter;
+
+
+abstract public class AbstractRewriterTestCase
+{
+ private String baseDir;
+
+ protected String getBaseDir()
+ {
+ if (baseDir == null)
+ {
+ baseDir = System.getProperty("basedir");
+
+ if (baseDir == null || baseDir.length() == 0)
+ {
+ baseDir = ".";
+ }
+
+ baseDir += "/";
+ }
+
+ return baseDir;
+ }
+}
\ No newline at end of file
Added: portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestNekoRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestNekoRewriter.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestNekoRewriter.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestNekoRewriter.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.portals.applications.webcontent2.portlet.rewriter.html.neko.NekoParserAdaptor;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Ruleset;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.xml.SaxParserAdaptor;
+import org.junit.Test;
+
+
+/**
+ * TestNekoRewriter
+ *
+ * @author <a href="mailto:dyoung@phase2systems.com">David L Young</a>
+ * @version $Id: TestNekoRewriter.java 771214 2009-05-04 07:08:16Z vkumar $
+ */
+public class TestNekoRewriter extends AbstractRewriterTestCase
+{
+
+ // NekoParserAdapter test
+ @Test
+ public void testNekoParserAdaptor() throws Exception
+ {
+ RewriterController controller = getController();
+ FileReader rulesReader = getTestReader("test-remove-rules.xml");
+ Ruleset ruleset = controller.loadRuleset(rulesReader);
+ rulesReader.close();
+ assertNotNull("ruleset is null", ruleset);
+ RulesetRewriter rewriter = controller.createRewriter(ruleset);
+ assertNotNull("ruleset rewriter is null", rewriter);
+
+ FileReader htmlReader = getTestReader("test-001.html");
+ FileWriter htmlWriter = getTestWriter("test-002-output.html");
+
+ ParserAdaptor adaptor = controller.createParserAdaptor("text/html");
+ rewriter.setBaseUrl("http://www.rewriter.com");
+ rewriter.rewrite(adaptor, htmlReader, htmlWriter);
+ htmlReader.close();
+ }
+
+ private RewriterController getController() throws Exception
+ {
+ Class[] rewriterClasses = new Class[]{ RulesetRewriterImpl.class, RulesetRewriterImpl.class};
+ Class[] adaptorClasses = new Class[]{ NekoParserAdaptor.class, SaxParserAdaptor.class};
+ return new MappingRewriterController(getBaseDir()+"src/test/webapp/WEB-INF/conf/rewriter-rules-mapping.xml", Arrays.asList(rewriterClasses), Arrays.asList(adaptorClasses));
+ }
+
+ /**
+ * Gets a reader for a given filename in the test directory.
+ *
+ * @return A file reader to the test rules file
+ * @throws IOException
+ */
+ private FileReader getTestReader(String filename) throws IOException
+ {
+ return new FileReader(getBaseDir() + "src/test/rewriter/" + filename);
+ }
+
+ /**
+ * Gets a writer for a given filename in the test directory.
+ *
+ * @return A file reader to the test rules file
+ * @throws IOException
+ */
+ private FileWriter getTestWriter(String filename) throws IOException
+ {
+ new File(getBaseDir()+"target/test/rewriter").mkdirs();
+ return new FileWriter(getBaseDir()+"target/test/rewriter/" + filename);
+ }
+}
Added: portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestRewriterController.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestRewriterController.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestRewriterController.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/TestRewriterController.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.portals.applications.webcontent2.portlet.rewriter.html.SwingParserAdaptor;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Attribute;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Rule;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Ruleset;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.rules.Tag;
+import org.apache.portals.applications.webcontent2.portlet.rewriter.xml.SaxParserAdaptor;
+import org.junit.Test;
+
+/**
+ * TestRewriterRules
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: TestRewriterController.java,v 1.3 2004/10/13 15:53:22 weaver
+ * Exp $
+ */
+public class TestRewriterController extends AbstractRewriterTestCase
+{
+
+ @Test
+ public void testFactories() throws Exception
+ {
+ RewriterController component = getController();
+ assertNotNull("template component is null", component);
+
+ Rewriter basic = component.createRewriter();
+ assertNotNull("basic rewriter is null", basic);
+ FileReader reader = new FileReader(getBaseDir()+"src/test/rewriter/test-rewriter-rules.xml");
+ Ruleset ruleset = component.loadRuleset(reader);
+ assertNotNull("ruleset is null", ruleset);
+ RulesetRewriter rewriter = component.createRewriter(ruleset);
+ assertNotNull("ruleset rewriter is null", rewriter);
+ assertNotNull("ruleset is null", rewriter.getRuleset());
+ }
+
+ @Test
+ public void testRules() throws Exception
+ {
+ RewriterController component = getController();
+ assertNotNull("template component is null", component);
+
+ assertNotNull("rewriter component is null", component);
+ FileReader reader = new FileReader(getBaseDir()+"src/test/rewriter/test-rewriter-rules.xml");
+ Ruleset ruleset = component.loadRuleset(reader);
+ assertNotNull("ruleset is null", ruleset);
+ assertEquals("ruleset id", "test-set-101", ruleset.getId());
+ Iterator rules = ruleset.getRules().iterator();
+ assertNotNull("rules is null", rules);
+
+ //
+ // test tags
+ //
+ Iterator tags = ruleset.getTags().iterator();
+
+ while (tags.hasNext())
+ {
+ Tag tag = (Tag) tags.next();
+
+ if (tag.getId().equalsIgnoreCase("FORM"))
+ {
+ assertFalse("Remove", tag.getRemove());
+ Iterator attributes = tag.getAttributes().iterator();
+
+ while (attributes.hasNext())
+ {
+ Attribute attribute = (Attribute) attributes.next();
+ assertTrue("attribute is not ACTION", attribute.getId().equals("ACTION"));
+ assertEquals("attribute rule not equal", attribute.getRule().getId(), "merge");
+ }
+ }
+ else if (tag.getId().equalsIgnoreCase("INPUT"))
+ {
+ assertFalse("Remove", tag.getRemove());
+ Iterator attributes = tag.getAttributes().iterator();
+
+ while (attributes.hasNext())
+ {
+ Attribute attribute = (Attribute) attributes.next();
+ assertTrue("attribute is not SOURCE", attribute.getId().equals("SOURCE"));
+ assertEquals("attribute rule not equal", attribute.getRule().getId(), "test");
+ }
+
+ }
+ else if (tag.getId().equalsIgnoreCase("LINK"))
+ {
+ assertFalse("Remove", tag.getRemove());
+ Iterator attributes = tag.getAttributes().iterator();
+
+ while (attributes.hasNext())
+ {
+ Attribute attribute = (Attribute) attributes.next();
+ assertTrue("attribute is not HREF", attribute.getId().equals("HREF"));
+ assertEquals("attribute rule not equal", attribute.getRule().getId(), "merge");
+ }
+ }
+ else if (tag.getId().equalsIgnoreCase("HEAD"))
+ {
+ assertTrue("Remove", tag.getRemove());
+ }
+ else
+ {
+ assertTrue("tag name unexpected: " + tag.getId(), false);
+ }
+
+ }
+ assertNotNull("tags is null", tags);
+
+ //
+ // test rules
+ //
+ while (rules.hasNext())
+ {
+ Rule rule = (Rule) rules.next();
+ assertNotNull("rule is null", rule);
+
+ if (rule.getId().equals("merge"))
+ {
+ assertEquals("Rule id", rule.getId(), "merge");
+ assertTrue("Rule Use Base", rule.getUseBase());
+ assertFalse("Rule Popup", rule.getPopup());
+ assertEquals("Rule Suffix", rule.getSuffix(), "/web");
+ }
+ else if (rule.getId().equals("test"))
+ {
+ assertEquals("Rule id", rule.getId(), "test");
+ assertFalse("Rule Use Base", rule.getUseBase());
+ assertTrue("Rule Popup", rule.getPopup());
+ assertEquals("Rule Suffix", rule.getSuffix(), "/whatever&xxx=1");
+ }
+ else
+ {
+ assertTrue("rule name unexpected: " + rule.getId(), false);
+ }
+ }
+
+ }
+
+ @Test
+ public void testRewriting() throws Exception
+ {
+ RewriterController component = getController();
+ assertNotNull("template component is null", component);
+
+ assertNotNull("rewriter component is null", component);
+
+ FileReader reader = new FileReader(getBaseDir()+"src/test/rewriter/test-remove-rules.xml");
+
+ Ruleset ruleset = component.loadRuleset(reader);
+ reader.close();
+ assertNotNull("ruleset is null", ruleset);
+ RulesetRewriter rewriter = component.createRewriter(ruleset);
+ assertNotNull("ruleset rewriter is null", rewriter);
+ assertNotNull("ruleset is null", rewriter.getRuleset());
+
+ FileReader htmlReader = new FileReader(getBaseDir()+"src/test/rewriter/test-001.html");
+ FileWriter htmlWriter = getTestWriter("test-001-output.html");
+
+ ParserAdaptor adaptor = component.createParserAdaptor("text/html");
+ rewriter.setBaseUrl("http://www.rewriter.com");
+ rewriter.rewrite(adaptor, htmlReader, htmlWriter);
+ htmlWriter.close();
+ htmlReader.close();
+
+ // validate result
+ FileReader testReader = new FileReader(getBaseDir()+"target/test/rewriter/test-001-output.html");
+ UnitTestRewriter testRewriter = new UnitTestRewriter();
+ testRewriter.parse(component.createParserAdaptor("text/html"), testReader);
+ assertTrue("1st rewritten anchor: " + testRewriter.getAnchorValue("1"), testRewriter.getAnchorValue("1")
+ .equals("http://www.bluesunrise.com/suffix"));
+ assertTrue("2nd rewritten anchor: " + testRewriter.getAnchorValue("2"), testRewriter.getAnchorValue("2")
+ .equals("http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix"));
+ assertTrue("3rd rewritten anchor: " + testRewriter.getAnchorValue("3"), testRewriter.getAnchorValue("3")
+ .equals("http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix"));
+ assertTrue("4th rewritten anchor: " + testRewriter.getAnchorValue("4"), testRewriter.getAnchorValue("4")
+ .equals("javascript:whatever()"));
+ assertTrue("5th rewritten anchor: " + testRewriter.getAnchorValue("5"), testRewriter.getAnchorValue("5")
+ .equals("mailto:david@bluesunrise.com"));
+ assertTrue("6th rewritten anchor: " + testRewriter.getAnchorValue("6"), testRewriter.getAnchorValue("6")
+ .equals("#INTERNAL"));
+
+ assertTrue("Paragraph text: " + testRewriter.getParagraph(), testRewriter.getParagraph().equals(
+ "This is a test"));
+ }
+
+ /**
+ * Gets a writer for a given filename in the test directory.
+ *
+ * @return A file reader to the test rules file
+ * @throws IOException
+ */
+ private FileWriter getTestWriter(String filename) throws IOException
+ {
+ new File(getBaseDir()+"target/test/rewriter").mkdirs();
+ return new FileWriter(getBaseDir()+"target/test/rewriter/" + filename);
+ }
+
+ private RewriterController getController() throws Exception
+ {
+ Class[] rewriterClasses = new Class[] { RulesetRewriterImpl.class, RulesetRewriterImpl.class };
+ Class[] adaptorClasses = new Class[] { SwingParserAdaptor.class, SaxParserAdaptor.class };
+ return new MappingRewriterController(getBaseDir()+"src/test/webapp/WEB-INF/conf/rewriter-rules-mapping.xml", Arrays
+ .asList(rewriterClasses), Arrays.asList(adaptorClasses));
+ }
+}
Added: portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/UnitTestRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/UnitTestRewriter.java?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/UnitTestRewriter.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/java/org/apache/portals/applications/webcontent2/portlet/rewriter/UnitTestRewriter.java Sun Aug 17 22:58:18 2014
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.portlet.rewriter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * TestRewriter
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: UnitTestRewriter.java 764612 2009-04-13 21:17:59Z taylor $
+ */
+public class UnitTestRewriter extends BasicRewriter
+{
+ private Map anchors = new HashMap();
+ private String paragraph = null;
+ private boolean inParagraph = false;
+
+ public String getAnchorValue(String name)
+ {
+ return (String)anchors.get(name);
+ }
+
+ public String getParagraph()
+ {
+ return paragraph;
+ }
+
+ public boolean enterStartTagEvent(String tag, MutableAttributes attrs)
+ {
+ if (tag.equalsIgnoreCase("a"))
+ {
+ anchors.put(attrs.getValue("name"), attrs.getValue("href"));
+ }
+ if (tag.equalsIgnoreCase("p"))
+ {
+ inParagraph = true;
+ }
+
+ return true;
+ }
+
+ public boolean enterText(char[] values, int param)
+ {
+ if (inParagraph)
+ {
+ paragraph = new String(values);
+ }
+
+ return true;
+ }
+
+ public String exitEndTagEvent(String tag)
+ {
+ inParagraph = false;
+ return "";
+ }
+}
Added: portals/applications/webcontent/trunk/portlets/src/test/rewriter/default-rewriter-rules.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/rewriter/default-rewriter-rules.xml?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/rewriter/default-rewriter-rules.xml (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/rewriter/default-rewriter-rules.xml Sun Aug 17 22:58:18 2014
@@ -0,0 +1,75 @@
+<?xml version='1.0' ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<ruleset id='test-set-102' remove-comments='false'>
+
+<!-- standard rewriter link rules -->
+<rule id='base' use-base='true' ignore-prefixes='javascript:,mailto:,#'/>
+
+<!-- remove tags -->
+<tag id='html' remove='true'/>
+<tag id='frameset' remove='true'/>
+<tag id='frame' remove='true'/>
+<tag id='noframes' remove='true'/>
+<tag id='body' remove='true'/>
+
+<!-- strip tags -->
+<tag id='head' strip='true'/>
+
+<!-- rewritten tags -->
+<tag id='a'>
+ <attribute id='href' rule='base'/>
+</tag>
+<tag id='link'>
+ <attribute id='href' rule='base'/>
+</tag>
+<tag id='img'>
+ <attribute id='src' rule='base'/>
+</tag>
+<tag id='input'>
+ <attribute id='src' rule='base'/>
+</tag>
+<tag id='option'>
+ <attribute id='value' rule='base'/>
+</tag>
+<tag id='applet'>
+ <attribute id='codebase' rule='base'/>
+</tag>
+<tag id='frame'>
+ <attribute id='src' rule='base'/>
+</tag>
+<tag id='script'>
+ <attribute id='src' rule='base'/>
+</tag>
+<tag id='form'>
+ <attribute id='action' rule='base'/>
+</tag>
+<tag id='area'>
+ <attribute id='href' rule='base'/>
+</tag>
+<tag id='body'>
+ <attribute id='background' rule='base'/>
+</tag>
+<tag id='td'>
+ <attribute id='background' rule='base'/>
+</tag>
+
+<!-- sample rules -->
+<rule id='portal-popup' popup='true' use-base='true' suffix='/portal' ignore-prefixes='javascript:,mailto:'/>
+<rule id='test' use-base='false' suffix='/whatever&xxx=1' popup='1'/>
+
+</ruleset>
Added: portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-001.html
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-001.html?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-001.html (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-001.html Sun Aug 17 22:58:18 2014
@@ -0,0 +1,49 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<HTML>
+<!--
+ comments
+ -->
+<HEaD>
+ <base href="http://localhost">
+ <link href="/css/which.css" type="text/css" rel="stylesheet">
+ <title>Administration Centre</title>
+<SCRIPT LANGUAGE="javascript">
+function CTF_launchPreview(URL)
+{
+ day = new Date();
+ id = day.getTime();
+ eval("page" + id + " = window.open(URL, '" + id+"','scrollbars=yes,width=500,height=500,resizable=yes');");
+}
+<!--
+function test(URL)
+{
+ day = new Date();
+}
+-->
+</SCRIPT>
+</heAd>
+<body>
+<p>This is a test</p>
+<a name='1' href="http://www.bluesunrise.com">keep this</a>
+<a name='2' href="/stuff/junk/stuffedjunk.html">junk</a>
+<a name='3' href="stuff/junk/stuffedjunk.html">junk2</a>
+<a name='4' href="javascript:whatever()">script</a>
+<a name='5' href="mailto:david@bluesunrise.com">script</a>
+<a name='6' href="#INTERNAL">internal</a>
+</body>
+</HTML>
\ No newline at end of file
Added: portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-remove-rules.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-remove-rules.xml?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-remove-rules.xml (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-remove-rules.xml Sun Aug 17 22:58:18 2014
@@ -0,0 +1,27 @@
+<?xml version='1.0' ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<ruleset id='test-set-102' remove-comments='true'>
+<rule id='base' popup='true' use-base='true' suffix='/suffix' ignore-prefixes='javascript:,mailto:,#'/>
+<tag id='HTML' remove='true'/>
+<tag id='body' remove='true'/>
+<tag id='head' strip='true'/>
+<tag id='a'>
+ <attribute id='href' rule='base'/>
+</tag>
+</ruleset>
+
Added: portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-rewriter-rules.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-rewriter-rules.xml?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-rewriter-rules.xml (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/rewriter/test-rewriter-rules.xml Sun Aug 17 22:58:18 2014
@@ -0,0 +1,31 @@
+<?xml version='1.0' ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<ruleset id='test-set-101'>
+<rule id='merge' use-base='true' suffix='/web' popup='0' ignore-prefixes='javascript:,mailto:,#'/>
+<tag id='form'>
+ <attribute id='action' rule='merge'/>
+</tag>
+<tag id='input'>
+ <attribute id='source' rule='test'/>
+</tag>
+<tag id='link'>
+ <attribute id='href' rule='merge'/>
+</tag>
+<tag id='head' remove='true'/>
+<rule id='test' use-base='false' suffix='/whatever&xxx=1' popup='1'/>
+</ruleset>
Added: portals/applications/webcontent/trunk/portlets/src/test/webapp/WEB-INF/conf/rewriter-rules-mapping.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/test/webapp/WEB-INF/conf/rewriter-rules-mapping.xml?rev=1618527&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/test/webapp/WEB-INF/conf/rewriter-rules-mapping.xml (added)
+++ portals/applications/webcontent/trunk/portlets/src/test/webapp/WEB-INF/conf/rewriter-rules-mapping.xml Sun Aug 17 22:58:18 2014
@@ -0,0 +1,105 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<mapping>
+ <class name="org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl.RulesetImpl">
+ <map-to xml="ruleset"/>
+
+ <field name="id" type="java.lang.String">
+ <bind-xml name="id" node="attribute"/>
+ </field>
+
+ <field name="removeComments" type="boolean">
+ <bind-xml name="remove-comments" node="attribute"/>
+ </field>
+
+ <field name="tags"
+ type="org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl.TagImpl"
+ collection="collection">
+ <bind-xml name="tag"/>
+ </field>
+
+ <field name="rules"
+ type="org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl.RuleImpl"
+ collection="collection">
+ <bind-xml name="rule"/>
+ </field>
+
+ </class>
+
+ <class name="org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl.TagImpl">
+ <map-to xml="tag"/>
+
+ <field name="id" type="java.lang.String">
+ <bind-xml name="id" node="attribute"/>
+ </field>
+
+ <field name="strip" type="boolean">
+ <bind-xml name="strip" node="attribute"/>
+ </field>
+
+ <field name="remove" type="boolean">
+ <bind-xml name="remove" node="attribute"/>
+ </field>
+
+ <field name="attributes"
+ type="org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl.AttributeImpl"
+ collection="collection">
+ <bind-xml name="attribute"/>
+ </field>
+
+ </class>
+
+ <class name="org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl.RuleImpl">
+ <map-to xml="rule"/>
+
+ <field name="id" type="java.lang.String">
+ <bind-xml name="id" node="attribute"/>
+ </field>
+
+ <field name="suffix" type="java.lang.String">
+ <bind-xml name="suffix" node="attribute"/>
+ </field>
+
+ <field name="ignorePrefixes" type="java.lang.String">
+ <bind-xml name="ignore-prefixes" node="attribute"/>
+ </field>
+
+ <field name="useBase" type="boolean">
+ <bind-xml name="use-base" node="attribute"/>
+ </field>
+
+ <field name="popup" type="boolean">
+ <bind-xml name="popup" node="attribute"/>
+ </field>
+
+ </class>
+
+ <class name="org.apache.portals.applications.webcontent2.portlet.rewriter.rules.impl.AttributeImpl">
+ <map-to xml="attribute"/>
+
+ <field name="id" type="java.lang.String">
+ <bind-xml name="id" node="attribute"/>
+ </field>
+
+ <field name="ruleId" type="java.lang.String">
+ <bind-xml name="rule" node="attribute"/>
+ </field>
+
+ </class>
+
+</mapping>
\ No newline at end of file
Modified: portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/classes/log4j.properties
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/classes/log4j.properties?rev=1618527&r1=1618526&r2=1618527&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/classes/log4j.properties (original)
+++ portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/classes/log4j.properties Sun Aug 17 22:58:18 2014
@@ -48,28 +48,28 @@ log4j.category.org.apache.http.wire = ER
########################################################################
#
-# webcontent.log
+# webcontent2.log
#
log4j.appender.pa = org.apache.log4j.FileAppender
-log4j.appender.pa.file = ${org.apache.portals.logdir}/webcontent.log
+log4j.appender.pa.file = ${org.apache.portals.logdir}/webcontent2.log
log4j.appender.pa.layout = org.apache.log4j.PatternLayout
log4j.appender.pa.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.pa.append = false
#
-# webcontent-velocity.log
+# webcontent2-velocity.log
#
log4j.appender.velocity = org.apache.log4j.FileAppender
-log4j.appender.velocity.file = ${org.apache.portals.logdir}/webcontent-velocity.log
+log4j.appender.velocity.file = ${org.apache.portals.logdir}/webcontent2-velocity.log
log4j.appender.velocity.layout = org.apache.log4j.PatternLayout
log4j.appender.velocity.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.velocity.append = false
#
-# webcontent-httpclient.log
+# webcontent2-httpclient.log
#
log4j.appender.httpclient = org.apache.log4j.FileAppender
-log4j.appender.httpclient.file = ${org.apache.portals.logdir}/webcontent-httpclient.log
+log4j.appender.httpclient.file = ${org.apache.portals.logdir}/webcontent2-httpclient.log
log4j.appender.httpclient.layout = org.apache.log4j.PatternLayout
log4j.appender.httpclient.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.httpclient.append = false
Modified: portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/portlet.xml?rev=1618527&r1=1618526&r2=1618527&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/portlet.xml (original)
+++ portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/portlet.xml Sun Aug 17 22:58:18 2014
@@ -14,7 +14,7 @@
License for the specific language governing permissions and
limitations under the License.
-->
-<portlet-app id='webcontent'
+<portlet-app id='webcontent2'
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
@@ -23,8 +23,8 @@
<description>Places an HTML IFrame inside a portlet for easily
hosting other web application within a portlet. Sizes of both
normal and maximized modes are configurable in edit mode.</description>
- <portlet-name>IFramePortlet</portlet-name>
- <display-name>IFrame Portlet</display-name>
+ <portlet-name>IFramePortlet2</portlet-name>
+ <display-name>IFrame Portlet 2</display-name>
<portlet-class>
org.apache.portals.applications.webcontent2.portlet.IFrameGenericPortlet</portlet-class>
<init-param>
@@ -48,8 +48,8 @@
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
- <title>IFrame</title>
- <short-title>IFrame</short-title>
+ <title>IFrame2</title>
+ <short-title>IFrame2</short-title>
<keywords>tool,iframe,web,frame,content,host</keywords>
</portlet-info>
<portlet-preferences>
@@ -107,8 +107,8 @@
<description>Places an HTML IFrame with reverse proxied url inside a portlet for easily
hosting other web application within a portlet. Sizes of both
normal and maximized modes are configurable in edit mode.</description>
- <portlet-name>ReverseProxyIFramePortlet</portlet-name>
- <display-name>ReverseProxy IFrame Portlet</display-name>
+ <portlet-name>ReverseProxyIFramePortlet2</portlet-name>
+ <display-name>ReverseProxy IFrame Portlet2</display-name>
<portlet-class>
org.apache.portals.applications.webcontent2.portlet.IFrameGenericPortlet</portlet-class>
<init-param>
@@ -132,8 +132,8 @@
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
- <title>ReverseProxyIFrame</title>
- <short-title>ReverseProxyIFrame</short-title>
+ <title>ReverseProxyIFrame2</title>
+ <short-title>ReverseProxyIFrame2</short-title>
<keywords>tool,reverse,proxy,iframe,web,frame,content,host</keywords>
</portlet-info>
<portlet-preferences>
@@ -148,17 +148,17 @@
<preference>
<name>SRC</name>
<!-- <value>http://portals.apache.org/</value> -->
- <value>http://localhost:${serverPort}/webcontent/examples/mission.html</value>
+ <value>http://localhost:${serverPort}/webcontent2/examples/mission.html</value>
</preference>
<preference>
<name>PROXYREMOTEURL</name>
<!-- <value>http://portals.apache.org/</value> -->
- <value>http://localhost:${serverPort}/webcontent/examples/</value>
+ <value>http://localhost:${serverPort}/webcontent2/examples/</value>
</preference>
<preference>
<name>PROXYLOCALPATH</name>
<!-- <value>${contextPath}/rproxy/portals_apache/</value> -->
- <value>${contextPath}/rproxy/localhost_${serverPort}/webcontent/examples/</value>
+ <value>${contextPath}/rproxy/localhost_${serverPort}/webcontent2/examples/</value>
</preference>
<preference>
<name>AUTORESIZE</name>
@@ -198,8 +198,8 @@
<portlet>
<description>Includes the content of another website inside the portal without using frames. All links are rewritten back to the portal to attempt to proxy all content through the portal.</description>
- <portlet-name>WebContentPortlet</portlet-name>
- <display-name>WebContent Portlet</display-name>
+ <portlet-name>WebContentPortlet2</portlet-name>
+ <display-name>WebContent Portlet2</display-name>
<portlet-class>org.apache.portals.applications.webcontent2.portlet.WebContentPortlet</portlet-class>
<init-param>
<name>EditPage</name>
@@ -208,7 +208,7 @@
<init-param>
<name>portlet-icon</name>
<value>preferences-system-network-proxy.png</value>
- </init-param>
+ </init-param>
<expiration-cache>-1</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
@@ -217,8 +217,8 @@
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
- <title>WebContent Prototype</title>
- <short-title>WebContent</short-title>
+ <title>WebContent Prototype 2</title>
+ <short-title>WebContent2</short-title>
<keywords>web,content,webnav,bridge,proxy,rewrite</keywords>
</portlet-info>
<portlet-preferences>
Modified: portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/web.xml?rev=1618527&r1=1618526&r2=1618527&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/web.xml (original)
+++ portals/applications/webcontent/trunk/war/src/main/webapp/WEB-INF/web.xml Sun Aug 17 22:58:18 2014
@@ -18,8 +18,8 @@
version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>Webcontent Portlet Application</display-name>
- <description>Apache Portals Applications: Webcontent PA</description>
+ <display-name>Webcontent Portlet Application 2</display-name>
+ <description>Apache Portals Applications: Webcontent 2 PA</description>
<!--
for deploying on Websphere: disable Websphere default
@@ -50,14 +50,18 @@
<!-- Default Reverse Proxy Servlet -->
<servlet>
<servlet-name>ReverseProxyServlet</servlet-name>
- <servlet-class>org.apache.portals.applications.webcontent2.proxy.impl.DefaultHttpReverseProxyServlet</servlet-class>
+ <servlet-class>org.apache.portals.applications.webcontent2.proxy.servlet.SimpleReverseProxyServlet</servlet-class>
<init-param>
- <param-name>reverseproxy.configuration</param-name>
- <param-value>/WEB-INF/conf/reverseproxy*.properties</param-value>
- </init-param>
- <init-param>
- <param-name>reverseproxy.configuration.refresh.delay</param-name>
- <param-value>60000</param-value>
+ <param-name>mappings</param-name>
+ <param-value>
+--- !simple
+local: /applications/
+remote: http://portals.apache.org/applications/
+
+--- !simple
+local: /bridges/
+remote: http://portals.apache.org/bridges/
+ </param-value>
</init-param>
<load-on-startup>11</load-on-startup>
</servlet>