Author: andreas
Date: Mon Nov 26 07:50:23 2007
New Revision: 598318
URL: http://svn.apache.org/viewvc?rev=598318&view=rev
Log:
Adding Batik protocol handlers for site: and lenya-document:, this allows to use internal URLs. Fixes bug 43933.
Added:
lenya/trunk/src/modules/svg/config/cocoon-xconf/
lenya/trunk/src/modules/svg/config/cocoon-xconf/protocol-handlers.xconf
lenya/trunk/src/modules/svg/java/
lenya/trunk/src/modules/svg/java/src/
lenya/trunk/src/modules/svg/java/src/org/
lenya/trunk/src/modules/svg/java/src/org/apache/
lenya/trunk/src/modules/svg/java/src/org/apache/lenya/
lenya/trunk/src/modules/svg/java/src/org/apache/lenya/modules/
lenya/trunk/src/modules/svg/java/src/org/apache/lenya/modules/svg/
lenya/trunk/src/modules/svg/java/src/org/apache/lenya/modules/svg/ProtocolHandler.java
Modified:
lenya/trunk/src/modules/svg/sitemap.xmap
lenya/trunk/src/modules/svg/xslt/scale.xsl
Added: lenya/trunk/src/modules/svg/config/cocoon-xconf/protocol-handlers.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/config/cocoon-xconf/protocol-handlers.xconf?rev=598318&view=auto
==============================================================================
--- lenya/trunk/src/modules/svg/config/cocoon-xconf/protocol-handlers.xconf (added)
+++ lenya/trunk/src/modules/svg/config/cocoon-xconf/protocol-handlers.xconf Mon Nov 26 07:50:23 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+ 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.xconf 164635 2005-04-25 20:01:43Z tschlabach $ -->
+
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.modules.svg.SiteProtocolHandler']">
+
+ <component logger="lenya.modules.svg"
+ role="org.apache.lenya.modules.svg.SiteProtocolHandler"
+ class="org.apache.lenya.modules.svg.ProtocolHandler">
+ <parameter name="protocol" value="site"/>
+ </component>
+
+ <component logger="lenya.modules.svg"
+ role="org.apache.lenya.modules.svg.LenyaDocumentProtocolHandler"
+ class="org.apache.lenya.modules.svg.ProtocolHandler">
+ <parameter name="protocol" value="lenya-document"/>
+ </component>
+
+</xconf>
Added: lenya/trunk/src/modules/svg/java/src/org/apache/lenya/modules/svg/ProtocolHandler.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/java/src/org/apache/lenya/modules/svg/ProtocolHandler.java?rev=598318&view=auto
==============================================================================
--- lenya/trunk/src/modules/svg/java/src/org/apache/lenya/modules/svg/ProtocolHandler.java (added)
+++ lenya/trunk/src/modules/svg/java/src/org/apache/lenya/modules/svg/ProtocolHandler.java Mon Nov 26 07:50:23 2007
@@ -0,0 +1,123 @@
+/*
+ * 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.svg;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.batik.util.ParsedURL;
+import org.apache.batik.util.ParsedURLData;
+import org.apache.batik.util.ParsedURLProtocolHandler;
+import org.apache.cocoon.CascadingIOException;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+
+/**
+ * Batik URL protocol handler for protocols which are handled by the SourceResolver.
+ */
+public class ProtocolHandler extends AbstractLogEnabled implements ParsedURLProtocolHandler,
+ ThreadSafe, Startable, Component, Serviceable, Parameterizable {
+
+ protected static final String PARAM_PROTOCOL = "protocol";
+
+ public static final String ROLE = ProtocolHandler.class.getName();
+
+ private SourceResolver resolver;
+ private ServiceManager manager;
+
+ private String protocol;
+
+ public ParsedURLData parseURL(String urlStr) {
+ if (this.resolver == null) {
+ throw new IllegalStateException("Please call setResolver() first!");
+ }
+ return new ParsedUrlData(getProtocolHandled(), this.resolver, urlStr);
+ }
+
+ public ParsedURLData parseURL(ParsedURL basepurl, String urlStr) {
+ return parseURL(urlStr);
+ }
+
+ static class ParsedUrlData extends ParsedURLData {
+
+ private Source source;
+ private SourceResolver resolver;
+ private String url;
+
+ public ParsedUrlData(String protocol, SourceResolver resolver, String url) {
+ this.url = url;
+ this.protocol = protocol;
+ this.resolver = resolver;
+ try {
+ this.source = resolver.resolveURI(url);
+ this.contentType = this.source.getMimeType();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Open a stream for the data. If the thread-local
+ * <code>SourceResolver</code> exists, then use it, otherwise fall
+ * back to <code>SourceHandler</code>.
+ */
+ protected InputStream openStreamInternal(String userAgent, Iterator mimeTypes,
+ Iterator encodingTypes) throws IOException {
+ try {
+ return this.source.getInputStream();
+ } catch (Exception e) {
+ throw new CascadingIOException("Cannot open URL " + this.url, e);
+ } finally {
+ this.resolver.release(this.source);
+ }
+ }
+
+ }
+
+ public void start() throws Exception {
+ this.resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ ParsedURL.registerHandler(this);
+ }
+
+ public void stop() throws Exception {
+ }
+
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ public String getProtocolHandled() {
+ return this.protocol;
+ }
+
+ public void parameterize(Parameters params) throws ParameterException {
+ this.protocol = params.getParameter(PARAM_PROTOCOL);
+ }
+
+}
Modified: lenya/trunk/src/modules/svg/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/sitemap.xmap?rev=598318&r1=598317&r2=598318&view=diff
==============================================================================
--- lenya/trunk/src/modules/svg/sitemap.xmap (original)
+++ lenya/trunk/src/modules/svg/sitemap.xmap Mon Nov 26 07:50:23 2007
@@ -89,11 +89,9 @@
<map:generate src="dummy.xml"/>
<map:act type="resource-exists">
- <map:parameter name="url" value="site://{1}/{2}/{page-envelope:default-language}/{3}"/>
+ <map:parameter name="url" value="lenya-document:{page-envelope:document-uuid},lang={page-envelope:document-language},pub={1},area={2}"/>
<map:transform src="xslt/scale.xsl">
- <map:parameter name="nonProxyBaseUrl" value="http://localhost:{request:serverPort}{request:contextPath}"/>
- <map:parameter name="url" value="/{../1}/{../2}/{../3}.{../4}"/>
- <map:parameter name="revision" value="{request-param:lenya.revision}"/>
+ <map:parameter name="url" value="lenya-document:{page-envelope:document-uuid},lang={page-envelope:document-language},pub={../1},area={../2}{link:rev}"/>
<map:parameter name="width" value="{request-param:width}"/>
<map:parameter name="height" value="{request-param:height}"/>
</map:transform>
Modified: lenya/trunk/src/modules/svg/xslt/scale.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/svg/xslt/scale.xsl?rev=598318&r1=598317&r2=598318&view=diff
==============================================================================
--- lenya/trunk/src/modules/svg/xslt/scale.xsl (original)
+++ lenya/trunk/src/modules/svg/xslt/scale.xsl Mon Nov 26 07:50:23 2007
@@ -21,30 +21,13 @@
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:param name="url"/>
- <xsl:param name="nonProxyBaseUrl"/>
<xsl:param name="height"/>
<xsl:param name="width"/>
- <xsl:param name="revision"/>
-
- <!-- Workaround: Batik doesn't seem to like SSL URLs -->
- <xsl:param name="imageUrl">
- <xsl:choose>
- <xsl:when test="starts-with($url, '/')">
- <xsl:value-of select="$nonProxyBaseUrl"/><xsl:value-of select="$url"/>
- </xsl:when>
- <xsl:when test="starts-with($url, 'https:')">
- <xsl:text>http</xsl:text><xsl:value-of select="substring($url, 6)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$url"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="$revision != ''">?lenya.revision=<xsl:value-of select="$revision"/></xsl:if>
- </xsl:param>
<xsl:template match="/">
<svg width="{$width}" height="{$height}" version="1.1">
- <image x="0" y="0" width="{$width}" height="{$height}" xlink:href="{$imageUrl}" preserveAspectRatio="none"/>
+ <image x="0" y="0" width="{$width}" height="{$height}" xlink:href="{$url}" preserveAspectRatio="none"/>
</svg>
</xsl:template>
+
</xsl:stylesheet>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.