View Javadoc

1   /* Copyright 2004 Apache Software Foundation
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.apache.portals.bridges.perl;
16  
17  
18  import javax.portlet.PortletURL;
19  
20  import org.apache.jetspeed.rewriter.Rewriter;
21  import org.apache.jetspeed.rewriter.RulesetRewriterImpl;
22  
23  /***
24   * PerlContentRewriter
25   * 
26   * @author <a href="mailto:rogerrutr@apache.org">Roger Ruttimann </a>
27   * @version $Id: PerlContentRewriter.java 188406 2005-03-21 18:31:11 +0100 (Mon, 21 Mar 2005) rogerrut $
28   */
29  public class PerlContentRewriter extends RulesetRewriterImpl implements
30          Rewriter {
31  
32      /*** WebContentURL */
33      public static final String ACTION_PARAMETER_URL = "WCURL";
34  
35      /* Portlet URL will be used to replace all URL's */
36      private PortletURL actionURL = null;
37  
38      /* Parameter name attached to action */
39      private String actionParameterName = null;
40  
41      /*
42       * LocalhostIP Some perl script refer to localhost which doesn't work for
43       * remote connections. The rewriter will replace any localhost references
44       * with the IP address
45       */
46      private String localHostIP = null;
47  
48      /***
49       * Setters/getters for members
50       */
51      public void setActionURL(PortletURL action) {
52          this.actionURL = action;
53      }
54  
55      public PortletURL getActionURL() {
56          return this.actionURL;
57      }
58  
59      /***
60       * @return Returns the localHostIP.
61       */
62      public String getLocalHostIP() {
63          return localHostIP;
64      }
65  
66      /***
67       * @param localHostIP
68       *                    The localHostIP to set.
69       */
70      public void setLocalHostIP(String localHostIP) {
71          this.localHostIP = localHostIP;
72      }
73  
74      /***
75       * @return Returns the actionParameterName.
76       */
77      public String getActionParameterName() {
78          return actionParameterName;
79      }
80  
81      /***
82       * @param actionParameterName
83       *                    The actionParameterName to set.
84       */
85      public void setActionParameterName(String actionParameterName) {
86          this.actionParameterName = actionParameterName;
87      }
88  
89      /***
90       * rewriteURL
91       * 
92       * @param url
93       * @param tag
94       * @param attribute
95       * @return the modified url which is a portlet action
96       * 
97       * Rewrites all URL's in the perl script with portlet actions. Tags include
98       * A (AREA) and FORM and replaces any localhost with the real IP address if
99       * provided
100      */
101     public String rewriteUrl(String url, String tag, String attribute) {
102         String modifiedURL = url;
103         // TODO: Remove debug
104         System.out.println("Perl HTML output TAG = " + tag + " Attribute = " + attribute);
105 
106         // For now only add PortletActions to URL's which are anchors (tag=a) or
107         // FORMS and HREF's (attribute= HREF) -- ignore all others links
108         if ((		tag.compareToIgnoreCase("A") == 0
109                 ||  tag.compareToIgnoreCase("FORM") == 0)
110                 && attribute.compareToIgnoreCase("HREF") == 0) {
111             // Regular URL just add a portlet action
112             if (this.actionURL != null) {
113                 // create Action URL
114                 actionURL.setParameter(actionParameterName, modifiedURL);
115                 modifiedURL = actionURL.toString();
116             }
117         }
118 
119         return modifiedURL;
120     }
121 
122     /*
123      * (non-Javadoc)
124      * 
125      * @see org.apache.jetspeed.rewriter.Rewriter#shouldRemoveTag(java.lang.String)
126      */
127     /*
128      * public boolean shouldRemoveTag(String tag) { if
129      * (tag.equalsIgnoreCase("html")) { return true; } return false; }
130      */
131 
132     /*
133      * (non-Javadoc)
134      * 
135      * @see org.apache.jetspeed.rewriter.Rewriter#shouldStripTag(java.lang.String)
136      */
137     /*
138      * public boolean shouldStripTag(String tag) { if
139      * (tag.equalsIgnoreCase("head")) { return true; } return false; }
140      */
141 
142     /*
143      * (non-Javadoc)
144      * 
145      * @see org.apache.jetspeed.rewriter.Rewriter#shouldRemoveComments()
146      */
147     /*
148      * public boolean shouldRemoveComments() { return true; }
149      */
150 
151 }