cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andr...@apache.org
Subject svn commit: r809303 - in /cocoon/whiteboard/blocks: ./ cocoon-links-impl/ cocoon-links-impl/src/ cocoon-links-impl/src/main/ cocoon-links-impl/src/main/java/ cocoon-links-impl/src/main/java/org/ cocoon-links-impl/src/main/java/org/apache/ cocoon-links-...
Date Sun, 30 Aug 2009 10:48:15 GMT
Author: andreas
Date: Sun Aug 30 10:48:13 2009
New Revision: 809303

URL: http://svn.apache.org/viewvc?rev=809303&view=rev
Log:
Importing first version of links block.

Added:
    cocoon/whiteboard/blocks/
    cocoon/whiteboard/blocks/cocoon-links-impl/
    cocoon/whiteboard/blocks/cocoon-links-impl/pom.xml
    cocoon/whiteboard/blocks/cocoon-links-impl/src/
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AbstractLinkTransformer.java
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfiguration.java
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfigurationSet.java
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/ChainLinkRewriter.java
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/LinkRewriter.java
    cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/PrefixRewriter.java
    cocoon/whiteboard/blocks/eclipse/
    cocoon/whiteboard/blocks/eclipse/.classpath
    cocoon/whiteboard/blocks/eclipse/.externalToolBuilders/
    cocoon/whiteboard/blocks/eclipse/.externalToolBuilders/Maven_Ant_Builder.launch
    cocoon/whiteboard/blocks/eclipse/.project
    cocoon/whiteboard/blocks/eclipse/.settings/
    cocoon/whiteboard/blocks/eclipse/.settings/org.eclipse.jdt.core.prefs
    cocoon/whiteboard/blocks/eclipse/.settings/org.maven.ide.eclipse.prefs
    cocoon/whiteboard/blocks/eclipse/maven-eclipse.xml

