View Javadoc

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