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 [3/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/rewriter/html/SwingParserAdaptor.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingParserAdaptor.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingParserAdaptor.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingParserAdaptor.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,544 @@
+/*
+ * 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.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Enumeration;
+
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLEditorKit;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.applications.webcontent.rewriter.ParserAdaptor;
+import org.apache.portals.applications.webcontent.rewriter.Rewriter;
+import org.apache.portals.applications.webcontent.rewriter.RewriterException;
+
+/**
+ * HTML Parser Adaptor for the Swing 'HotJava' parser.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public class SwingParserAdaptor implements ParserAdaptor
+{
+ protected final static Log log = LogFactory.getLog(SwingParserAdaptor.class);
+
+ private SwingParserAdaptor.Callback callback = null;
+ private String lineSeparator;
+ private boolean skippingImplied = false;
+ private Rewriter rewriter;
+
+ /*
+ * Construct a swing (hot java) parser adaptor
+ * Receives a Rewriter parameter, which is used as a callback when rewriting URLs.
+ * The rewriter object executes the implementation specific URL rewriting.
+ *
+ * @param rewriter The rewriter object that is called back during URL rewriting
+ */
+ public SwingParserAdaptor()
+ {
+ lineSeparator = System.getProperty("line.separator", "\r\n");
+ }
+
+ /*
+ * Parses and an HTML document, rewriting all URLs as determined by the Rewriter callback
+ *
+ *
+ * @param reader The input stream reader
+ *
+ * @throws MalformedURLException
+ *
+ * @return An HTML-String with rewritten URLs.
+ */
+ public void rewrite(Rewriter rewriter, Reader reader, Writer writer)
+ throws RewriterException
+ {
+ try
+ {
+ this.rewriter = rewriter;
+ HTMLEditorKit.Parser parser = new SwingParserAdaptor.ParserGetter().getParser();
+ callback = new SwingParserAdaptor.Callback(writer);
+ parser.parse(reader, callback, true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new RewriterException(e);
+ }
+ }
+
+ public void parse(Rewriter rewriter, Reader reader)
+ throws RewriterException
+ {
+ try
+ {
+ this.rewriter = rewriter;
+ HTMLEditorKit.Parser parser = new SwingParserAdaptor.ParserGetter().getParser();
+ callback = new SwingParserAdaptor.Callback(null);
+ parser.parse(reader, callback, true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new RewriterException(e);
+ }
+ }
+
+ /*
+ * This Class is needed, because getParser is protected and therefore
+ * only accessibly by a subclass
+ */
+ class ParserGetter extends HTMLEditorKit
+ {
+
+ public HTMLEditorKit.Parser getParser()
+ {
+ return super.getParser();
+ }
+ }
+
+ /*
+ * Swing Parser Callback from the HTMLEditorKit.
+ * This class handles all SAX-like events during parsing.
+ *
+ */
+ class Callback extends HTMLEditorKit.ParserCallback
+ {
+ // either handling of <FORM> is buggy, or I made some weird mistake ...
+ // ... JDK 1.3 sends double "</form>"-tags on closing <form>
+ private boolean inForm = false;
+ private boolean inScript = false;
+ private boolean strip = false;
+ private boolean simpleTag = false;
+ private String stripTag = null;
+ private Writer writer = null;
+
+ private Callback (Writer writer)
+ {
+ this.writer = writer;
+ }
+
+ //
+ // -------------- Hot Java event callbacks... --------------------
+ //
+
+ /*
+ * Hot Java event callback for text (all data in between tags)
+ *
+ * @param values The array of characters containing the text.
+ */
+ public void handleText(char[] values,int param)
+ {
+ if (strip)
+ {
+ return;
+ }
+ if (values[0] == '>')
+ {
+ return;
+ }
+ if (false == rewriter.enterText(values, param))
+ {
+ return;
+ }
+
+ addToResult(values);
+ }
+
+ private void write(String text)
+ throws IOException
+ {
+ if (writer != null)
+ {
+ writer.write(text);
+ }
+ }
+
+ /*
+ * Hot Java event callback for handling a simple tag (without begin/end)
+ *
+ * @param tag The HTML tag being handled.
+ * @param attrs The mutable HTML attribute set for the current HTML element.
+ * @param position the position of the tag.
+ *
+ */
+ public void handleSimpleTag(HTML.Tag htmlTag, MutableAttributeSet attrs, int param)
+ {
+ String tag = htmlTag.toString();
+
+ if (false == rewriter.enterSimpleTagEvent(tag, new SwingAttributes(attrs)))
+ {
+ return;
+ }
+
+ if (strip)
+ {
+ return;
+ }
+
+ if (rewriter.shouldStripTag(tag))
+ {
+ return;
+ }
+
+ if (rewriter.shouldRemoveTag(tag))
+ {
+ return;
+ }
+
+ try
+ {
+ simpleTag = true;
+ appendTagToResult(htmlTag, attrs);
+ write(lineSeparator);
+/*
+ if (tag.toString().equalsIgnoreCase("param") ||
+ tag.toString().equalsIgnoreCase("object") ||
+ tag.toString().equalsIgnoreCase("embed"))
+ {
+ write(lineSeparator);
+ }
+*/
+ simpleTag = false;
+ String appended = rewriter.exitSimpleTagEvent(tag, new SwingAttributes(attrs));
+ if (null != appended)
+ {
+ write(appended);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Simple tag parsing error", e);
+ }
+ }
+
+ /*
+ * Hot Java event callback for handling a start tag.
+ *
+ * @param tag The HTML tag being handled.
+ * @param attrs The mutable HTML attribute set for the current HTML element.
+ * @param position the position of the tag.
+ *
+ */
+ public void handleStartTag(HTML.Tag htmlTag, MutableAttributeSet attrs, int position)
+ {
+ String tag = htmlTag.toString();
+
+ if (false == rewriter.enterStartTagEvent(tag, new SwingAttributes(attrs)))
+ {
+ return;
+ }
+
+ if (strip)
+ {
+ return;
+ }
+
+ if (rewriter.shouldStripTag(tag))
+ {
+ stripTag = tag;
+ strip = true;
+ return;
+ }
+
+ if (rewriter.shouldRemoveTag(tag))
+ {
+ return;
+ }
+
+ try
+ {
+ appendTagToResult(htmlTag, attrs);
+ formatLine(htmlTag);
+ String appended = rewriter.exitStartTagEvent(tag, new SwingAttributes(attrs));
+ if (null != appended)
+ {
+ write(appended);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Start tag parsing error", e);
+ }
+
+ }
+
+
+
+ /*
+ * Hot Java event callback for handling an end tag.
+ *
+ * @param tag The HTML tag being handled.
+ * @param position the position of the tag.
+ *
+ */
+ public void handleEndTag(HTML.Tag htmlTag, int position)
+ {
+ String tag = htmlTag.toString();
+ if (false == rewriter.enterEndTagEvent(tag.toString()))
+ {
+ return;
+ }
+
+ if (strip)
+ {
+ if (tag.equalsIgnoreCase(stripTag))
+ {
+ strip = false;
+ stripTag = null;
+ }
+ return;
+ }
+
+ if (rewriter.shouldRemoveTag(tag))
+ {
+ return;
+ }
+
+ try
+ {
+ addToResult("</").addToResult(tag).addToResult(">");
+
+ // formatLine(htmlTag);
+ write(lineSeparator);
+
+ String appended = rewriter.exitEndTagEvent(tag);
+ if (null != appended)
+ {
+ write(appended);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("End tag parsing error", e);
+ }
+ }
+
+
+ /*
+ * Hot Java event callback for handling errors.
+ *
+ * @param str The error message from Swing.
+ * @param param A parameter passed to handler.
+ *
+ */
+ public void handleError(java.lang.String str,int param)
+ {
+ // System.out.println("Handling error: " + str);
+ }
+
+ /*
+ * Hot Java event callback for HTML comments.
+ *
+ * @param values The character array of text comments.
+ * @param param A parameter passed to handler.
+ *
+ */
+ public void handleComment(char[] values,int param)
+ {
+ if (strip || rewriter.shouldRemoveComments())
+ {
+ return;
+ }
+ addToResult("<!-- ").addToResult(values).addToResult(" -->").addToResult(lineSeparator);
+ }
+
+ /*
+ * Hot Java event callback for end of line strings.
+ *
+ * @param str The end-of-line string.
+ *
+ */
+ public void handleEndOfLineString(java.lang.String str)
+ {
+ if (strip)
+ {
+ return;
+ }
+
+ addToResult(lineSeparator);
+ addToResult(str);
+ }
+
+
+ /*
+ * Prints new lines to make the output a little easier to read when debugging.
+ *
+ * @param tag The HTML tag being handled.
+ *
+ */
+ private void formatLine(HTML.Tag tag)
+ {
+ try
+ {
+ if (tag.isBlock() ||
+ tag.breaksFlow() ||
+ tag == HTML.Tag.FRAME ||
+ tag == HTML.Tag.FRAMESET ||
+ tag == HTML.Tag.SCRIPT)
+ {
+ write(lineSeparator);
+ }
+
+ }
+ catch (Exception e)
+ {
+ log.error("Format Line tag parsing error", e);
+ }
+
+ }
+
+
+ /*
+ * 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 Callback 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;
+ }
+
+
+ /*
+ * Used to write all character content to the output stream.
+ * Returns a reference to itself so that these calls can be chained.
+ *
+ * @param txt Any character text to be written out directly to stream.
+ * @return A handle to the this, the callback, for chaining results.
+ *
+ */
+ private Callback addToResult(char[] txt)
+ {
+ //if (ignoreLevel > 0) return this;
+
+ try
+ {
+ if (writer != null)
+ {
+ writer.write(txt);
+ }
+
+ }
+ catch (Exception e)
+ { /* ignore */
+ }
+ return this;
+ }
+
+ /*
+ * Accessor to the Callback's content-String
+ *
+ * @return Cleaned and rewritten HTML-Content
+ */
+ public void getResult()
+ {
+ try
+ {
+ if (writer != null)
+ {
+ writer.flush();
+ }
+ }
+ catch (Exception e)
+ { /* ignore */
+ }
+
+ // WARNING: doesn't work, if you remove " " + ... but don't know why
+ //String res = " " + result.toString();
+
+ // return res;
+ }
+
+ /*
+ * Flushes the output stream. NOT IMPLEMENTED
+ *
+ */
+ public void flush() throws javax.swing.text.BadLocationException
+ {
+ // nothing to do here ...
+ }
+
+ /*
+ * 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(HTML.Tag tag, MutableAttributeSet attrs)
+ {
+ convertURLS(tag, attrs);
+ Enumeration e = attrs.getAttributeNames();
+ addToResult("<").addToResult(tag);
+ while (e.hasMoreElements())
+ {
+ Object attr = e.nextElement();
+ String value = attrs.getAttribute(attr).toString();
+ addToResult(" ").addToResult(attr).addToResult("=\"").
+ addToResult(value).addToResult("\"");
+ }
+ if (simpleTag)
+ addToResult("/>");
+ else
+ addToResult(">");
+ }
+
+
+ /*
+ * 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.
+ *
+ * @param tag TAG from the Callback-Interface.
+ * @param attrs The mutable HTML attribute set for the current HTML element.
+ */
+
+ private void convertURLS( HTML.Tag tag, MutableAttributeSet attrs )
+ {
+ rewriter.enterConvertTagEvent(tag.toString(), new SwingAttributes(attrs));
+
+ /*
+ if ( removeScript && (tag == HTML.Tag.SCRIPT)) {
+ ignoreLevel ++;
+ */
+ }
+
+
+ }
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingParserAdaptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/SwingParserAdaptor.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/CallbackElementRemover.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/CallbackElementRemover.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/CallbackElementRemover.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/CallbackElementRemover.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,163 @@
+/*
+ * 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.neko;
+
+import org.apache.portals.applications.webcontent.rewriter.Rewriter;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLString;
+import org.apache.xerces.xni.XNIException;
+import org.cyberneko.html.filters.ElementRemover;
+
+/**
+ * <p>
+ * CallbackElementRemover
+ * </p>
+ * <p>
+ * Extended version of the NekoHTML ElementRemover which provides
+ * tag stripping/removal based on Rewriter settings.
+ * </p>
+ *
+ * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
+ * @version $Id$
+ *
+ */
+public class CallbackElementRemover extends ElementRemover
+{
+
+ private Rewriter rewriter;
+
+ /**
+ * Construct with reference to the rewriter context to consult for rewriting advice
+ */
+ public CallbackElementRemover( Rewriter rewriter )
+ {
+ super();
+
+ this.rewriter = rewriter;
+ }
+
+
+ // Base Class Protocol
+
+ /**
+ * <p>
+ * comment
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#comment(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
+ * @param text
+ * @param augs
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void comment(XMLString text,Augmentations augs) throws XNIException
+ {
+ if (rewriter.shouldRemoveComments())
+ return;
+ super.comment(text,augs);
+ }
+
+ /**
+ * <p>
+ * emptyElement
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#emptyElement(org.apache.xerces.xni.QName,
+ * org.apache.xerces.xni.XMLAttributes,
+ * org.apache.xerces.xni.Augmentations)
+ * @param element
+ * @param arg1
+ * @param arg2
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void emptyElement( QName element, XMLAttributes attrs, Augmentations arg2 ) throws XNIException
+ {
+ processTag(element,attrs) ;
+ super.emptyElement(element, attrs, arg2);
+ }
+
+ /**
+ * <p>
+ * startElement
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#startElement(org.apache.xerces.xni.QName,
+ * org.apache.xerces.xni.XMLAttributes,
+ * org.apache.xerces.xni.Augmentations)
+ * @param element
+ * @param arg1
+ * @param arg2
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void startElement( QName element, XMLAttributes attrs, Augmentations arg2 ) throws XNIException
+ {
+ processTag(element,attrs);
+ super.startElement(element, attrs, arg2);
+ }
+
+
+ // Support Methods
+
+ /**
+ * <p>
+ * processTag
+ * </p>
+ *
+ * @param tag
+ */
+ protected void processTag(QName element, XMLAttributes attrs)
+ {
+ String tag = element.rawname.toLowerCase();
+ if (fRemovedElements.contains(tag))
+ {
+ // alread removed
+ return ;
+ }
+ else if (rewriter.shouldStripTag(tag))
+ {
+ // first time for this tag...
+ // strip - remove tag and any text associated with it
+ removeElement(tag);
+ return ;
+ }
+ else if (rewriter.shouldRemoveTag(tag))
+ {
+ // BOZO - block intentially left EMPTY
+
+ // first time for this tag...
+ // remove - no directive necessary, the default behavior of ElementRemover is to drop tags that it does not know about (but the assocated text will remain)
+ return ;
+ }
+
+ // OTHERWISE - explicitly accept (keep tag and associated text)
+ // NOTE: even if fAcceptedElements contains the tag already, we need to reset the attribute names for this invocation context
+ rewriter.enterConvertTagEvent(tag,new XMLAttributesWrapper(attrs));
+ acceptElement(tag,getAttributeNames(attrs));
+ }
+ protected String[] getAttributeNames(XMLAttributes attrs)
+ {
+ int length = attrs != null ? attrs.getLength() : 0 ;
+ String[] names = length > 0 ? new String[ length ] : null ;
+
+ for( int i = 0, limit = length;i<limit;i++)
+ {
+ names[i] = attrs.getQName(i) ;
+ }
+ return names ;
+ }
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/CallbackElementRemover.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/CallbackElementRemover.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoHTMLParserAdapter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoHTMLParserAdapter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoHTMLParserAdapter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoHTMLParserAdapter.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,74 @@
+/*
+ * 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.neko;
+
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.portals.applications.webcontent.rewriter.ParserAdaptor;
+import org.apache.portals.applications.webcontent.rewriter.Rewriter;
+import org.apache.portals.applications.webcontent.rewriter.RewriterException;
+
+/**
+ * <p>
+ * NeckoHTMLParserAdapter
+ * </p>
+ * <p>
+ *
+ * </p>
+ * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
+ * @version $Id$
+ *
+ */
+public class NekoHTMLParserAdapter implements ParserAdaptor
+{
+
+
+ /**
+ * <p>
+ * parse
+ * </p>
+ *
+ * @see org.apache.portals.applications.webcontent.rewriter.ParserAdaptor#parse(org.apache.portals.applications.webcontent.rewriter.Rewriter, java.io.Reader)
+ * @param rewriter
+ * @param reader
+ * @throws RewriterException
+ */
+ public void parse( Rewriter rewriter, Reader reader ) throws RewriterException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * <p>
+ * rewrite
+ * </p>
+ *
+ * @see org.apache.portals.applications.webcontent.rewriter.ParserAdaptor#rewrite(org.apache.portals.applications.webcontent.rewriter.Rewriter, java.io.Reader, java.io.Writer)
+ * @param rewriter
+ * @param reader
+ * @param writer
+ * @throws RewriterException
+ */
+ public void rewrite( Rewriter rewriter, Reader reader, Writer writer ) throws RewriterException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoHTMLParserAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoHTMLParserAdapter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoParserAdaptor.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoParserAdaptor.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoParserAdaptor.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoParserAdaptor.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,129 @@
+/*
+ * 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.neko;
+
+import java.io.Reader;
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xerces.xni.parser.XMLDocumentFilter;
+import org.apache.xerces.xni.parser.XMLInputSource;
+
+import org.apache.portals.applications.webcontent.rewriter.ParserAdaptor;
+import org.apache.portals.applications.webcontent.rewriter.Rewriter;
+import org.apache.portals.applications.webcontent.rewriter.RewriterException;
+
+import org.xml.sax.SAXException ;
+
+import org.cyberneko.html.parsers.SAXParser;
+import org.cyberneko.html.filters.DefaultFilter;
+import org.cyberneko.html.filters.Purifier;
+
+
+/**
+ * <p>
+ * NekoParserAdapter
+ * </p>
+ * <p>
+ *
+ * </p>
+ * @author <a href="mailto:dyoung@phase2systems.com">David L Young</a>
+ * @version $Id$
+ *
+ */
+public class NekoParserAdaptor implements ParserAdaptor
+{
+ protected final static Log log = LogFactory.getLog(NekoParserAdaptor.class);
+
+ /*
+ * Construct a cyberneko HTML parser adaptor
+ */
+ public NekoParserAdaptor()
+ {
+ super();
+ }
+
+ /**
+ * <p>
+ * parse
+ * </p>
+ *
+ * @see org.apache.portals.applications.webcontent.rewriter.ParserAdaptor#parse(org.apache.portals.applications.webcontent.rewriter.Rewriter, java.io.Reader)
+ * @param rewriter
+ * @param reader
+ * @throws RewriterException
+ */
+ public void parse(Rewriter rewriter, Reader reader)
+ throws RewriterException
+ {
+ // not sure what this means to parse without rewriting
+ rewrite(rewriter,reader,null);
+ }
+
+ /**
+ * <p>
+ * rewrite
+ * </p>
+ *
+ * @see org.apache.portals.applications.webcontent.rewriter.ParserAdaptor#rewrite(org.apache.portals.applications.webcontent.rewriter.Rewriter, java.io.Reader, java.io.Writer)
+ * @param rewriter
+ * @param reader
+ * @param writer
+ * @throws RewriterException
+ */
+ public void rewrite(Rewriter rewriter, java.io.Reader reader, java.io.Writer writer)
+ throws RewriterException
+ {
+ // use a cyberneko SAXParser
+ SAXParser parser = new SAXParser() ;
+
+ // setup filter chain
+ XMLDocumentFilter[] filters = {
+ new Purifier(), // [1] standard neko purifications (tag balancing, etc)
+ new CallbackElementRemover( rewriter ), // [2] accept / reject tags based on advice from rewriter
+ writer != null ? new org.cyberneko.html.filters.Writer( writer, null ) : new DefaultFilter() // [3] propagate results to specified writer (or do nothing -- Default -- when writer is null)
+ };
+
+ String filtersPropName = "http://cyberneko.org/html/properties/filters";
+
+ try
+ {
+ parser.setProperty(filtersPropName, filters);
+ }
+ catch (SAXException e)
+ {
+ // either no longer supported (SAXNotSupportedException), or no logner recognized (SAXNotRecognizedException)
+ log.error(filtersPropName + " is, unexpectedly, no longer defined for the cyberneko HTML parser",e);
+ throw new RewriterException("cyberneko parser version not supported",e);
+ }
+
+ try
+ {
+ // parse from reader
+ parser.parse(new XMLInputSource( null, null, null, reader, null )) ;
+ }
+ catch (IOException e)
+ {
+ String msg = "cyberneko HTML parsing failure";
+ log.error(msg,e);
+ throw new RewriterException(msg,e);
+ }
+
+ }
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoParserAdaptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/NekoParserAdaptor.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/URLRewriterFilter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/URLRewriterFilter.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/URLRewriterFilter.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/URLRewriterFilter.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,181 @@
+/*
+ * 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.neko;
+
+import org.apache.portals.applications.webcontent.rewriter.Rewriter;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLString;
+import org.apache.xerces.xni.XNIException;
+import org.cyberneko.html.filters.DefaultFilter;
+
+/**
+ * <p>
+ * URLRewriterFilter
+ * </p>
+ * <p>
+ *
+ * </p>
+ *
+ * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
+ * @version $Id$
+ *
+ */
+public class URLRewriterFilter extends DefaultFilter
+{
+
+ private Rewriter rewriter;
+
+
+ /**
+ *
+ */
+ public URLRewriterFilter(Rewriter rewriter )
+ {
+ super();
+ this.rewriter = rewriter;
+ }
+
+
+ /**
+ * <p>
+ * startElement
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#startElement(org.apache.xerces.xni.QName,
+ * org.apache.xerces.xni.XMLAttributes,
+ * org.apache.xerces.xni.Augmentations)
+ * @param element
+ * @param attrs
+ * @param augs
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void startElement( QName element, XMLAttributes attrs, Augmentations augs ) throws XNIException
+ {
+ if (false == rewriter.enterSimpleTagEvent(element.rawname, new XMLAttributesWrapper(attrs)))
+ {
+ doRewrite(element, attrs);
+ String appended = rewriter.exitSimpleTagEvent(element.rawname, new XMLAttributesWrapper(attrs));
+ if (null != appended)
+ {
+ //TODO: implement this!
+ }
+ }
+
+ super.startElement(element, attrs, augs);
+ }
+
+ /**
+ * <p>
+ * doRewrite
+ * </p>
+ *
+ * @param element
+ * @param attrs
+ */
+ protected void doRewrite( QName element, XMLAttributes attrs )
+ {
+ if (element.rawname.equals("A"))
+ {
+ rewriteAttribute("href", attrs);
+ }
+ else if (element.rawname.equals("FORM"))
+ {
+ rewriteAttribute("action", attrs);
+ }
+ }
+
+ protected void rewriteAttribute( String attrName, XMLAttributes attributes )
+ {
+
+ String uri = attributes.getValue(attrName);
+
+
+ if (uri != null)
+ {
+ // attributes.setValue(attributes.getIndex(attrName), urlGenerator.createUrl(uri));
+
+ }
+
+ }
+ /**
+ * <p>
+ * emptyElement
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#emptyElement(org.apache.xerces.xni.QName, org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void emptyElement( QName element, XMLAttributes attrs, Augmentations arg2 ) throws XNIException
+ {
+ doRewrite(element, attrs);
+ super.emptyElement(element, attrs, arg2);
+ }
+ /**
+ * <p>
+ * comment
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#comment(org.apache.xerces.xni.XMLString, org.apache.xerces.xni.Augmentations)
+ * @param comment
+ * @param augs
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void comment( XMLString comment, Augmentations augs ) throws XNIException
+ {
+ if (!rewriter.shouldRemoveComments())
+ {
+ super.comment(comment, augs);
+ }
+
+ }
+ /**
+ * <p>
+ * endElement
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#endElement(org.apache.xerces.xni.QName, org.apache.xerces.xni.Augmentations)
+ * @param arg0
+ * @param arg1
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void endElement( QName element, Augmentations augs ) throws XNIException
+ {
+ super.endElement(element, augs);
+ }
+ /**
+ * <p>
+ * characters
+ * </p>
+ *
+ * @see org.apache.xerces.xni.XMLDocumentHandler#characters(org.apache.xerces.xni.XMLString, org.apache.xerces.xni.Augmentations)
+ * @param arg0
+ * @param arg1
+ * @throws org.apache.xerces.xni.XNIException
+ */
+ public void characters( XMLString text, Augmentations arg1 ) throws XNIException
+ {
+ if (!(text.ch[0] == '>') && ! rewriter.enterText(text.ch, text.offset))
+ {
+ super.characters(text, arg1);
+ }
+ }
+}
\ No newline at end of file
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/URLRewriterFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/URLRewriterFilter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/XMLAttributesWrapper.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/XMLAttributesWrapper.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/XMLAttributesWrapper.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/XMLAttributesWrapper.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,464 @@
+/*
+ * 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.neko;
+
+import org.apache.portals.applications.webcontent.rewriter.MutableAttributes;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+
+/**
+ * <p>
+ * XMLAttributesWrapper
+ * </p>
+ * <p>
+ *
+ * </p>
+ * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
+ * @version $Id$
+ *
+ */
+public class XMLAttributesWrapper implements MutableAttributes
+{
+ protected XMLAttributes attrs;
+
+ /**
+ *
+ */
+ public XMLAttributesWrapper(XMLAttributes attrs)
+ {
+ super();
+ this.attrs = attrs;
+ }
+
+ /**
+ * <p>
+ * addAttribute
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @return
+ */
+ public int addAttribute( QName arg0, String arg1, String arg2 )
+ {
+ int i = getIndex( arg0.rawname );
+ if ( i >= 0 )
+ attrs.removeAttributeAt( i );
+
+ return attrs.addAttribute( arg0, arg1, arg2 );
+ }
+ /**
+ * <p>
+ * equals
+ * </p>
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ * @param obj
+ * @return
+ */
+ public boolean equals( Object obj )
+ {
+ return attrs.equals(obj);
+ }
+ /**
+ * <p>
+ * getAugmentations
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public Augmentations getAugmentations( int arg0 )
+ {
+ return attrs.getAugmentations(arg0);
+ }
+ /**
+ * <p>
+ * getAugmentations
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public Augmentations getAugmentations( String qName )
+ {
+ return attrs.getAugmentations(asNekoAttributeName(qName)) ;
+ }
+ /**
+ * <p>
+ * getAugmentations
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ * @return
+ */
+ public Augmentations getAugmentations( String uri, String localPart )
+ {
+ return attrs.getAugmentations(uri,asNekoAttributeName(localPart));
+ }
+ /**
+ * <p>
+ * getIndex
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public int getIndex( String qName )
+ {
+ return attrs.getIndex(asNekoAttributeName(qName));
+ }
+ /**
+ * <p>
+ * getIndex
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ * @return
+ */
+ public int getIndex( String uri, String localName )
+ {
+ return attrs.getIndex(uri,asNekoAttributeName(localName));
+ }
+ /**
+ * <p>
+ * getLength
+ * </p>
+ *
+ * @return
+ */
+ public int getLength()
+ {
+ return attrs.getLength();
+ }
+ /**
+ * <p>
+ * getLocalName
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getLocalName( int arg0 )
+ {
+ return attrs.getLocalName(arg0);
+ }
+ /**
+ * <p>
+ * getName
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public void getName( int arg0, QName arg1 )
+ {
+ attrs.getName(arg0, arg1);
+ }
+ /**
+ * <p>
+ * getNonNormalizedValue
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getNonNormalizedValue( int arg0 )
+ {
+ return attrs.getNonNormalizedValue(arg0);
+ }
+ /**
+ * <p>
+ * getPrefix
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getPrefix( int arg0 )
+ {
+ return attrs.getPrefix(arg0);
+ }
+ /**
+ * <p>
+ * getQName
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getQName( int arg0 )
+ {
+ return attrs.getQName(arg0);
+ }
+ /**
+ * <p>
+ * getType
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getType( int arg0 )
+ {
+ return attrs.getType(arg0);
+ }
+ /**
+ * <p>
+ * getType
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getType( String qName )
+ {
+ return attrs.getType(asNekoAttributeName(qName));
+ }
+ /**
+ * <p>
+ * getType
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ * @return
+ */
+ public String getType( String uri, String localName )
+ {
+ return attrs.getType(uri, asNekoAttributeName(localName));
+ }
+ /**
+ * <p>
+ * getURI
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getURI( int arg0 )
+ {
+ return attrs.getURI(arg0);
+ }
+ /**
+ * <p>
+ * getValue
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getValue( int arg0 )
+ {
+ return attrs.getValue(arg0);
+ }
+ /**
+ * <p>
+ * getValue
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public String getValue( String qName )
+ {
+ return attrs.getValue(asNekoAttributeName(qName));
+ }
+ /**
+ * <p>
+ * getValue
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ * @return
+ */
+ public String getValue( String uri, String localName )
+ {
+ return attrs.getValue(uri, asNekoAttributeName(localName));
+ }
+ /**
+ * <p>
+ * hashCode
+ * </p>
+ *
+ * @see java.lang.Object#hashCode()
+ * @return
+ */
+ public int hashCode()
+ {
+ return attrs.hashCode();
+ }
+ /**
+ * <p>
+ * isSpecified
+ * </p>
+ *
+ * @param arg0
+ * @return
+ */
+ public boolean isSpecified( int arg0 )
+ {
+ return attrs.isSpecified(arg0);
+ }
+ /**
+ * <p>
+ * removeAllAttributes
+ * </p>
+ *
+ *
+ */
+ public void removeAllAttributes()
+ {
+ attrs.removeAllAttributes();
+ }
+ /**
+ * <p>
+ * removeAttributeAt
+ * </p>
+ *
+ * @param arg0
+ */
+ public void removeAttributeAt( int arg0 )
+ {
+ attrs.removeAttributeAt(arg0);
+ }
+ /**
+ * <p>
+ * setAugmentations
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public void setAugmentations( int arg0, Augmentations arg1 )
+ {
+ attrs.setAugmentations(arg0, arg1);
+ }
+ /**
+ * <p>
+ * setName
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public void setName( int arg0, QName arg1 )
+ {
+ attrs.setName(arg0, arg1);
+ }
+ /**
+ * <p>
+ * setNonNormalizedValue
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public void setNonNormalizedValue( int arg0, String arg1 )
+ {
+ attrs.setNonNormalizedValue(arg0, arg1);
+ }
+ /**
+ * <p>
+ * setSpecified
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public void setSpecified( int arg0, boolean arg1 )
+ {
+ attrs.setSpecified(arg0, arg1);
+ }
+ /**
+ * <p>
+ * setType
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public void setType( int arg0, String arg1 )
+ {
+ attrs.setType(arg0, arg1);
+ }
+ /**
+ * <p>
+ * setValue
+ * </p>
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public void setValue( int arg0, String arg1 )
+ {
+ attrs.setValue(arg0, arg1);
+ }
+ /**
+ * <p>
+ * toString
+ * </p>
+ *
+ * @see java.lang.Object#toString()
+ * @return
+ */
+ public String toString()
+ {
+ return attrs.toString();
+ }
+ /**
+ * <p>
+ * addAttribute
+ * </p>
+ *
+ * @see org.apache.portals.applications.webcontent.rewriter.MutableAttributes#addAttribute(java.lang.String, java.lang.Object)
+ * @param name
+ * @param value
+ */
+ public void addAttribute( String name, Object value )
+ {
+ QName qName = null ;
+ int i = name.indexOf(':');
+ if (i < 0)
+ {
+ name = name.toLowerCase();
+ qName = new QName(null,name,name,null);
+ }
+ else
+ {
+ String prefix = name.substring(0,i);
+ String localPart = name.substring(i+1).toLowerCase();
+ name = name.toLowerCase();
+ qName = new QName(prefix,localPart,name,null);
+ }
+ addAttribute(qName,"CDATA",value.toString());
+ }
+
+
+ // Support Methods
+
+ protected String asNekoAttributeName(String n)
+ {
+ // neko, by default, converts attribute names to lower case
+ return n != null ? n.toLowerCase() : null ;
+ }
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/XMLAttributesWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/html/neko/XMLAttributesWrapper.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Attribute.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Attribute.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Attribute.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Attribute.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter.rules;
+
+/**
+ * Attribute
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public interface Attribute extends Identified
+{
+ /**
+ * Get the rewriter rule associated with this attribute.
+ *
+ * @return The rewriter rule.
+ */
+ Rule getRule();
+
+ /**
+ * Set the rewriter rule associated with this attribute.
+ *
+ * @param rule The rewriter rule.
+ */
+ void setRule(Rule rule);
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Attribute.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Attribute.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Identified.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Identified.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Identified.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Identified.java Mon Apr 13 21:17:59 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.rules;
+
+/**
+ * Identified
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public interface Identified
+{
+ /**
+ * Get the unique identification string for this rule.
+ *
+ * @return the unique identifier of the rule
+ */
+ String getId();
+
+ /**
+ * Set the unique identification string for this rule.
+ *
+ * @param id the unique identifier of the rule
+ */
+ void setId(String id);
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Identified.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Identified.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Rule.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Rule.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Rule.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Rule.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter.rules;
+
+/**
+ * Rule
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+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);
+
+
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Rule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Rule.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Ruleset.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Ruleset.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Ruleset.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Ruleset.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter.rules;
+
+import java.util.Collection;
+
+/**
+ * Ruleset
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+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();
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Ruleset.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Ruleset.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Tag.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Tag.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Tag.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Tag.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter.rules;
+
+import java.util.Collection;
+
+/**
+ * Tag
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+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);
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Tag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/Tag.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/AttributeImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/AttributeImpl.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/AttributeImpl.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/AttributeImpl.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.rules.impl;
+
+import org.apache.portals.applications.webcontent.rewriter.rules.Attribute;
+import org.apache.portals.applications.webcontent.rewriter.rules.Rule;
+
+/**
+ * Attribute
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+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;
+ }
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/AttributeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/AttributeImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/IdentifiedImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/IdentifiedImpl.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/IdentifiedImpl.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/IdentifiedImpl.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.rules.impl;
+
+/**
+ * IdentifiedImpl
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+public class IdentifiedImpl
+{
+ protected String id;
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId(String id)
+ {
+ if (id != null)
+ {
+ this.id = id;
+ }
+ }
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/IdentifiedImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/IdentifiedImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RuleImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RuleImpl.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RuleImpl.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RuleImpl.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter.rules.impl;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.apache.portals.applications.webcontent.rewriter.rules.Rule;
+
+/**
+ * Rule
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+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;
+ }
+
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RuleImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RuleImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RulesetImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RulesetImpl.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RulesetImpl.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RulesetImpl.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.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.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;
+
+/**
+ * RulesetImpl
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+/**
+ * Ruleset
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+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;
+ }
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RulesetImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/RulesetImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/TagImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/TagImpl.java?rev=764612&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/TagImpl.java (added)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/TagImpl.java Mon Apr 13 21:17:59 2009
@@ -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.webcontent.rewriter.rules.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.portals.applications.webcontent.rewriter.rules.Tag;
+
+/**
+ * Tag
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id$
+ */
+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;
+ }
+
+}
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/TagImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/rules/impl/TagImpl.java
------------------------------------------------------------------------------
svn:keywords = Id