Added: cocoon/whiteboard/blocks/cocoon-links-impl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/cocoon-links-impl/pom.xml?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/cocoon-links-impl/pom.xml (added)
+++ cocoon/whiteboard/blocks/cocoon-links-impl/pom.xml Sun Aug 30 10:48:13 2009
@@ -0,0 +1,49 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  
+  <modelVersion>4.0.0</modelVersion>  
+  <packaging>jar</packaging>  
+  
+  <parent>
+    <artifactId>cocoon-blocks-modules</artifactId>
+    <groupId>org.apache.cocoon</groupId>
+    <version>6-SNAPSHOT</version>
+    <relativePath>../../pom.xml</relativePath>
+  </parent>
+  <groupId>org.apache.cocoon</groupId>
+  <artifactId>cocoon-links-impl</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <name>Cocoon Links Block Implementation</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AbstractLinkTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AbstractLinkTransformer.java?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AbstractLinkTransformer.java
(added)
+++ cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AbstractLinkTransformer.java
Sun Aug 30 10:48:13 2009
@@ -0,0 +1,254 @@
+/*
+ * 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.cocoon.links;
+
+import java.io.IOException;
+import java.security.AccessControlException;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.transformation.AbstractSAXTransformer;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * <p>
+ * This transformer processes all links which are configured using <code>&lt;transform/&gt;</code>
+ * elements.
+ * </p>
+ * <p>
+ * If the link rewriter returns <code>null</code> for a link, an attribute can
be added to the
+ * corresponding element, with an optional message of the form "Broken link: ...".
+ * </p>
+ * <code><pre>
+ *   &lt;map:transformer ... &gt;
+ *     &lt;transform namespace=&quot;http://www.w3.org/1999/xhtml&quot; element=&quot;a&quot;
attribute=&quot;href&quot;/&gt;
+ *     &lt;transform namespace=&quot;...&quot; ... /&gt;
+ *     &lt;markBrokenLinks attribute=&quot;...&quot; value=&quot;...&quot;
messageAttribute=&quot;...&quot;/&gt;
+ *   &lt;/map:transformer&gt;
+ * </pre></code>
+ * <p>
+ * The reference URL can optionally be passed using the <em>url</em> parameter.
+ * </p>
+ */
+public abstract class AbstractLinkTransformer extends AbstractSAXTransformer {
+
+    protected static final String PARAM_URL = "url";
+
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
+            throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, params);
+    }
+
+    private boolean markBrokenLinks;
+    private String brokenLinkAttribute;
+    private String brokenLinkValue;
+    private String brokenLinkMessageAttribute;
+    private AttributeConfigurationSet attributeConfigs = new AttributeConfigurationSet();
+
+    public void configure(Configuration config) throws ConfigurationException {
+        super.configure(config);
+        Configuration[] transformConfigs = config.getChildren("transform");
+        for (Configuration transformConfig : transformConfigs) {
+            String namespace = transformConfig.getAttribute("namespace");
+            String element = transformConfig.getAttribute("element");
+            String attribute = transformConfig.getAttribute("attribute");
+            AttributeConfiguration attrConfig = new AttributeConfiguration(namespace, element,
+                    attribute);
+            this.attributeConfigs.add(attrConfig);
+        }
+        Configuration brokenLinksConfig = config.getChild("markBrokenLinks", false);
+        if (brokenLinksConfig != null) {
+            this.brokenLinkAttribute = brokenLinksConfig.getAttribute("attribute");
+            this.brokenLinkValue = brokenLinksConfig.getAttribute("value");
+            String messageAttr = brokenLinksConfig.getAttribute("messageAttribute", null);
+            if (messageAttr != null) {
+                this.brokenLinkMessageAttribute = messageAttr;
+            }
+            this.markBrokenLinks = true;
+        } else {
+            this.markBrokenLinks = false;
+        }
+    }
+
+    protected String indent = "";
+    protected boolean ignoreLinkElement = false;
+    private Stack<Boolean> ignoreLinkElementStack = new Stack<Boolean>();
+    protected boolean useIgnore = false;
+
+    /**
+     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String,
+     *      java.lang.String, org.xml.sax.Attributes)
+     */
+    public void startElement(String uri, String name, String qname, Attributes attrs)
+            throws SAXException {
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug(
+                    this.indent + "<" + qname + "> (ignoreAElement = " + this.ignoreLinkElement
+                            + ")");
+            this.indent += "  ";
+        }
+
+        Set<AttributeConfiguration> configs = this.attributeConfigs.getMatchingConfigurations(uri,
+                name, attrs);
+        AttributesImpl newAttrs = null;
+
+        if (!configs.isEmpty()) {
+            newAttrs = new AttributesImpl(attrs);
+            this.ignoreLinkElement = false;
+
+            for (AttributeConfiguration config : configs) {
+                String linkUrl = newAttrs.getValue(config.attribute);
+                try {
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug(this.indent + "link URL: [" + linkUrl + "]");
+                    }
+                    handleLink(linkUrl, config, newAttrs);
+                } catch (final Exception e) {
+                    getLogger().error("startElement failed: ", e);
+                    throw new SAXException(e);
+                }
+            }
+
+            // use existsMatching to match up with endElement
+            if (this.useIgnore) {
+                if (this.ignoreLinkElement) {
+                    this.ignoreLinkElementStack.push(Boolean.TRUE);
+                    return;
+                } else {
+                    this.ignoreLinkElementStack.push(Boolean.FALSE);
+                }
+            }
+        }
+
+        if (newAttrs != null) {
+            attrs = newAttrs;
+        }
+        super.startElement(uri, name, qname, attrs);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug(this.indent + "<" + qname + "> sent");
+        }
+    }
+
+    /**
+     * Handle a link in the source SAX stream.
+     * @param linkUrl The link URL.
+     * @param config The attribute configuration which matched the link.
+     * @param newAttrs The new attributes which will be added to the result element.
+     * @throws Exception if an error occurs.
+     */
+    protected void handleLink(String linkUrl, AttributeConfiguration config, AttributesImpl
newAttrs)
+            throws Exception {
+        if (getLinkRewriter().matches(linkUrl)) {
+            String rewrittenUrl = getLinkRewriter().rewrite(linkUrl);
+            if (rewrittenUrl != null) {
+                setAttribute(newAttrs, config.attribute, rewrittenUrl);
+            } else {
+                markBrokenLink(newAttrs, config.attribute, linkUrl);
+            }
+        }
+    }
+
+    /**
+     * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String,
+     *      java.lang.String)
+     */
+    public void endElement(String uri, String name, String qname) throws SAXException {
+        if (getLogger().isDebugEnabled()) {
+            this.indent = this.indent.substring(2);
+            getLogger().debug(this.indent + "</" + qname + ">");
+        }
+        
+        if (this.attributeConfigs.existsMatchingConfiguration(uri, name) && this.useIgnore)
{
+            if (((Boolean) this.ignoreLinkElementStack.pop()).booleanValue()) {
+                this.ignoreLinkElement = false;
+                return;
+            }
+        }
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug(this.indent + "</" + qname + "> sent");
+        }
+        super.endElement(uri, name, qname);
+    }
+
+    /**
+     * Sets the value of a certain attribute.
+     * 
+     * @param attr The attributes.
+     * @param name The attribute name.
+     * @param value The value.
+     * @throws IllegalArgumentException if the href attribute is not contained in this attributes.
+     */
+    protected void setAttribute(AttributesImpl attr, String name, String value) {
+        int position = attr.getIndex(name);
+        if (position == -1) {
+            throw new IllegalArgumentException("The attribute [" + name + "] is not available!");
+        }
+        attr.setValue(position, value);
+    }
+
+    /**
+     * @return The link rewriter used by this transformer.
+     */
+    protected abstract LinkRewriter getLinkRewriter();
+
+    /**
+     * Marks a link element as broken and removes the attribute which contained the URL.
+     * @param newAttrs The new attributes.
+     * @param attrName The attribute name containing the URL which could not be rewritten.
+     * @param brokenLinkUri The broken link URI.
+     * @throws AccessControlException when something went wrong.
+     */
+    protected void markBrokenLink(AttributesImpl newAttrs, String attrName, String brokenLinkUri)
{
+        if (this.markBrokenLinks) {
+            if (newAttrs.getIndex(this.brokenLinkAttribute) > -1) {
+                newAttrs.removeAttribute(newAttrs.getIndex(this.brokenLinkAttribute));
+            }
+            if (newAttrs.getIndex(attrName) > -1) {
+                newAttrs.setAttribute(newAttrs.getIndex(attrName), "", attrName, attrName,
"CDATA",
+                        "");
+            }
+            String msgAttr = this.brokenLinkMessageAttribute;
+            if (msgAttr != null) {
+                int index = newAttrs.getIndex(msgAttr);
+                if (index > -1) {
+                    newAttrs.removeAttribute(index);
+                }
+                String msg = "Broken link: " + brokenLinkUri;
+                newAttrs.addAttribute("", msgAttr, msgAttr, "CDATA", msg);
+            }
+            newAttrs.addAttribute("", this.brokenLinkAttribute, this.brokenLinkAttribute,
"CDATA",
+                    this.brokenLinkValue);
+        }
+    }
+
+    public void recycle() {
+        super.recycle();
+        this.ignoreLinkElementStack.clear();
+    }
+
+}

