You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2007/06/26 10:00:12 UTC
svn commit: r550725 - in /lenya/sandbox/modules/feed: ./ config/ java/
java/src/ java/src/org/ java/src/org/apache/ java/src/org/apache/lenya/
java/src/org/apache/lenya/modules/ java/src/org/apache/lenya/modules/feed/
java/test/ java/test/org/ java/tes...
Author: andreas
Date: Tue Jun 26 01:00:11 2007
New Revision: 550725
URL: http://svn.apache.org/viewvc?view=rev&rev=550725
Log:
Added feed module to sandbox
Added:
lenya/sandbox/modules/feed/
lenya/sandbox/modules/feed/config/
lenya/sandbox/modules/feed/config/module.xml
lenya/sandbox/modules/feed/java/
lenya/sandbox/modules/feed/java/src/
lenya/sandbox/modules/feed/java/src/org/
lenya/sandbox/modules/feed/java/src/org/apache/
lenya/sandbox/modules/feed/java/src/org/apache/lenya/
lenya/sandbox/modules/feed/java/src/org/apache/lenya/modules/
lenya/sandbox/modules/feed/java/src/org/apache/lenya/modules/feed/
lenya/sandbox/modules/feed/java/src/org/apache/lenya/modules/feed/UnescapeXmlTransformer.java
lenya/sandbox/modules/feed/java/test/
lenya/sandbox/modules/feed/java/test/org/
lenya/sandbox/modules/feed/java/test/org/apache/
lenya/sandbox/modules/feed/java/test/org/apache/lenya/
lenya/sandbox/modules/feed/java/test/org/apache/lenya/modules/
lenya/sandbox/modules/feed/java/test/org/apache/lenya/modules/feed/
lenya/sandbox/modules/feed/java/test/org/apache/lenya/modules/feed/UnescapeXmlTransformerTest.java
lenya/sandbox/modules/feed/sitemap.xmap
lenya/sandbox/modules/feed/xslt/
lenya/sandbox/modules/feed/xslt/addXhtmlNamespace.xsl
lenya/sandbox/modules/feed/xslt/atom2collection.xsl
Added: lenya/sandbox/modules/feed/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/config/module.xml?view=auto&rev=550725
==============================================================================
--- lenya/sandbox/modules/feed/config/module.xml (added)
+++ lenya/sandbox/modules/feed/config/module.xml Tue Jun 26 01:00:11 2007
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<!-- $Id: publication.xml 374687 2006-02-03 15:24:55Z michi $ -->
+
+<module xmlns="http://apache.org/lenya/module/1.0">
+ <id>ch.becompany.website.feed</id>
+ <package>ch.becompany.website</package>
+ <version>0.1-dev</version>
+ <name>BeCompany Feed</name>
+ <lenya-version>@lenya.version@</lenya-version>
+ <description></description>
+</module>
Added: lenya/sandbox/modules/feed/java/src/org/apache/lenya/modules/feed/UnescapeXmlTransformer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/java/src/org/apache/lenya/modules/feed/UnescapeXmlTransformer.java?view=auto&rev=550725
==============================================================================
--- lenya/sandbox/modules/feed/java/src/org/apache/lenya/modules/feed/UnescapeXmlTransformer.java (added)
+++ lenya/sandbox/modules/feed/java/src/org/apache/lenya/modules/feed/UnescapeXmlTransformer.java Tue Jun 26 01:00:11 2007
@@ -0,0 +1,176 @@
+/*
+ * 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.lenya.modules.feed;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.avalon.excalibur.pool.Poolable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.serializers.XHTMLSerializer;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.transformation.AbstractSAXTransformer;
+import org.apache.cocoon.xml.StringXMLizable;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/**
+ * Transforms textual XML representations inside <code><unescape></code> elements to
+ * actual XML elements, i.e. <code><unescape>&lt;a&gt;foo&lt;/a&gt;</unescape></code>
+ * is transformed to <code><unescape><a>foo</a></unescape></code>.
+ */
+public class UnescapeXmlTransformer extends AbstractSAXTransformer implements Poolable {
+
+ private boolean isUnescaping;
+
+ protected static final String NAMESPACE = "http://apache.org/lenya/unescape/1.0";
+ protected static final String ELEMENT_UNESCAPE = "unescape";
+ protected static final Object ELEMENT_WRAP = "wrap";
+ protected static final String PROLOG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ protected static final String DEFAULT_NAMESPACE = XHTMLSerializer.XHTML1_NAMESPACE;
+ protected static final String DEFAULT_PREFIX = "xhtml";
+
+ private StringBuffer buffer;
+ private String namespace = DEFAULT_NAMESPACE;
+ private String prefix = DEFAULT_PREFIX;
+
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
+ throws ProcessingException, SAXException, IOException {
+ super.setup(resolver, objectModel, src, params);
+
+ this.namespace = params.getParameter("namespace", DEFAULT_NAMESPACE);
+ this.prefix = params.getParameter("prefix", DEFAULT_PREFIX);
+ this.isUnescaping = false;
+ }
+
+ public void startElement(String uri, String name, String raw, Attributes attr)
+ throws SAXException {
+ if (uri != null && uri.equals(NAMESPACE) && name.equals(ELEMENT_UNESCAPE)) {
+ buffer = new StringBuffer();
+ this.isUnescaping = true;
+ } else {
+ super.startElement(uri, name, raw, attr);
+ }
+ }
+
+ public void endElement(String uri, String name, String raw) throws SAXException {
+ if (uri != null && uri.equals(NAMESPACE) && name.equals(ELEMENT_UNESCAPE)) {
+ String string = "<unescape:wrap xmlns:unescape=\"http://apache.org/lenya/unescape/1.0\">"
+ + this.buffer.toString() + "</unescape:wrap>";
+ StringXMLizable xml = new StringXMLizable(string);
+ FragmentHandler fragmentHandler = new FragmentHandler(this.contentHandler, this.namespace, this.prefix);
+ xml.toSAX(fragmentHandler);
+ this.isUnescaping = false;
+ } else {
+ super.endElement(uri, name, raw);
+ }
+ }
+
+ public void characters(char[] characters, int start, int length) throws SAXException {
+ if (isUnescaping) {
+ String string = new String(characters, start, length);
+ this.buffer.append(string);
+ } else {
+ super.characters(characters, start, length);
+ }
+ }
+
+ /**
+ * Unescapes an XML fragment.
+ */
+ public static class FragmentHandler implements ContentHandler {
+
+ private ContentHandler handler;
+ private String namespace;
+ private String prefix;
+
+ /**
+ * @param handler The content handler for the generated SAX stream.
+ * @param namespace The namespace URI.
+ * @param prefix The namespace prefix.
+ */
+ public FragmentHandler(ContentHandler handler, String namespace, String prefix) {
+ this.handler = handler;
+ this.namespace = namespace;
+ this.prefix = prefix;
+ }
+
+ protected String qName(String localName) {
+ String prefixWithColon = prefix.equals("") ? "" : prefix + ":";
+ return prefixWithColon + localName;
+ }
+
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ this.handler.characters(ch, start, length);
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException {
+ if (uri != null && uri.equals(NAMESPACE) && localName.equals(ELEMENT_WRAP)) {
+ this.handler.startPrefixMapping(this.prefix, this.namespace);
+ } else {
+ this.handler.startElement(this.namespace, localName, qName(localName), atts);
+ }
+ }
+
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ if (uri != null && uri.equals(NAMESPACE) && localName.equals(ELEMENT_WRAP)) {
+ this.handler.endPrefixMapping(this.prefix);
+ } else {
+ this.handler.endElement(this.namespace, localName, qName(localName));
+ }
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ this.handler.endPrefixMapping(prefix);
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ this.handler.ignorableWhitespace(ch, start, length);
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException {
+ this.handler.processingInstruction(target, data);
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ this.handler.setDocumentLocator(locator);
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ this.handler.skippedEntity(name);
+ }
+
+ public void startDocument() throws SAXException {
+ // ignore
+ }
+
+ public void endDocument() throws SAXException {
+ // ignore
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ this.handler.startPrefixMapping(prefix, uri);
+ }
+
+ }
+
+}
Added: lenya/sandbox/modules/feed/java/test/org/apache/lenya/modules/feed/UnescapeXmlTransformerTest.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/java/test/org/apache/lenya/modules/feed/UnescapeXmlTransformerTest.java?view=auto&rev=550725
==============================================================================
--- lenya/sandbox/modules/feed/java/test/org/apache/lenya/modules/feed/UnescapeXmlTransformerTest.java (added)
+++ lenya/sandbox/modules/feed/java/test/org/apache/lenya/modules/feed/UnescapeXmlTransformerTest.java Tue Jun 26 01:00:11 2007
@@ -0,0 +1,95 @@
+/*
+ * 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.lenya.modules.feed;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+import junit.framework.TestCase;
+
+public class UnescapeXmlTransformerTest extends TestCase {
+
+ protected static final String[] ESCAPED_XML = { "this is a <a ", "href=\"foo\">link</a>" };
+
+ public void testUnescapeXml() throws Exception {
+ UnescapeXmlTransformer transformer = new UnescapeXmlTransformer();
+ TestHandler handler = new TestHandler();
+ transformer.setContentHandler(handler);
+
+ String namespace = UnescapeXmlTransformer.NAMESPACE;
+ String localName = UnescapeXmlTransformer.ELEMENT_UNESCAPE;
+
+ transformer.startElement(namespace, localName, localName, null);
+ for (int i = 0; i < ESCAPED_XML.length; i++) {
+ String string = ESCAPED_XML[i];
+ transformer.characters(string.toCharArray(), 0, string.length());
+ }
+ transformer.endElement(namespace, localName, localName);
+
+ assertFalse(handler.startDocumentCalled);
+ assertTrue(handler.success);
+ }
+
+ public static class TestHandler implements ContentHandler {
+
+ protected boolean success = false;
+ protected boolean startDocumentCalled;
+
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException {
+ if (localName.equals("a") && atts.getValue("href").equals("foo")) {
+ success = true;
+ }
+ }
+
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ }
+
+ public void endDocument() throws SAXException {
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException {
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ }
+
+ public void startDocument() throws SAXException {
+ this.startDocumentCalled = true;
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ }
+
+ }
+
+}
Added: lenya/sandbox/modules/feed/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/sitemap.xmap?view=auto&rev=550725
==============================================================================
--- lenya/sandbox/modules/feed/sitemap.xmap (added)
+++ lenya/sandbox/modules/feed/sitemap.xmap Tue Jun 26 01:00:11 2007
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<!-- $Id: doctypes.xmap 179488 2005-06-02 02:29:39Z gregor $ -->
+
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+
+ <map:components>
+ <map:transformers default="xslt">
+ <map:transformer name="unescape" src="org.apache.lenya.modules.feed.UnescapeXmlTransformer"/>
+ </map:transformers>
+ </map:components>
+
+ <map:pipelines>
+
+ <map:pipeline>
+
+ <map:match pattern="*/**">
+ <map:generate src="{2}"/>
+ <map:transform src="xslt/{1}2collection.xsl"/>
+ <map:transform type="unescape"/>
+ <map:transform src="xslt/addXhtmlNamespace.xsl"/>
+ <map:transform type="i18n">
+ <map:parameter name="locale" value="en"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
+
+ </map:pipeline>
+
+ </map:pipelines>
+</map:sitemap>
Added: lenya/sandbox/modules/feed/xslt/addXhtmlNamespace.xsl
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/xslt/addXhtmlNamespace.xsl?view=auto&rev=550725
==============================================================================
--- lenya/sandbox/modules/feed/xslt/addXhtmlNamespace.xsl (added)
+++ lenya/sandbox/modules/feed/xslt/addXhtmlNamespace.xsl Tue Jun 26 01:00:11 2007
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+ <xsl:template match="*[namespace-uri() = '']">
+ <xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:element>
+ </xsl:template>
+
+ <xsl:template match="@*|node()">
+ <xsl:copy>
+ <xsl:copy-of select="@*|node()"/>
+ </xsl:copy>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
Added: lenya/sandbox/modules/feed/xslt/atom2collection.xsl
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/feed/xslt/atom2collection.xsl?view=auto&rev=550725
==============================================================================
--- lenya/sandbox/modules/feed/xslt/atom2collection.xsl (added)
+++ lenya/sandbox/modules/feed/xslt/atom2collection.xsl Tue Jun 26 01:00:11 2007
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+ xmlns:col="http://apache.org/cocoon/lenya/collection/1.0"
+ xmlns:atom='http://www.w3.org/2005/Atom'
+ xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
+ xmlns:meta="http://apache.org/cocoon/lenya/metadata/1.0"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
+ xmlns:unescape="http://apache.org/lenya/unescape/1.0"
+ exclude-result-prefixes="atom openSearch">
+
+
+ <xsl:template match="atom:feed">
+ <col:collection>
+ <xsl:apply-templates select="atom:entry"/>
+ </col:collection>
+ </xsl:template>
+
+
+ <xsl:template match="atom:entry">
+ <col:document href="{atom:link[@type = 'text/html']/@href}">
+ <meta:metadata>
+ <dc:elements>
+ <dc:date>
+ <i18n:date-time src-pattern="yyyy-MM-dd'T'HH:mm:ss.S Z" pattern="yyyy-MM-dd HH:mm:ss">
+ <xsl:text/>
+ <xsl:value-of select="substring(atom:published, 1, 23)"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="substring(atom:published, 24, 3)"/>
+ <xsl:value-of select="substring(atom:published, 28, 2)"/>
+ <xsl:text/>
+ </i18n:date-time>
+ </dc:date>
+ <dc:title><xsl:value-of select="atom:title"/></dc:title>
+ </dc:elements>
+ </meta:metadata>
+ <html>
+ <body>
+ <p>
+ <unescape:unescape>
+ <xsl:apply-templates select="atom:content/text()"/>
+ </unescape:unescape>
+ </p>
+ </body>
+ </html>
+ </col:document>
+ </xsl:template>
+
+
+</xsl:stylesheet>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org