You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2014/07/04 06:15:05 UTC
svn commit: r1607784 - in
/portals/applications/webcontent/trunk/content-rewriter/src:
main/java/org/apache/portals/applications/webcontent2/rewriter2/
test/java/org/ test/java/org/apache/ test/java/org/apache/portals/
test/java/org/apache/portals/appl...
Author: woonsan
Date: Fri Jul 4 04:15:04 2014
New Revision: 1607784
URL: http://svn.apache.org/r1607784
Log:
APA-59: Initial API definition for content rewriter.
- For now, putting into 'rewriter2' package. Later I'll remove the old ones and move it to 'rewriter'.
- TODO: verify the API in test cases first (with some examples such as text line based rewriting, sax event based rewriting, htmlcleaner based rewriting, etc.)
Added:
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewriter.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingContext.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingException.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Sink.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Source.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/UriRewriter.java
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter2/
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewriter.java?rev=1607784&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewriter.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewriter.java Fri Jul 4 04:15:04 2014
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.rewriter2;
+
+/**
+ * Reads content from the <code>source</code>, transforms the content and writes to the <code>sink</code>.
+ */
+public interface ContentRewriter
+{
+ /**
+ * Reads content from the <code>source</code>, transforms the content and writes to the <code>sink</code>.
+ *
+ * @param source source of content
+ * @param sink target of content rewritten
+ * @param context content rewriting context
+ * @throws ContentRewritingException
+ */
+ void rewrite(Source source, Sink sink, ContentRewritingContext context) throws ContentRewritingException;
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingContext.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingContext.java?rev=1607784&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingContext.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingContext.java Fri Jul 4 04:15:04 2014
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.rewriter2;
+
+import java.util.Map;
+
+/**
+ * Content Rewriting Context which can be used to shared context variables.
+ */
+public interface ContentRewritingContext
+{
+
+ /**
+ * Returns true if the named attribute exists. Otherwise returns false.
+ * @param name
+ * @return
+ */
+ public boolean hasAttribute(String name);
+
+ /**
+ * Returns the value of the named attribute as an <code>Object</code>,
+ * or <code>null</code> if no attribute of the given name exists.
+ * @param name
+ * @return
+ */
+ public Object getAttribute(String name);
+
+ /**
+ * Returns a <code>Map</code> containing the attributes available.
+ * This method returns an empty <code>Map</code>
+ * if there's no attributes available to it.
+ * @return
+ */
+ public Map<String, Object> getAttributesMap();
+
+ /**
+ * Stores an attribute in this context.
+ * @param name
+ * @param value
+ */
+ public void setAttribute(String name, Object value);
+
+ /**
+ * Removes an attribute from this context.
+ * @param name
+ */
+ public void removeAttribute(String name);
+
+ /**
+ * Returns the <code>UriRewriter</code>.
+ * @return
+ */
+ public UriRewriter getUriRewriter();
+
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingException.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingException.java?rev=1607784&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingException.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingException.java Fri Jul 4 04:15:04 2014
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.rewriter2;
+
+/**
+ * ContentRewritingException which defines a general exception that a ContentRewriter
+ * can throw when it is unable to perform its operation successfully.
+ */
+public class ContentRewritingException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructs a new ContentRewritingException exception.
+ */
+ public ContentRewritingException()
+ {
+ super();
+ }
+
+ /**
+ * Constructs a new ContentRewritingException exception with the given message.
+ *
+ * @param message
+ */
+ public ContentRewritingException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructs a new ContentRewritingException exception when the ContentRewritingException
+ * needs to do the following: throw an exception include the "nested" exception include a description message.
+ *
+ * @param message
+ * @param nested
+ */
+ public ContentRewritingException(String message, Throwable nested)
+ {
+ super(message, nested);
+ }
+
+ /**
+ * Constructs a new ContentRewritingException exception with the nested exception.
+ *
+ * @param nested
+ */
+ public ContentRewritingException(Throwable nested)
+ {
+ super(nested);
+ }
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Sink.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Sink.java?rev=1607784&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Sink.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Sink.java Fri Jul 4 04:15:04 2014
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.rewriter2;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ * Content sink as output to <code>ContentRewriter</code>.
+ */
+public interface Sink
+{
+ /**
+ * Returns an {@link OutputStream} suitable for writing binary data.
+ * Either this method or {@link #getWriter} may be called to write the body, not both.
+ *
+ * @return
+ * @throws IOException
+ */
+ public OutputStream getOutputStream() throws IOException;
+
+ /**
+ * Returns a <code>Writer</code> object that can send character text.
+ *
+ * @return
+ * @throws IOException
+ */
+ public Writer getWriter() throws IOException;
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Source.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Source.java?rev=1607784&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Source.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Source.java Fri Jul 4 04:15:04 2014
@@ -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.webcontent2.rewriter2;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+/**
+ * Content source as input to <code>ContentRewriter</code>.
+ */
+public interface Source
+{
+ /**
+ * Returns the content type (e.g, "text/html; charset=UTF-8") of the content.
+ *
+ * @return
+ */
+ public String getContentType();
+
+ /**
+ * Retrieves the content as binary data using a {@link InputStream}.
+ * Either this method or {@link #getReader} may be called to read the body, not both.
+ *
+ * @return
+ * @throws IOException
+ */
+ public InputStream getInputStream() throws IOException;
+
+ /**
+ * Retrieves the content as character data using a <code>Reader</code>.
+ * Either this method or {@link #getReader} may be called to read the body, not both.
+ *
+ * @return
+ * @throws IOException
+ */
+ public Reader getReader() throws IOException;
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/UriRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/UriRewriter.java?rev=1607784&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/UriRewriter.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/UriRewriter.java Fri Jul 4 04:15:04 2014
@@ -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.webcontent2.rewriter2;
+
+/**
+ * URI Rewriter
+ * <P>
+ * While {@link ContentRewriter} transforms all of the content,
+ * this is only responsible for transforming only URI strings.
+ * For example, a ContentRewriter implementation can invoke a
+ * UriRewriter to transform 'href' attributes while transforming
+ * an HTML document.
+ * </P>
+ */
+public interface UriRewriter
+{
+
+ /**
+ * Transforms the input <code>uri</code> into a URI.
+ * @param uri
+ * @return
+ * @throws NullPointerException
+ * @throws IllegalArgumentException
+ */
+ public String rewrite(String uri);
+
+}