Added: cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfiguration.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfiguration.java?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfiguration.java
(added)
+++ cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfiguration.java
Sun Aug 30 10:48:13 2009
@@ -0,0 +1,48 @@
+package org.apache.cocoon.links;
+
+import org.xml.sax.Attributes;
+
+/**
+ * Declaration of an attribute which should be transformed.
+ */
+public class AttributeConfiguration {
+
+    protected final String element;
+    protected final String namespace;
+    protected final String attribute;
+
+    /**
+     * @param namespace The namespace of the element.
+     * @param element The local name of the element.
+     * @param attribute The name of the attribute to transform.
+     */
+    public AttributeConfiguration(String namespace, String element, String attribute) {
+        this.namespace = namespace;
+        this.element = element;
+        this.attribute = attribute;
+    }
+
+    /**
+     * @param uri The namespace URI.
+     * @param localName The local name.
+     * @param attrs The attributes.
+     * @return If this configuration matches the parameters.
+     */
+    public boolean matches(String uri, String localName, Attributes attrs) {
+        return this.namespace.equals(uri) && this.element.equals(localName)
+                && attrs.getValue(this.attribute) != null;
+    }
+
+    public String getNamespace() {
+        return this.namespace;
+    }
+
+    public String getElementLocalName() {
+        return this.element;
+    }
+    
+    public String getAttributeName() {
+        return this.attribute;
+    }
+
+}
\ No newline at end of file

