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 ta...@apache.org on 2009/04/13 23:18:01 UTC

svn commit: r764612 [2/5] - in /portals/applications/webcontent: ./ trunk/ trunk/webcontent-jar/ trunk/webcontent-jar/src/ trunk/webcontent-jar/src/main/ trunk/webcontent-jar/src/main/java/ trunk/webcontent-jar/src/main/java/org/ trunk/webcontent-jar/s...

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentResource.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentResource.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentResource.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentResource.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,93 @@
+/*
+ * 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.webcontent.portlet;
+
+import java.io.Serializable;
+
+/**
+ * A cached resource object, stored in memory to optimize access to static resources
+ * such as images and style sheets.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$ 
+ */
+
+public class WebContentResource implements Serializable
+{
+    private transient byte[] content = null;
+    private String url = null;
+    private String lastUrl = null;
+
+    /**
+     * Constructor for a cached resource. 
+     *
+     * @param contentType The HTTP content type for a cached resource as defined 
+     *        in WebPageHelper, i.e. WebPageHelper.CT_HTML, WebPageHelper.CT_IMAGE....
+     * @param content The byte array of content this cached. This content can be
+     *         binary images, or static text such as scripts and style sheets.
+     *         
+     */
+    public WebContentResource(String url, byte[] content)
+    {
+        this.url = url;
+        if (content != null)
+        {
+            this.content = new byte[content.length];
+            System.arraycopy(content, 0, this.content, 0, this.content.length);
+        }
+    }
+
+    /**
+     * Gets the content of this resource in a byte array.
+     *
+     * @return A byte array of the resource's content.
+     */
+    public byte[] getContent()
+    {
+        return content;
+    }
+
+
+    /**
+     * @return Returns the lastUrl.
+     */
+    public String getLastUrl()
+    {
+        return lastUrl;
+    }
+    /**
+     * @param lastUrl The lastUrl to set.
+     */
+    public void setLastUrl(String lastUrl)
+    {
+        this.lastUrl = lastUrl;
+    }
+    /**
+     * @return Returns the url.
+     */
+    public String getUrl()
+    {
+        return url;
+    }
+    /**
+     * @param url The url to set.
+     */
+    public void setUrl(String url)
+    {
+        this.url = url;
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/WebContentResource.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/AbstractRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/AbstractRewriter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/AbstractRewriter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/AbstractRewriter.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,125 @@
+/*
+ * 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.webcontent.rewriter;
+
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+/**
+ * AbstractRewriter
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public abstract class AbstractRewriter implements Rewriter
+{
+    protected final static Log log = LogFactory.getLog(AbstractRewriter.class);
+    
+    private String baseUrl = null;
+    private boolean useProxy = false; 
+        
+    public void parse(ParserAdaptor adaptor, Reader reader) throws RewriterException
+    {
+        adaptor.parse(this, reader);        
+    }
+    
+    public void rewrite(ParserAdaptor adaptor, Reader reader, Writer writer) throws RewriterException
+    {
+        adaptor.rewrite(this, reader, writer);        
+    }
+    
+    public abstract String rewriteUrl(String url, String tag, String attribute);
+    
+    public void setBaseUrl(String base)
+    {
+        this.baseUrl = base;
+    }
+    
+    public String getBaseUrl()
+    {
+        return baseUrl;
+    }
+    public String getBaseRelativeUrl(String relativeUrl)
+    {        
+        try
+        {
+            String baseUrl = getBaseUrl();
+            if (baseUrl != null)
+            {
+                URL xlate = new URL(new URL(baseUrl), relativeUrl);
+                return xlate.toString();
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("Unable to translate URL relative to base URL", e);
+        }
+        return relativeUrl;
+    }
+    
+    public boolean getUseProxy()
+    {
+        return useProxy;
+    }
+    
+    public void setUseProxy(boolean useProxy)
+    {
+        this.useProxy = useProxy;        
+    }
+    
+    public boolean enterSimpleTagEvent(String tag, MutableAttributes attrs)
+    {
+        return true;
+    }
+    
+    public String exitSimpleTagEvent(String tag, MutableAttributes attrs)
+    {
+        return null;
+    }
+    
+    public boolean enterStartTagEvent(String tag, MutableAttributes attrs)
+    {
+        return true;
+    }
+    
+    public String exitStartTagEvent(String tag, MutableAttributes attrs)
+    {
+        return null;
+    }
+    
+    public boolean enterEndTagEvent(String tag)
+    {
+        return true;
+    }
+    
+    public String exitEndTagEvent(String tag)
+    {
+        return null;
+    }
+    
+    public boolean enterText(char[] values, int param)
+    {
+        return true;
+    }
+
+    public void enterConvertTagEvent(String tag, MutableAttributes attrs)
+    {
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/AbstractRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/AbstractRewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/BasicRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/BasicRewriter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/BasicRewriter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/BasicRewriter.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,64 @@
+/*
+ * 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.webcontent.rewriter;
+
+
+/**
+ * BasicRewriter
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public class BasicRewriter extends AbstractRewriter implements Rewriter
+{
+    /*    
+     * This callback is called by the ParserAdaptor implementation to write
+     * back all rewritten URLs to point to the proxy server.
+     * Given the targetURL, rewrites the link as a link back to the proxy server.
+     *
+     * @return the rewritten URL to the proxy server.
+     *
+     */
+    public String rewriteUrl(String url, String tag, String attribute)
+    {
+        return getBaseRelativeUrl(url);
+    }
+    
+    public boolean shouldRemoveTag(String tag)
+    {
+        if (tag.equalsIgnoreCase("html"))
+        {
+            return true;
+        }
+        return false;
+    }
+
+    public boolean shouldStripTag(String tag)
+    {
+        if (tag.equalsIgnoreCase("head"))
+        {
+            return true;
+        }
+        return false;
+    }
+
+    public boolean shouldRemoveComments()
+    {
+        return true;
+    }
+    
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/BasicRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/BasicRewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingClasspathRewriterController.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingClasspathRewriterController.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingClasspathRewriterController.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingClasspathRewriterController.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.webcontent.rewriter;
+
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * RewriterServiceImpl
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: MappingRewriterController.java,v 1.2 2004/03/08 00:44:40 jford
+ *          Exp $
+ */
+public class MappingClasspathRewriterController
+       extends MappingRewriterController
+       implements RewriterController
+{
+    protected final static Log log = LogFactory.getLog(MappingClasspathRewriterController.class);
+
+    public MappingClasspathRewriterController( String mappingFile ) throws RewriterException
+    {
+        super(mappingFile);
+    }
+
+    public MappingClasspathRewriterController( String mappingFile, List rewriterClasses, List adaptorClasses )
+            throws RewriterException
+    {
+        super(mappingFile, rewriterClasses, adaptorClasses);
+    }
+    
+    public MappingClasspathRewriterController( String mappingFile, 
+            String basicRewriterClassName, String rulesetRewriterClassName, 
+            String adaptorHtmlClassName, String adaptorXmlClassName )
+    throws RewriterException
+    {
+        super(mappingFile, toClassList(basicRewriterClassName,rulesetRewriterClassName), 
+              toClassList(adaptorHtmlClassName,adaptorXmlClassName));
+    }
+    
+    protected Reader getReader(String resource)
+    throws RewriterException
+    {
+        InputStream stream = this.getClass().getClassLoader().getResourceAsStream(resource);
+        if (stream != null)
+            return new InputStreamReader(stream);
+
+        throw new RewriterException("could not access rewriter classpath resource " + resource);        
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingClasspathRewriterController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingClasspathRewriterController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,251 @@
+/*
+ * 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.webcontent.rewriter;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.applications.webcontent.rewriter.html.SwingParserAdaptor;
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
+import org.apache.portals.applications.webcontent.rewriter.xml.SaxParserAdaptor;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.xml.Unmarshaller;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+/**
+ * RewriterServiceImpl
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id$
+ *          Exp $
+ */
+public class MappingRewriterController implements RewriterController
+{
+    protected final static Log log = LogFactory.getLog(MappingRewriterController.class);
+    final static String CONFIG_MAPPING_FILE = "mapping";
+    final static String CONFIG_BASIC_REWRITER = "basic.class";
+    final static String CONFIG_RULESET_REWRITER = "ruleset.class";
+    final static String CONFIG_ADAPTOR_HTML = "adaptor.html";
+    final static String CONFIG_ADAPTOR_XML = "adaptor.xml";
+
+    // configuration parameters
+    protected String mappingFile = null;
+
+    /** the Castor mapping file name */
+    protected Mapping mapper = null;
+
+    /** Collection of rulesets in the system */
+    protected Map rulesets = Collections.synchronizedMap(new HashMap());
+
+    /** configured basic rewriter class */
+    protected Class basicRewriterClass = BasicRewriter.class;
+
+    /** configured ruleset rewriter class */
+    protected Class rulesetRewriterClass = RulesetRewriterImpl.class;
+
+    /** Adaptors */
+    protected Class adaptorHtmlClass = SwingParserAdaptor.class;
+    protected Class adaptorXmlClass = SaxParserAdaptor.class;
+
+    public MappingRewriterController( String mappingFile ) throws RewriterException
+    {
+        this.mappingFile = mappingFile;
+        loadMapping();
+    }
+
+    public MappingRewriterController( String mappingFile, List rewriterClasses, List adaptorClasses )
+            throws RewriterException
+    {
+        this.mappingFile = mappingFile;
+        if (rewriterClasses.size() > 0)
+        {
+            this.basicRewriterClass = (Class) rewriterClasses.get(0);
+            if (rewriterClasses.size() > 1)
+            {
+                this.rulesetRewriterClass = (Class) rewriterClasses.get(1);
+            }
+        }
+        if (adaptorClasses.size() > 0)
+        {
+            this.adaptorHtmlClass = (Class) adaptorClasses.get(0);
+            if (adaptorClasses.size() > 1)
+            {
+                this.adaptorXmlClass = (Class) adaptorClasses.get(1);
+            }
+        }
+
+        loadMapping();
+    }
+    
+    public MappingRewriterController( String mappingFile, String basicRewriterClassName, String rulesetRewriterClassName, 
+                    String adaptorHtmlClassName, String adaptorXmlClassName )
+    throws RewriterException
+    {
+        this(mappingFile, toClassList(basicRewriterClassName,rulesetRewriterClassName), toClassList(adaptorHtmlClassName,adaptorXmlClassName));
+    }
+
+    protected static List toClassList(String classNameA, String classNameB)
+    {
+        try
+        {
+            List list = new ArrayList(2);
+            if ( classNameA != null )
+            {
+                list.add(Class.forName(classNameA));
+            }
+            if ( classNameB != null )
+            {
+                list.add(Class.forName(classNameB));
+            }
+            return list;
+        } 
+        catch (ClassNotFoundException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }    
+
+    public Rewriter createRewriter() throws InstantiationException, IllegalAccessException
+    {
+        return (Rewriter) basicRewriterClass.newInstance();
+    }
+
+    public RulesetRewriter createRewriter( Ruleset ruleset ) throws RewriterException
+    {
+        try
+        {
+            RulesetRewriter rewriter = (RulesetRewriter) rulesetRewriterClass.newInstance();
+            rewriter.setRuleset(ruleset);
+            return rewriter;
+        }
+        catch (Exception e)
+        {
+            log.error("Error creating rewriter class", e);
+        }
+        return null;
+    }
+
+    public ParserAdaptor createParserAdaptor( String mimeType ) throws RewriterException
+    {
+        try
+        {
+            if (mimeType.equals("text/html"))
+            {
+                return (ParserAdaptor) adaptorHtmlClass.newInstance();
+            }
+            else if (mimeType.equals("text/xml"))
+            {
+                return (ParserAdaptor) adaptorXmlClass.newInstance();
+            }
+            else
+            {
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("Error creating rewriter class", e);
+        }
+        return null;
+    }
+
+    /**
+     * Load the mapping file for ruleset configuration
+     *  
+     */
+    protected void loadMapping() throws RewriterException
+    {
+        try
+        {
+            Reader reader = getReader(this.mappingFile);
+            
+            this.mapper = new Mapping();
+            InputSource is = new InputSource(reader);
+            is.setSystemId(this.mappingFile);
+            this.mapper.loadMapping(is);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            String msg = "RewriterService: Error in castor mapping creation";
+            log.error(msg, e);
+            throw new RewriterException(msg, e);
+        }
+    }
+
+    protected Reader getReader(String resource)
+    throws RewriterException
+    {
+        File file = new File(resource);
+        if (file.exists() && file.isFile() && file.canRead())
+        {
+            try
+            {
+                return new FileReader(file);
+            }
+            catch (Exception e)
+            {
+                throw new RewriterException("could not open rewriter file " + resource, e);
+            }
+        }
+        throw new RewriterException("could not access rewriter file " + resource);
+    }
+        
+    public Ruleset lookupRuleset( String id )
+    {
+        return (Ruleset) rulesets.get(id);
+    }
+
+    public Ruleset loadRuleset( Reader reader )
+    {
+        Ruleset ruleset = null;
+        try
+        {
+            DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder builder = dbfactory.newDocumentBuilder();
+
+            InputSource source = new InputSource(reader);
+
+            Document doc = builder.parse(source);
+
+            Unmarshaller unmarshaller = new Unmarshaller(this.mapper);
+
+            ruleset = (Ruleset) unmarshaller.unmarshal(doc);
+            ruleset.sync();
+            rulesets.put(ruleset.getId(), ruleset);
+
+        }
+        catch (Throwable t)
+        {
+            log.error("ForwardService: Could not unmarshal: " + reader, t);
+        }
+
+        return ruleset;
+    }
+
+}
\ No newline at end of file

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MutableAttributes.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MutableAttributes.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MutableAttributes.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MutableAttributes.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.webcontent.rewriter;
+
+import org.xml.sax.Attributes;
+
+/**
+ * MutableAttributes
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public interface MutableAttributes extends Attributes
+{
+    /**
+     * Creates a new attribute set similar to this one except that it contains
+     * an attribute with the given name and value.  The object must be
+     * immutable, or not mutated by any client.
+     *
+     * @param name the name
+     * @param value the value
+     */
+    public void addAttribute(String name, Object value);
+    
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MutableAttributes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MutableAttributes.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/ParserAdaptor.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/ParserAdaptor.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/ParserAdaptor.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/ParserAdaptor.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.webcontent.rewriter;
+
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Interface for HTML Parser Adaptors.
+ * Adaptors normalize the interface over HTML and XML adaptor implementations.
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public interface ParserAdaptor
+{
+    /**
+     * Parses a document from the reader, without actually rewriting URLs.
+     * During parsing the events are called back on the given rewriter to handle the normalized events.
+     *
+     * @param reader the input stream over the content to be parsed.
+     * @exception RewriteException when a parsing error occurs or unexpected content is found.
+     */        
+    void parse(Rewriter rewriter, Reader reader)
+            throws RewriterException;
+
+    /**
+     * Parses and rewrites a document from the reader, rewriting URLs via the rewriter's events to the writer.
+     * During parsing the rewriter events are called on the given rewriter to handle the rewriting.
+     *
+     * @param reader the input stream over the content to be parsed.
+     * @param writer the output stream where content is rewritten to.
+     * @exception RewriteException when a parsing error occurs or unexpected content is found.
+     */            
+    void rewrite(Rewriter rewriter, Reader reader, Writer writer)
+        throws RewriterException;
+    
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/ParserAdaptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/ParserAdaptor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/Rewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/Rewriter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/Rewriter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/Rewriter.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,210 @@
+/*
+ * 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.webcontent.rewriter;
+
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Rewriter
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public interface Rewriter
+{
+    /**
+     * Parses the reader of content receiving call backs for rewriter events.
+     * This method does not rewrite, but only parses. Useful for readonly operations.
+     * The configured parser can parse over different stream formats returning a
+     * normalized (org.sax.xml) attribute and element based events.
+     *
+     * @param adaptor the parser adaptor which handles generating SAX-like events called back on this object. 
+     * @param reader the input stream over the content to be parsed.
+     * @exception RewriteException when a parsing error occurs or unexpected content is found.
+     */
+    void parse(ParserAdaptor adaptor, Reader reader)
+            throws RewriterException;
+
+    /**
+     * Parses the reader of content receiving call backs for rewriter events.
+     * The content is rewritten to the output stream.
+     * The configured parser can parse over different stream formats returning a
+     * normalized (org.sax.xml) attribute and element based events. 
+     *
+     * @param adaptor the parser adaptor which handles generating SAX-like events called back on this object. 
+     * @param reader the input stream over the content to be parsed.
+     * @param writer the output stream where content is rewritten to.
+     * @exception RewriteException when a parsing error occurs or unexpected content is found.
+     */                               
+    void rewrite(ParserAdaptor adaptor, Reader reader, Writer writer)
+        throws RewriterException;
+                                       
+
+    /** 
+     * This event is the inteface between the Rewriter and ParserAdaptor for rewriting URLs.
+     * The ParserAdaptor calls back the Rewriter when it finds a URL that is a candidate to be
+     * rewritten. The Rewriter rewrites the URL and returns it as the result of this function. 
+     * 
+     * @param url the URL to be rewritten
+     * @param tag The tag being processed
+     * @param attribute The current attribute being processsed
+     */
+    String rewriteUrl(String url, String tag, String attribute);
+
+    /**
+     * Returns true if the tag should be removed, otherwise false.
+     * Removing a tag only removes the tag but not the contents in 
+     * between the start and end tag.
+     * 
+     * @return true if the tag should be removed.
+     */
+    boolean shouldRemoveTag(String tag);
+
+    /**
+     * Returns true if the tag should be stripped, otherwise false.
+     * Stripping tags removes the start and end tag, plus all tags
+     * and content in between the start and end tag.
+     * 
+     * @return true if the tag should be stripped.
+     */
+    boolean shouldStripTag(String tag);
+
+    /**
+     * Returns true if all comments should be removed.
+     * 
+     * @return true If all comments should be removed.
+     */    
+    boolean shouldRemoveComments();
+    
+    /**
+     * Sets the base URL for rewriting. This URL is the base 
+     * from which other URLs are generated.
+     * 
+     * @param base The base URL for this rewriter
+     */
+    void setBaseUrl(String base);
+    
+    /**
+     * Gets the base URL for rewriting. This URL is the base 
+     * from which other URLs are generated.
+     * 
+     * @return The base URL for this rewriter
+     */
+    String getBaseUrl();
+    
+    /**
+     * Gets a new URL relative to Base according to the site / and URL
+     * rewriting rules of java.net.URL
+     * 
+     * @return The new URL from path, relative to the base URL (or path, if path is absolute)
+     */
+    String getBaseRelativeUrl(String path);
+    
+    /**
+     * Gets whether this rewriter require a proxy server.
+     * 
+     * @return true if it requires a proxy
+     */
+    boolean getUseProxy();
+    
+    /**
+     * Set whether this rewriter require a proxy server.
+     * 
+     * @param useProxy true if it requires a proxy
+     */    
+    void setUseProxy(boolean useProxy);
+    
+    /**
+     * Rewriter event called back on the leading edge of processing a simple tag by the ParserAdaptor.
+     * Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.
+     * 
+     * @param tag The name of the tag being processed.
+     * @param attrs The attribute list for the tag.
+     * @return Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.
+     */
+    boolean enterSimpleTagEvent(String tag, MutableAttributes attrs);
+    
+    /**
+     * Rewriter event called back on the trailing edge of a simple tag by the ParserAdaptor.
+     * Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available. 
+     *  
+     * @param tag The name of the tag being processed.
+     * @param attrs The attribute list for the tag.
+     * @return Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.
+     */    
+    String exitSimpleTagEvent(String tag, MutableAttributes attrs);
+
+    /**
+     * Rewriter event called back on the leading edge of processing a start tag by the ParserAdaptor.
+     * Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.
+     * 
+     * @param tag The name of the tag being processed.
+     * @param attrs The attribute list for the tag.
+     * @return Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.
+     */
+    boolean enterStartTagEvent(String tag, MutableAttributes attrs);
+    
+    /**
+     * Rewriter event called back on the trailing edge of a start tag by the ParserAdaptor.
+     * Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available. 
+     *  
+     * @param tag The name of the tag being processed.
+     * @param attrs The attribute list for the tag.
+     * @return Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.
+     */        
+    String exitStartTagEvent(String tag, MutableAttributes attrs);
+
+    /**
+     * Rewriter event called back on the leading edge of processing an end tag by the ParserAdaptor.
+     * Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.
+     * 
+     * @param tag The name of the tag being processed.
+     * @param attrs The attribute list for the tag.
+     * @return Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.
+     */
+    boolean enterEndTagEvent(String tag);
+
+    /**
+     * Rewriter event called back on the trailing edge of a end tag by the ParserAdaptor.
+     * Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available. 
+     *  
+     * @param tag The name of the tag being processed.
+     * @param attrs The attribute list for the tag.
+     * @return Returns a String that can be appended to the rewritten output for the given tag, or null to indicate no content available.
+     */            
+    String exitEndTagEvent(String tag);
+
+    /**
+     * Rewriter event called back when text is found for 
+     * Returns false to indicate to the ParserAdaptor to short-circuit processing on this tag.
+     * 
+     * @param values an array of characters containing the text.
+     * @param param 
+     * @return Should return true to continue processing the tag in the ParserAdaptor, false to indicate that processing is completed.
+     */
+    boolean enterText(char[] values, int param);
+
+    /**
+     * Rewriter event called back just before tag conversion (rewriter callbacks) begins by the ParserAdaptor.
+     * 
+     * @param tag The name of the tag being processed.
+     * @param attrs The attribute list for the tag.
+     */
+    void enterConvertTagEvent(String tag, MutableAttributes attrs);
+    
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/Rewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/Rewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterController.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterController.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterController.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterController.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,84 @@
+/*
+ * 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.webcontent.rewriter;
+
+import java.io.Reader;
+
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
+
+/**
+ * RewriterService
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public interface RewriterController 
+{
+    public String SERVICE_NAME = "rewriter";
+
+    /**
+     * Creates a basic rewriter that does not support rulesets configurations.
+     * The Rewriter implementation is configured in the service configuration.
+     *  
+     * @return A new rewriter that does not support rulesets.
+     * @throws InstantiationException
+     * @throws 
+     * @throws IllegalAccessException
+     */
+    Rewriter createRewriter()
+        throws IllegalAccessException, InstantiationException;
+
+    /**
+     * Creates a rewriter that supports rulesets configurations.
+     * The rewriter uses the rulesets configuration to control rewriting.
+     * The Rewriter implementation is configured in the service configuration.
+     * 
+     * @param ruleset The ruleset configuration to control the rewriter.
+     * @return A new rewriter that supports rulesets.
+     */
+    RulesetRewriter createRewriter(Ruleset ruleset)
+        throws RewriterException;
+    
+
+    /**
+     * Creates a Parser Adaptor for the given mime type
+     * The Parser Adaptor implementation is configured in the service configuration.
+     * Only MimeTypes of "text/html" and "text/xml" are currently supported.
+     * 
+     * @param mimeType The mimetype to create a parser adaptor for.
+     * @return A new parser adaptor
+     */
+    ParserAdaptor createParserAdaptor(String mimeType)
+        throws RewriterException;
+    
+    /**
+     * Loads a XML-based Rewriter Ruleset given a stream to the XML configuration.
+     * 
+     * @param reader The stream to the XML configuration.
+     * @return A Ruleset configuration tree.
+     */
+    Ruleset loadRuleset(Reader reader);
+       
+    /**
+     * Lookup a Ruleset given a ruleset identifier.
+     * 
+     * @param id The identifier for the Ruleset.
+     * @return A Ruleset configuration tree.
+     */
+    Ruleset lookupRuleset(String id);
+    
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterException.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterException.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterException.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterException.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter;
+
+/**
+ * RewriterException
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public class RewriterException extends Exception
+{
+    /**
+     * Constructs a new <code>RewriterException</code> without specified detail
+     * message.
+     */
+    public RewriterException()
+    {
+    }
+
+    /**
+     * Constructs a new <code>RewriterException</code> with specified detail
+     * message.
+     *
+     * @param msg the error message.
+     */
+    public RewriterException(String msg)
+    {
+        super(msg);
+    }
+
+    /**
+     * Constructs a new <code>RewriterException</code> with specified nested
+     * <code>Throwable</code>.
+     *
+     * @param nested the exception or error that caused this exception
+     *               to be thrown.
+     */
+    public RewriterException(Throwable nested)
+    {
+        super(nested);
+    }
+
+    /**
+     * Constructs a new <code>RewriterException</code> with specified detail
+     * message and nested <code>Throwable</code>.
+     *
+     * @param msg the error message.
+     * @param nested the exception or error that caused this exception
+     *               to be thrown.
+     */
+    public RewriterException(String msg, Throwable nested)
+    {
+        super(msg, nested);
+    }
+    
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RewriterException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriter.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter;
+
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
+
+/**
+ * RulesetRewriter
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public interface RulesetRewriter extends Rewriter
+{
+    /**
+     * Set the Ruleset configuration for this rewriter.
+     * 
+     * @param ruleset The Ruleset configuration.
+     */
+    void setRuleset(Ruleset ruleset);
+
+    /**
+     * Get the Ruleset configuration for this rewriter.
+     * 
+     * @return The Ruleset configuration.
+     */    
+    Ruleset getRuleset();
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriterImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriterImpl.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriterImpl.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriterImpl.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,160 @@
+/*
+ * 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.webcontent.rewriter;
+
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.portals.applications.webcontent.rewriter.rules.Attribute;
+import org.apache.portals.applications.webcontent.rewriter.rules.Rule;
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
+import org.apache.portals.applications.webcontent.rewriter.rules.Tag;
+
+
+/**
+ * RuleBasedRewriter
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public class RulesetRewriterImpl extends BasicRewriter implements RulesetRewriter
+{
+    protected final static Log log = LogFactory.getLog(RulesetRewriterImpl.class);
+    
+    private Ruleset ruleset = null;
+    private boolean removeComments = false;
+
+    public boolean shouldStripTag(String tagid)
+    {        
+        if (null == ruleset)
+        {
+            return false;
+        }
+        
+        Tag tag = ruleset.getTag(tagid.toUpperCase());
+        if (null == tag)
+        {
+            return false;
+        }
+        return tag.getStrip();        
+    }
+            
+    public boolean shouldRemoveTag(String tagid)
+    {        
+        if (null == ruleset)
+        {
+            return false;
+        }
+        
+        Tag tag = ruleset.getTag(tagid.toUpperCase());
+        if (null == tag)
+        {
+            return false;
+        }
+        return tag.getRemove();
+    }
+
+    public void setRuleset(Ruleset ruleset)
+    {
+        this.ruleset = ruleset;
+    }
+    
+    public Ruleset getRuleset()
+    {
+        return this.ruleset;
+    }
+
+    public boolean shouldRemoveComments()
+    {
+        if (null == ruleset)
+        {
+            return false;
+        }
+        
+        return ruleset.getRemoveComments();                
+    }
+
+    public void enterConvertTagEvent(String tagid, MutableAttributes attributes)
+    {
+        if (null == ruleset)
+        {
+            return;
+        }
+        
+         Tag tag = ruleset.getTag(tagid.toUpperCase());
+        if (null == tag)
+        {
+             return;
+        }
+
+        Iterator attribRules = tag.getAttributes().iterator();
+        while (attribRules.hasNext())
+        {
+            Attribute attribute = (Attribute)attribRules.next();
+            String name = attribute.getId();
+            String value = attributes.getValue(name);
+ 
+            if (value != null) // && name.equalsIgnoreCase(attribute.getId()))
+            {
+                Rule rule = attribute.getRule();
+                if (null == rule)
+                {
+                    continue;
+                }
+                
+                if (!rule.shouldRewrite(value))
+                {
+                    continue;
+                }                                        
+                
+                String rewritten = rewriteUrl(value, tag.getId(), name, attributes);
+                if (null != rewritten) // return null indicates "don't rewrite" 
+                {
+                    if (rule.getSuffix() != null)
+                    {
+                        rewritten = rewritten.concat(rule.getSuffix());
+                    }
+                    
+                    attributes.addAttribute(name, rewritten);
+                                        
+                    if (rule.getPopup())
+                    {
+                        attributes.addAttribute("TARGET", "_BLANK");                        
+                    }
+                }
+            }            
+        }
+    }
+    
+    /**
+     * rewriteURL
+     * 
+     * @param url
+     * @param tag
+     * @param attribute
+     * @param otherAttributes
+     * @return the modified url which is a portlet action
+     * 
+     * Rewrites all urls HREFS with a portlet action
+     */
+    public String rewriteUrl(String url, String tag, String attribute, MutableAttributes otherAttributes)
+    {
+        return getBaseRelativeUrl(url);
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/RulesetRewriterImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/TicketParamRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/TicketParamRewriter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/TicketParamRewriter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/TicketParamRewriter.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.webcontent.rewriter;
+
+
+/**
+ * Parses looking for a Ticket Param, used in SSO portlets where ticket processing is required
+ * Often tickets are added as form parameters and checked on the authentication for better security
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public class TicketParamRewriter extends BasicRewriter
+{    
+    private String ticket;
+    private String ticketName;
+
+    public String getTicketName() 
+    {
+        return ticketName;
+    }
+
+    public void setTicketName(String ticketName) 
+    {
+        this.ticketName = ticketName;
+    }
+    
+    public String getTicket() 
+    {
+		return ticket;
+	}
+
+	public void setTicket(String ticket) 
+    {
+		this.ticket = ticket;
+	}
+    
+    public boolean enterSimpleTagEvent(String tag, MutableAttributes attrs)
+    {
+        if (tag.equalsIgnoreCase("input"))
+        {
+            String name = attrs.getValue("name");
+            String value = attrs.getValue("value");
+            if (name.equals(this.ticketName))
+            {
+            
+            	//System.out.println("*** TICKET attr=" + name + " val = " + value);    
+            	setTicket(value);
+            }
+        }        
+        return true;
+    }            
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/TicketParamRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/TicketParamRewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/WebContentRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/WebContentRewriter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/WebContentRewriter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/WebContentRewriter.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,158 @@
+/* 
+ * 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.webcontent.rewriter;
+
+import java.util.StringTokenizer;
+
+import javax.portlet.PortletURL;
+
+/**
+ * WebContentRewriter
+ * 
+ * @author <a href="mailto:rogerrutr@apache.org">Roger Ruttimann </a>
+ * @version $Id$
+ */
+public class WebContentRewriter extends RulesetRewriterImpl implements Rewriter
+{
+    public void enterConvertTagEvent(String tagid, MutableAttributes attributes) 
+    {
+        super.enterConvertTagEvent(tagid, attributes);
+    }
+
+    /** parameters that need to be propagated in the action URL (since HTTP request parameters will not be available) */
+    public static final String ACTION_PARAMETER_URL    = "_AP_URL";
+    public static final String ACTION_PARAMETER_METHOD = "_AP_METHOD";
+
+    /*
+     * Portlet URL will be used to replace all URL's
+     */
+    private PortletURL actionURL = null;
+
+    /**
+     * Setters/getters for members
+     */
+    public void setActionURL(PortletURL action)
+    {
+        this.actionURL = action;
+    }
+
+    public PortletURL getActionURL()
+    {
+        return this.actionURL;
+    }
+
+    /**
+     * rewriteURL
+     * 
+     * @param url
+     * @param tag
+     * @param attribute
+     * @param otherAttributes
+     * @return the modified url which is a portlet action
+     * 
+     * Rewrites all urls HREFS with a portlet action
+     */
+    public String rewriteUrl(String url, String tag, String attribute, MutableAttributes otherAttributes)
+    {
+         String modifiedURL = url;
+        modifiedURL = getModifiedURL(url);
+
+        // translate "submit" URL's as actions
+        //  <A href="..."/>
+        //  <FORM submit="..."/>
+        if (( tag.equalsIgnoreCase("A") && attribute.equalsIgnoreCase("href")) ||
+            ( tag.equalsIgnoreCase("FORM") && attribute.equalsIgnoreCase("action")))
+                
+        {
+                // Regular URL just add a portlet action
+                if (this.actionURL != null)
+                {
+                    // create Action URL
+                    actionURL.setParameter(ACTION_PARAMETER_URL, modifiedURL);
+                    if (tag.equalsIgnoreCase("FORM"))
+                    {
+                        String httpMethod = otherAttributes.getValue("method");
+                        if (httpMethod != null)
+                            actionURL.setParameter(ACTION_PARAMETER_METHOD, httpMethod);
+                    }
+                    modifiedURL = actionURL.toString();
+                }
+        }
+
+        // Deal with links in an "onclick".
+        if (attribute.equalsIgnoreCase("onclick"))
+        {
+            // Check for onclick with location change
+            for (int i=0; i < otherAttributes.getLength(); i++) {
+
+                String name = otherAttributes.getQName(i);
+
+                if (name.equalsIgnoreCase("onclick")) {
+
+                    String value = otherAttributes.getValue(i);
+
+                    int index = value.indexOf(".location=");
+                    if (index >= 0) {
+                        String oldLocation = value.substring(index + ".location=".length());
+                        StringTokenizer tokenizer = new StringTokenizer(oldLocation, "\'\"");
+                        oldLocation = tokenizer.nextToken();
+
+                        modifiedURL = oldLocation;
+                        url = oldLocation;
+                        modifiedURL = getModifiedURL(url);
+
+                        // Regular URL just add a portlet action
+                        if (this.actionURL != null)
+                        {
+                            // create Action URL
+                            actionURL.setParameter(ACTION_PARAMETER_URL, modifiedURL);
+                            modifiedURL = actionURL.toString();
+                        }
+
+
+                        modifiedURL = value.replaceAll(oldLocation, modifiedURL);
+                    }
+                }
+            }
+
+
+        }
+        
+        // if ( !url.equalsIgnoreCase( modifiedURL ))
+        //     System.out.println("WebContentRewriter.rewriteUrl() - In tag: "+tag+", for attribute: "+attribute+", converted url: "+url+", to: "+modifiedURL+", base URL was: "+getBaseUrl());
+
+        return modifiedURL;
+    }
+
+    private String getModifiedURL(String url) {
+        String modifiedURL = url;
+        // Any relative URL needs to be converted to a full URL
+        if (url.startsWith("/") || (!url.startsWith("http:") && !url.startsWith("https:")))
+        {
+            if (this.getBaseUrl() != null)
+            {
+                modifiedURL = getBaseRelativeUrl(url) ;
+                // System.out.println("WebContentRewriter.rewriteUrl() - translated URL relative to base URL - result is: "+modifiedURL);
+  	        }
+            else
+            {
+                modifiedURL = url; // leave as is
+	        }
+        }
+        return modifiedURL;
+    }
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/WebContentRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/WebContentRewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingAttributes.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingAttributes.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingAttributes.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingAttributes.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,179 @@
+/*
+ * 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.webcontent.rewriter.html;
+
+import java.util.Enumeration;
+
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTML.Attribute;
+
+import org.apache.portals.applications.webcontent.rewriter.MutableAttributes;
+
+
+/**
+ * SwingAttributes
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public class SwingAttributes implements MutableAttributes
+{
+    MutableAttributeSet swingset;
+    
+    public SwingAttributes(MutableAttributeSet swingset)
+    {
+        this.swingset = swingset;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getLength()
+     */
+    public int getLength()
+    {
+        return swingset.getAttributeCount();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getURI(int)
+     */
+    public String getURI(int index)
+    {
+        return "";
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getLocalName(int)
+     */
+    public String getLocalName(int index)
+    {
+        Enumeration e = swingset.getAttributeNames();
+        int ix = 0;
+        while (e.hasMoreElements())
+        {
+            Object object = e.nextElement();
+            if (ix == index)
+            {
+                return object.toString();
+            }
+        }
+        return null;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getQName(int)
+     */
+    public String getQName(int index)
+    {
+        return getLocalName(index);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getType(int)
+     */
+    public String getType(int index)
+    {
+        return "CDATA";
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getValue(int)
+     */
+    public String getValue(int index)
+    {
+        Enumeration e = swingset.getAttributeNames();
+        int ix = 0;
+        while (e.hasMoreElements())
+        {
+            Object object = e.nextElement();
+            if (ix == index)
+            {
+                return (String)swingset.getAttribute(object);
+            }
+        }
+        return null;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getIndex(java.lang.String, java.lang.String)
+     */
+    public int getIndex(String uri, String localPart)
+    {
+        return getIndex(localPart);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getIndex(java.lang.String)
+     */
+    public int getIndex(String qName)
+    {
+        Enumeration e = swingset.getAttributeNames();
+        int ix = 0;
+        while (e.hasMoreElements())
+        {
+            String name = (String)e.nextElement();
+            if (name.equalsIgnoreCase(qName))
+            {
+                return ix;
+            }
+        }
+        return -1;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getType(java.lang.String, java.lang.String)
+     */
+    public String getType(String uri, String localName)
+    {
+        return "CDATA";
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getType(java.lang.String)
+     */
+    public String getType(String qName)
+    {
+        return "CDATA";
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getValue(java.lang.String, java.lang.String)
+     */
+    public String getValue(String uri, String localName)
+    {
+        return getValue(localName);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.Attributes#getValue(java.lang.String)
+     */
+    public String getValue(String qName)
+    {
+        Attribute att = HTML.getAttributeKey(qName.toLowerCase());        
+        return (String)swingset.getAttribute(att);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.portals.applications.webcontent.cps.rewriter.MutableAttributes#addAttribute(java.lang.String, java.lang.Object)
+     */
+    public void addAttribute(String name, Object value)
+    {
+        Attribute att = HTML.getAttributeKey(name.toLowerCase());
+        swingset.addAttribute(att, value);
+    }
+
+}

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingAttributes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingAttributes.java
------------------------------------------------------------------------------
    svn:keywords = Id