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/05 06:55:31 UTC
svn commit: r1607975 - in /portals/applications/webcontent/trunk: ./
content-rewriter/
content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/
content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewr...
Author: woonsan
Date: Sat Jul 5 04:55:29 2014
New Revision: 1607975
URL: http://svn.apache.org/r1607975
Log:
APA-59: Initial API definition for content rewriter.
- Verifing the API in a simple text line based test case
Added:
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/AbstractTextLineContentRewriter.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/SimpleContentRewritingContext.java
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter2/TextLineContentRewriterTest.java
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter2/
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter2/announce-template.txt
Removed:
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/UriRewriter.java
Modified:
portals/applications/webcontent/trunk/content-rewriter/pom.xml
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/Source.java
portals/applications/webcontent/trunk/pom.xml
Modified: portals/applications/webcontent/trunk/content-rewriter/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/pom.xml?rev=1607975&r1=1607974&r2=1607975&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/pom.xml (original)
+++ portals/applications/webcontent/trunk/content-rewriter/pom.xml Sat Jul 5 04:55:29 2014
@@ -84,6 +84,12 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Modified: 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=1607975&r1=1607974&r2=1607975&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewriter.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewriter.java Sat Jul 5 04:55:29 2014
@@ -16,6 +16,8 @@
*/
package org.apache.portals.applications.webcontent2.rewriter2;
+import java.io.IOException;
+
/**
* Reads content from the <code>source</code>, transforms the content and writes to the <code>sink</code>.
*/
@@ -29,5 +31,5 @@ public interface ContentRewriter
* @param context content rewriting context
* @throws ContentRewritingException
*/
- void rewrite(Source source, Sink sink, ContentRewritingContext context) throws ContentRewritingException;
+ void rewrite(Source source, Sink sink, ContentRewritingContext context) throws ContentRewritingException, IOException;
}
Modified: 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=1607975&r1=1607974&r2=1607975&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingContext.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/ContentRewritingContext.java Sat Jul 5 04:55:29 2014
@@ -60,10 +60,4 @@ public interface ContentRewritingContext
*/
public void removeAttribute(String name);
- /**
- * Returns the <code>UriRewriter</code>.
- * @return
- */
- public UriRewriter getUriRewriter();
-
}
Modified: 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=1607975&r1=1607974&r2=1607975&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Source.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/Source.java Sat Jul 5 04:55:29 2014
@@ -26,13 +26,6 @@ import java.io.Reader;
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.
*
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/AbstractTextLineContentRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/AbstractTextLineContentRewriter.java?rev=1607975&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/AbstractTextLineContentRewriter.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/AbstractTextLineContentRewriter.java Sat Jul 5 04:55:29 2014
@@ -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.webcontent2.rewriter2.impl;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.LineIterator;
+import org.apache.portals.applications.webcontent2.rewriter2.ContentRewriter;
+import org.apache.portals.applications.webcontent2.rewriter2.ContentRewritingContext;
+import org.apache.portals.applications.webcontent2.rewriter2.ContentRewritingException;
+import org.apache.portals.applications.webcontent2.rewriter2.Sink;
+import org.apache.portals.applications.webcontent2.rewriter2.Source;
+
+/**
+ * AbstractTextLineContentRewriter
+ */
+public abstract class AbstractTextLineContentRewriter implements ContentRewriter
+{
+
+ public void rewrite(Source source, Sink sink, ContentRewritingContext context) throws ContentRewritingException, IOException
+ {
+ Reader reader = null;
+ Writer writer = null;
+ BufferedWriter bw = null;
+ PrintWriter out = null;
+
+ try
+ {
+ reader = source.getReader();
+ writer = sink.getWriter();
+ bw = new BufferedWriter(writer);
+ out = new PrintWriter(bw);
+ String line = null;
+
+ for (LineIterator lineIt = IOUtils.lineIterator(reader); lineIt.hasNext();)
+ {
+ line = rewriteLine(lineIt.nextLine());
+ out.println(line);
+ }
+
+ out.flush();
+ }
+ finally
+ {
+ IOUtils.closeQuietly(reader);
+ IOUtils.closeQuietly(out);
+ IOUtils.closeQuietly(bw);
+ IOUtils.closeQuietly(writer);
+ }
+ }
+
+ protected abstract String rewriteLine(String line) throws ContentRewritingException, IOException;
+
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/SimpleContentRewritingContext.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/SimpleContentRewritingContext.java?rev=1607975&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/SimpleContentRewritingContext.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter2/impl/SimpleContentRewritingContext.java Sat Jul 5 04:55:29 2014
@@ -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.webcontent2.rewriter2.impl;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.portals.applications.webcontent2.rewriter2.ContentRewritingContext;
+
+public class SimpleContentRewritingContext implements ContentRewritingContext
+{
+
+ private Map<String, Object> attributes;
+
+ public boolean hasAttribute(String name)
+ {
+ if (attributes == null) {
+ return false;
+ }
+
+ return attributes.containsKey(name);
+ }
+
+ public Object getAttribute(String name)
+ {
+ if (attributes == null) {
+ return null;
+ }
+
+ return attributes.get(name);
+ }
+
+ public Map<String, Object> getAttributesMap()
+ {
+ if (attributes == null) {
+ return Collections.emptyMap();
+ }
+
+ return Collections.unmodifiableMap(attributes);
+ }
+
+ public void setAttribute(String name, Object value)
+ {
+ if (attributes == null) {
+ attributes = new ConcurrentHashMap<String, Object>();
+ }
+
+ attributes.put(name, value);
+ }
+
+ public void removeAttribute(String name)
+ {
+ if (attributes != null) {
+ attributes.remove(name);
+ }
+ }
+
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter2/TextLineContentRewriterTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter2/TextLineContentRewriterTest.java?rev=1607975&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter2/TextLineContentRewriterTest.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter2/TextLineContentRewriterTest.java Sat Jul 5 04:55:29 2014
@@ -0,0 +1,90 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.commons.io.output.TeeOutputStream;
+import org.apache.commons.lang.StringUtils;
+import org.apache.portals.applications.webcontent2.rewriter2.impl.AbstractTextLineContentRewriter;
+import org.apache.portals.applications.webcontent2.rewriter2.impl.SimpleContentRewritingContext;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TextLineContentRewriterTest
+{
+
+ private Source source;
+ private Sink sink;
+ private ByteArrayOutputStream sinkTeeOut;
+ private ContentRewriter contentRewriter;
+
+ @Before
+ public void before() {
+ source = new Source() {
+ public InputStream getInputStream() throws IOException
+ {
+ return TextLineContentRewriterTest.class.getResourceAsStream("announce-template.txt");
+ }
+ public Reader getReader() throws IOException
+ {
+ return new InputStreamReader(getInputStream());
+ }
+ };
+
+ sinkTeeOut = new ByteArrayOutputStream();
+ sink = new Sink() {
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TeeOutputStream(System.out, sinkTeeOut);
+ }
+ public Writer getWriter() throws IOException
+ {
+ return new OutputStreamWriter(getOutputStream());
+ }
+ };
+
+ contentRewriter = new AbstractTextLineContentRewriter() {
+ @Override
+ protected String rewriteLine(String line) throws ContentRewritingException, IOException
+ {
+ return StringUtils.replace(line, "1.3", "2.0");
+ }
+ };
+
+ }
+
+ @Test
+ public void testA() throws Exception {
+ ContentRewritingContext rewritingContext = new SimpleContentRewritingContext();
+ contentRewriter.rewrite(source, sink, rewritingContext);
+ String output = sinkTeeOut.toString();
+ assertFalse(output.contains("[ANNOUNCE] Apache Portals Applications WebContent version 1.3 Release"));
+ assertTrue(output.contains("[ANNOUNCE] Apache Portals Applications WebContent version 2.0 Release"));
+ }
+
+}
Added: portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter2/announce-template.txt
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter2/announce-template.txt?rev=1607975&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter2/announce-template.txt (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter2/announce-template.txt Sat Jul 5 04:55:29 2014
@@ -0,0 +1,19 @@
+From: John Doe <jo...@apache.org>
+To: PortalApps Users List <po...@portals.apache.org>; Portals Discussion <ge...@portals.apache.org>; announce@apache.org
+Cc: Portals PMC <pr...@portals.apache.org>
+Subject: [ANNOUNCE] Apache Portals Applications WebContent version 1.3 Release
+
+The Apache Portals team is pleased to announce the General Availability of Portals Applications WebContent version 1.3.
+
+The Apache Portals Applications WebContent 1.3 contains changes concerning primarily minor bugfixes and maintenance.
+For more information or to download the release, please visit:
+
+Website:
+http://portals.apache.org/applications
+
+Download:
+http://portals.apache.org/applications/download.html
+
+John Doe
+
+On behalf of the Apache Portals PMC
\ No newline at end of file
Modified: portals/applications/webcontent/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/pom.xml?rev=1607975&r1=1607974&r2=1607975&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/pom.xml (original)
+++ portals/applications/webcontent/trunk/pom.xml Sat Jul 5 04:55:29 2014
@@ -40,6 +40,7 @@
<org.apache.portals.bridges.velocity.version>2.0</org.apache.portals.bridges.velocity.version>
<slf4j.version>1.5.6</slf4j.version>
<junit.version>4.11</junit.version>
+ <easymock.version>3.2</easymock.version>
<nekohtml.version>0.9.5</nekohtml.version>
<castor.version>1.1.1</castor.version>
<httpcomponents-httpcore.version>4.0.1</httpcomponents-httpcore.version>
@@ -277,6 +278,13 @@
</dependency>
<dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>${easymock.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>${velocity.version}</version>