Added: cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfigurationSet.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfigurationSet.java?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfigurationSet.java
(added)
+++ cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/AttributeConfigurationSet.java
Sun Aug 30 10:48:13 2009
@@ -0,0 +1,90 @@
+package org.apache.cocoon.links;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.xml.sax.Attributes;
+
+public class AttributeConfigurationSet implements Iterable<AttributeConfiguration>
{
+    
+    private static final long serialVersionUID = 1L;
+    
+    /**
+     * Set of supported local names for quick pre-checks.
+     */
+    private Set<String> localNames = new HashSet<String>();
+    private Set<AttributeConfiguration> configs = new HashSet<AttributeConfiguration>();
+    
+    /**
+     * @param namespace The namespace URI.
+     * @param localName The local name.
+     * @param attrs The attributes.
+     * @return A set of {@link AttributeConfiguration} objects.
+     */
+    public Set<AttributeConfiguration> getMatchingConfigurations(String namespace,
String localName, Attributes attrs) {
+
+        // pre-check for performance reasons
+        if (!existsMatchingConfiguration(namespace, localName)) {
+            return Collections.emptySet();
+        }
+
+        String key = getCacheKey(namespace, localName);
+
+        // don't initialize yet for performance reasons
+        Set<AttributeConfiguration> configs = null;
+        Set<AttributeConfiguration> allConfigs = this.namespaceLocalname2configSet.get(key);
+        for (AttributeConfiguration config : allConfigs) {
+            if (config.matches(namespace, localName, attrs)) {
+                if (configs == null) {
+                    configs = new HashSet<AttributeConfiguration>();
+                }
+                configs.add(config);
+            }
+        }
+        if (configs == null) {
+            configs = Collections.emptySet();
+        }
+        return configs;
+    }
+
+    /**
+     * Cache to improve performance.
+     */
+    private Map<String, Set<AttributeConfiguration>> namespaceLocalname2configSet
= new HashMap<String, Set<AttributeConfiguration>>();
+
+    public boolean existsMatchingConfiguration(String namespace, String localName) {
+        // quick pre-check
+        if (!this.localNames.contains(localName)) {
+            return false;
+        }
+
+        // more expensive check
+        String key = getCacheKey(namespace, localName);
+        return this.namespaceLocalname2configSet.containsKey(key);
+    }
+
+    protected String getCacheKey(String namespace, String localName) {
+        return namespace + " " + localName;
+    }
+    
+    public void add(AttributeConfiguration config) {
+        String key = getCacheKey(config.getNamespace(), config.getElementLocalName());
+        Set<AttributeConfiguration> configs = this.namespaceLocalname2configSet.get(key);
+        this.localNames.add(config.getElementLocalName());
+        if (configs == null) {
+            configs = new HashSet<AttributeConfiguration>();
+            this.namespaceLocalname2configSet.put(key, configs);
+        }
+        configs.add(config);
+        this.configs.add(config);
+    }
+
+    public Iterator<AttributeConfiguration> iterator() {
+        return this.configs.iterator();
+    }
+
+}

