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 2008/03/20 02:33:24 UTC
svn commit: r639105 - in /lenya/trunk/src/modules/sitetree: ./ config/
java/src/org/apache/lenya/cms/cocoon/transformation/ resources/javascript/
xslt/navigation/
Author: andreas
Date: Wed Mar 19 18:33:21 2008
New Revision: 639105
URL: http://svn.apache.org/viewvc?rev=639105&view=rev
Log:
Use only resource type for sitetree icon URLs to reduce traffic.
Added:
lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/IconUrlTransformer.java
Modified:
lenya/trunk/src/modules/sitetree/config/module.xml
lenya/trunk/src/modules/sitetree/resources/javascript/lenyatree.js
lenya/trunk/src/modules/sitetree/resources/javascript/navtree.js
lenya/trunk/src/modules/sitetree/sitemap.xmap
lenya/trunk/src/modules/sitetree/xslt/navigation/sitetree2nav.xsl
Modified: lenya/trunk/src/modules/sitetree/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/config/module.xml?rev=639105&r1=639104&r2=639105&view=diff
==============================================================================
--- lenya/trunk/src/modules/sitetree/config/module.xml (original)
+++ lenya/trunk/src/modules/sitetree/config/module.xml Wed Mar 19 18:33:21 2008
@@ -23,6 +23,7 @@
<export package="org.apache.lenya.cms.site.tree"/>
<depends module="org.apache.lenya.modules.ac"/>
<depends module="org.apache.lenya.modules.usecase"/>
+ <depends module="org.apache.lenya.modules.linking"/>
<package>org.apache.lenya.modules</package>
<version>0.1-dev</version>
<name>Sitetree</name>
Added: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/IconUrlTransformer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/IconUrlTransformer.java?rev=639105&view=auto
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/IconUrlTransformer.java (added)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/IconUrlTransformer.java Wed Mar 19 18:33:21 2008
@@ -0,0 +1,139 @@
+/*
+ * 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.cms.cocoon.transformation;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.lenya.cms.linking.Link;
+import org.apache.lenya.cms.linking.LinkResolver;
+import org.apache.lenya.cms.linking.LinkRewriter;
+import org.apache.lenya.cms.linking.LinkTarget;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.publication.URLInformation;
+import org.apache.lenya.util.ServletHelper;
+import org.xml.sax.SAXException;
+
+/**
+ * Transforms <code>icon:{uuid}...</code> URLs into
+ * <code>/{pub}/{area}/{resourceType}.gif?lenya.module=sitetree</code> URLs.
+ */
+public class IconUrlTransformer extends AbstractLinkTransformer {
+
+ private LinkResolver linkResolver;
+ private IconLinkRewriter rewriter = null;
+ private DocumentFactory factory;
+ private String pubId;
+ private String area;
+
+ protected LinkRewriter getLinkRewriter() {
+ if (this.rewriter == null) {
+ this.rewriter = new IconLinkRewriter();
+ }
+ return this.rewriter;
+ }
+
+ protected class IconLinkRewriter implements LinkRewriter {
+
+ protected static final String PROTOCOL = "icon:";
+
+ public boolean matches(String url) {
+ return url.startsWith(PROTOCOL);
+ }
+
+ public String rewrite(String url) {
+ String pubId = IconUrlTransformer.this.pubId;
+ String area = IconUrlTransformer.this.area;
+ StringBuffer iconUrl = new StringBuffer();
+ iconUrl.append("/").append(pubId).append("/").append(area).append("/");
+ String name = "default";
+ if (url.length() > PROTOCOL.length()) {
+ String suffix = url.substring(PROTOCOL.length());
+ String linkUri = "lenya-document:" + suffix;
+ try {
+ Link link = getLink(linkUri, pubId, area);
+ LinkTarget target = IconUrlTransformer.this.linkResolver.resolve(
+ IconUrlTransformer.this.factory, link.getUri());
+ if (target.exists()) {
+ Document doc = target.getDocument();
+ ResourceType type = doc.getResourceType();
+ if (Arrays.asList(type.getFormats()).contains("icon")) {
+ name = type.getName();
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ iconUrl.append(name).append(".gif?lenya.module=sitetree");
+ return iconUrl.toString();
+ }
+
+ protected Link getLink(String linkUri, String pubId, String area)
+ throws MalformedURLException {
+ Link link = new Link(linkUri);
+ if (link.getArea() == null) {
+ link.setArea(area);
+ }
+ if (link.getPubId() == null) {
+ link.setPubId(pubId);
+ }
+ return link;
+ }
+
+ }
+
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
+ throws ProcessingException, SAXException, IOException {
+ super.setup(resolver, objectModel, src, params);
+ try {
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ this.factory = DocumentUtil.getDocumentFactory(this.manager, request);
+ this.linkResolver = (LinkResolver) this.manager.lookup(LinkResolver.ROLE);
+
+ String webappUrl = ServletHelper.getWebappURI(request);
+ URLInformation url = new URLInformation(webappUrl);
+ this.pubId = url.getPublicationId();
+ this.area = url.getArea();
+
+ } catch (ServiceException e) {
+ throw new ProcessingException(e);
+ }
+ }
+
+ public void dispose() {
+ super.dispose();
+ if (this.linkResolver != null) {
+ this.manager.release(linkResolver);
+ }
+ }
+
+}
Modified: lenya/trunk/src/modules/sitetree/resources/javascript/lenyatree.js
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/resources/javascript/lenyatree.js?rev=639105&r1=639104&r2=639105&view=diff
==============================================================================
--- lenya/trunk/src/modules/sitetree/resources/javascript/lenyatree.js (original)
+++ lenya/trunk/src/modules/sitetree/resources/javascript/lenyatree.js Wed Mar 19 18:33:21 2008
@@ -245,17 +245,14 @@
else {
var href;
if (steps.length < 4) {
- href = AREA_BASE_PATH + "/folder";
- }
- else if(item.href == "") {
- href = AREA_BASE_PATH + "/default";
+ href = AREA_BASE_PATH + "/folder.gif?lenya.module=sitetree";
}
else {
- href = item.href;
+ href = item.icon;
}
var img = this.doc.createElement('img');
var language = CHOSEN_LANGUAGE;
- img.setAttribute('src', href + '.gif?lenya.module=sitetree');
+ img.setAttribute('src', href);
img.setAttribute('alt', '');
return img;
}
Modified: lenya/trunk/src/modules/sitetree/resources/javascript/navtree.js
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/resources/javascript/navtree.js?rev=639105&r1=639104&r2=639105&view=diff
==============================================================================
--- lenya/trunk/src/modules/sitetree/resources/javascript/navtree.js (original)
+++ lenya/trunk/src/modules/sitetree/resources/javascript/navtree.js Wed Mar 19 18:33:21 2008
@@ -51,6 +51,7 @@
newItem.uuid = node.getAttribute('uuid');
newItem.isprotected = isNodeProtected(node);
newItem.href = node.getAttribute('href');
+ newItem.icon = node.getAttribute('icon');
newItem.label = getLabel(node);
newItem.existsChosenLanguage = existsChosenLanguage(node);
newItem.langSuffix = node.getAttribute('language-suffix');
Modified: lenya/trunk/src/modules/sitetree/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/sitemap.xmap?rev=639105&r1=639104&r2=639105&view=diff
==============================================================================
--- lenya/trunk/src/modules/sitetree/sitemap.xmap (original)
+++ lenya/trunk/src/modules/sitetree/sitemap.xmap Wed Mar 19 18:33:21 2008
@@ -39,10 +39,15 @@
<urls type="relative"/>
<transform namespace="http://apache.org/cocoon/lenya/navigation/1.0" element="node" attribute="href"/>
</map:transformer>
+ <map:transformer logger="lenya.sitemap.transformer.uuid2url" name="icon-sitetree"
+ src="org.apache.lenya.cms.cocoon.transformation.IconUrlTransformer">
+ <transform namespace="http://apache.org/cocoon/lenya/navigation/1.0" element="node" attribute="icon"/>
+ </map:transformer>
<map:transformer logger="lenya.sitemap.transformer.proxy" name="proxy-sitetree"
src="org.apache.lenya.cms.cocoon.transformation.ProxyTransformer">
<transform namespace="http://apache.org/cocoon/lenya/navigation/1.0" element="site" attribute="href"/>
<transform namespace="http://apache.org/cocoon/lenya/navigation/1.0" element="node" attribute="href"/>
+ <transform namespace="http://apache.org/cocoon/lenya/navigation/1.0" element="node" attribute="icon"/>
</map:transformer>
</map:transformers>
</map:components>
@@ -94,6 +99,7 @@
<!-- pattern: {1:nav-element}/{2:pub-id}/{3:area}/{4:default-language}/{5:language}/{6:path}.xml -->
<map:match pattern="*/*/*/*/*/**.xml">
<map:generate src="cocoon:/navtree/{2}/{3}/{4}/{5}/{6}.xml"/>
+ <map:transform type="sitemeta"/>
<map:transform src="fallback://lenya/modules/sitetree/xslt/navigation/{1}.xsl">
<map:parameter name="area" value="{3}"/>
<map:parameter name="root" value="/{2}/{3}/"/>
@@ -150,6 +156,7 @@
<map:parameter name="locale" value="{request:locale}"/>
</map:transform>
<map:transform type="uuid2url-sitetree"/>
+ <map:transform type="icon-sitetree"/>
<map:transform type="proxy-sitetree"/>
<map:serialize type="xml"/>
</map:match>
@@ -173,18 +180,9 @@
<map:match pattern="*/*/default.gif">
<map:read src="fallback://lenya/modules/sitetree/resources/icons/default.gif"/>
</map:match>
-
- <map:match pattern="*/*/**.gif">
- <map:select type="parameter">
- <map:parameter name="parameter-selector-test"
- value="{resource-type:{doc-info:{1}:{2}:{page-envelope:document-uuid}:{page-envelope:language}:resourceType}:supportsFormat:icon}"/>
- <map:when test="true">
- <map:read src="lenya-document:{page-envelope:document-uuid},lang={page-envelope:language},area={2},pub={1}?format=icon"/>
- </map:when>
- <map:otherwise>
- <map:read src="fallback://lenya/modules/sitetree/resources/icons/default.gif"/>
- </map:otherwise>
- </map:select>
+
+ <map:match pattern="*/*/*.gif">
+ <map:read src="{resource-type:{3}:format-icon}" mime-type="image/gif"/>
</map:match>
</map:pipeline>
Modified: lenya/trunk/src/modules/sitetree/xslt/navigation/sitetree2nav.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/xslt/navigation/sitetree2nav.xsl?rev=639105&r1=639104&r2=639105&view=diff
==============================================================================
--- lenya/trunk/src/modules/sitetree/xslt/navigation/sitetree2nav.xsl (original)
+++ lenya/trunk/src/modules/sitetree/xslt/navigation/sitetree2nav.xsl Wed Mar 19 18:33:21 2008
@@ -144,6 +144,15 @@
</xsl:when>
</xsl:choose>
</xsl:attribute>
+
+ <xsl:attribute name="icon">
+ <xsl:text>icon:</xsl:text>
+ <xsl:if test="@uuid">
+ <xsl:value-of select="@uuid"/>
+ <xsl:text>,lang=</xsl:text><xsl:value-of select="$existinglanguage"/>
+ <xsl:value-of select="$areaParam"/>
+ </xsl:if>
+ </xsl:attribute>
<xsl:if test="@mimetype">
<xsl:attribute name="mimetype">
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org