Added: cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/ChainLinkRewriter.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/ChainLinkRewriter.java?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/ChainLinkRewriter.java
(added)
+++ cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/ChainLinkRewriter.java
Sun Aug 30 10:48:13 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.cocoon.links;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.springframework.util.Assert;
+
+/**
+ * A chain of link rewriters. The output of one rewriter serves as the input of
+ * the next one. If a rewriter doesn't match a link, it is skipped.
+ */
+public class ChainLinkRewriter implements LinkRewriter {
+
+    private List<LinkRewriter> rewriters = new ArrayList<LinkRewriter>();
+
+    /**
+     * Adds a rewriter to the end of the chain.
+     * @param rewriter The rewriter.
+     */
+    public void add(LinkRewriter rewriter) {
+        Assert.notNull(rewriter, "rewriter");
+        this.rewriters.add(rewriter);
+    }
+
+    public boolean matches(String url) {
+        return true;
+    }
+
+    public String rewrite(String url) {
+        String link = url;
+        Iterator<LinkRewriter> i = this.rewriters.iterator();
+        while (link != null && i.hasNext()) {
+            LinkRewriter rewriter = (LinkRewriter) i.next();
+            if (rewriter.matches(link)) {
+                link = rewriter.rewrite(link);
+            }
+        }
+        return link;
+    }
+
+}

Added: cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/LinkRewriter.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/LinkRewriter.java?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/LinkRewriter.java
(added)
+++ cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/LinkRewriter.java
Sun Aug 30 10:48:13 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.cocoon.links;
+
+/**
+ * Interface for services which convert links from one form to another.
+ */
+public interface LinkRewriter {
+    
+    /**
+     * @param url The URL.
+     * @return If this rewriter feels responsible for the URL.
+     */
+    boolean matches(String url);
+    
+    /**
+     * @param url The original URL.
+     * @return The rewritten URL or <code>null</code> if the URL could not be
rewritten.
+     */
+    String rewrite(String url);
+
+}

Added: cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/PrefixRewriter.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/PrefixRewriter.java?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/PrefixRewriter.java
(added)
+++ cocoon/whiteboard/blocks/cocoon-links-impl/src/main/java/org/apache/cocoon/links/PrefixRewriter.java
Sun Aug 30 10:48:13 2009
@@ -0,0 +1,38 @@
+/*
+ * 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.cocoon.links;
+
+public class PrefixRewriter implements LinkRewriter {
+    
+    private String sourcePrefix;
+    private String targetPrefix;
+    
+    public PrefixRewriter(String sourcePrefix, String targetPrefix) {
+        this.sourcePrefix = sourcePrefix;
+        this.targetPrefix = targetPrefix;
+    }
+
+    public boolean matches(String url) {
+        return url.startsWith(this.sourcePrefix);
+    }
+
+    public String rewrite(String url) {
+        return this.targetPrefix + url.substring(this.sourcePrefix.length());
+    }
+
+}

Added: cocoon/whiteboard/blocks/eclipse/.classpath
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/eclipse/.classpath?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/eclipse/.classpath (added)
+++ cocoon/whiteboard/blocks/eclipse/.classpath Sun Aug 30 10:48:13 2009
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: cocoon/whiteboard/blocks/eclipse/.externalToolBuilders/Maven_Ant_Builder.launch
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/eclipse/.externalToolBuilders/Maven_Ant_Builder.launch?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/eclipse/.externalToolBuilders/Maven_Ant_Builder.launch (added)
+++ cocoon/whiteboard/blocks/eclipse/.externalToolBuilders/Maven_Ant_Builder.launch Sun Aug
30 10:48:13 2009
@@ -0,0 +1,24 @@
+<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
+  <booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
+  <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,clean"/>
+  <booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
+  <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+  <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="cocoon-links-impl"/>
+  <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
+  <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${build_project}/maven-eclipse.xml"/>
+  <stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${build_project}"/>
+  <stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
+  <booleanAttribute key="org.eclipse.debug.core.capture_output" value="false"/>
+  <stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml
version=&apos;1.0&apos;?&gt;&lt;launchConfigurationWorkingSet editPageId=&apos;org.eclipse.ui.resourceWorkingSetPage&apos;
factoryID=&apos;org.eclipse.ui.internal.WorkingSetFactory&apos; label=&apos;workingSet&apos;
name=&apos;workingSet&apos;&gt;&lt;item factoryID=&apos;org.eclipse.ui.internal.model.ResourceFactory&apos;
path=&apos;cocoon-links-impl&apos; type=&apos;4&apos;/&gt;&lt;/launchConfigurationWorkingSet&gt;}"/>
+  <stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
+  <booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
+  <booleanAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON" value="false"/>
+  <booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
+  <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
+  <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+    <listEntry value="1"/>
+  </listAttribute>
+  <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+    <listEntry value="/cocoon-links-impl/maven-eclipse.xml"/>
+  </listAttribute>
+</launchConfiguration>
\ No newline at end of file

Added: cocoon/whiteboard/blocks/eclipse/.project
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/eclipse/.project?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/eclipse/.project (added)
+++ cocoon/whiteboard/blocks/eclipse/.project Sun Aug 30 10:48:13 2009
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cocoon-links-impl</name>
+	<comment>The Apache Software Foundation provides support for the Apache community
of open-source software projects.
+    The Apache projects are characterized by a collaborative, consensus based development
process, an open and
+    pragmatic software license, and a desire to create high quality software that leads the
way in its field.
+    We consider ourselves not simply a group of projects sharing a server, but rather a community
of developers
+    and users.</comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
+			<arguments>
+				<dictionary>
+					<key>LaunchConfigHandle</key>
+					<value>&lt;project&gt;/.externalToolBuilders/Maven_Ant_Builder.launch</value>
+				</dictionary>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: cocoon/whiteboard/blocks/eclipse/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/eclipse/.settings/org.eclipse.jdt.core.prefs?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/eclipse/.settings/org.eclipse.jdt.core.prefs (added)
+++ cocoon/whiteboard/blocks/eclipse/.settings/org.eclipse.jdt.core.prefs Sun Aug 30 10:48:13
2009
@@ -0,0 +1,5 @@
+#Sun Aug 30 11:12:47 CEST 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5

Added: cocoon/whiteboard/blocks/eclipse/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/eclipse/.settings/org.maven.ide.eclipse.prefs?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/eclipse/.settings/org.maven.ide.eclipse.prefs (added)
+++ cocoon/whiteboard/blocks/eclipse/.settings/org.maven.ide.eclipse.prefs Sun Aug 30 10:48:13
2009
@@ -0,0 +1,9 @@
+#Sun Aug 30 11:12:16 CEST 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1

Added: cocoon/whiteboard/blocks/eclipse/maven-eclipse.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/blocks/eclipse/maven-eclipse.xml?rev=809303&view=auto
==============================================================================
--- cocoon/whiteboard/blocks/eclipse/maven-eclipse.xml (added)
+++ cocoon/whiteboard/blocks/eclipse/maven-eclipse.xml Sun Aug 30 10:48:13 2009
@@ -0,0 +1,8 @@
+<project default="copy-resources">
+  <target name="init"/>
+  <target name="copy-resources" depends="init">
+    <copy todir="target/classes/META-INF" filtering="false">
+      <fileset dir="." includes="LICENSE.txt|NOTICE.txt"/>
+    </copy>
+  </target>
+</project>
\ No newline at end of file



Mime
View raw message