Author: andreas
Date: Thu Jan 31 13:37:22 2008
New Revision: 617247
URL: http://svn.apache.org/viewvc?rev=617247&view=rev
Log:
Add attribute 'default' to MetaDataTransformer. This makes the addXhtmlTitle.xsl obsolete.
Removed:
lenya/trunk/src/pubs/default/xslt/addXhtmlTitle.xsl
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/MetaDataTransformer.java
lenya/trunk/src/pubs/default/sitemap.xmap
lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/MetaDataTransformer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/MetaDataTransformer.java?rev=617247&r1=617246&r2=617247&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/MetaDataTransformer.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/MetaDataTransformer.java Thu Jan 31 13:37:22 2008
@@ -1,6 +1,10 @@
package org.apache.lenya.cms.cocoon.transformation;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.activity.Disposable;
@@ -11,7 +15,7 @@
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.AbstractSAXTransformer;
import org.apache.lenya.cms.metadata.MetaData;
-import org.apache.lenya.cms.metadata.MetaDataException;
+import org.apache.lenya.cms.publication.Area;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentUtil;
@@ -22,7 +26,18 @@
import org.xml.sax.helpers.AttributesImpl;
/**
- * Meta data transformer.
+ * <p>Meta data transformer.</p>
+ * <p>Usage example:</p>
+ * <pre>
+ * <meta:value xmlns:meta="http://apache.org/lenya/meta/1.0/"
+ * element="title"
+ * ns="http://purl.org/dc/elements/1.1/"
+ * uuid="{$uuid}"
+ * lang="{$language}"
+ * default="default-title"
+ * i18n:attr="default" />
+ * </pre>
+ * <p>The attribute <em>default</em> is optional.</p>
*/
public class MetaDataTransformer extends AbstractSAXTransformer implements Disposable {
/**
@@ -61,6 +76,11 @@
*/
static public final String LANG_ATT = "lang";
+ /**
+ * Use this attribute to provide a default value to be used if the document doesn't exist.
+ */
+ static public final String DEFAULT_ATT = "default";
+
/** Helper for lenya document retrival */
protected String publicationId = null;
@@ -105,7 +125,7 @@
throws SAXException {
if (NAMESPACE_URI.equals(uri)) {
if (VALUE_ELEMENT.equals(name)) {
- String lang = null, uuid = null, ns = null, key = null;
+ String lang = null, uuid = null, ns = null, key = null, defaultValue = null;
for (int i = 0; i < attr.getLength(); i++) {
String localName = attr.getLocalName(i);
String value = attr.getValue(i);
@@ -117,37 +137,46 @@
uuid = value;
else if (LANG_ATT.equals(localName))
lang = value;
+ else if (DEFAULT_ATT.equals(localName))
+ defaultValue = value;
}// end for
if (uuid == null || ns == null || key == null)
throw new SAXException(
"Error by setting up the transformation. Please fix the calling code.");
if (lang == null)
lang = pub.getDefaultLanguage();
+ List returnValues = new ArrayList();
try {
- Document document = pub.getArea(area).getDocument(uuid, lang);
- MetaData metaData = document.getMetaData(ns);
- String[] returnValue = metaData.getValues(key);
- if (returnValue.length > 1) {
- for (int i = 0; i < returnValue.length; i++) {
- AttributesImpl attributes = new AttributesImpl();
- attributes.addAttribute("", VALUE_ELEMENT, VALUE_ELEMENT, "CDATA",
- returnValue[i]);
- attributes.addAttribute("", ELEMENT_ATT, ELEMENT_ATT, "CDATA", key);
- this.contentHandler.startElement(ns, VALUE_ELEMENT, PREFIX + ":"
- + VALUE_ELEMENT, attributes);
- this.contentHandler.endElement(ns, VALUE_ELEMENT, PREFIX + ":"
- + VALUE_ELEMENT);
- }
- } else if (returnValue.length == 1) {
- this.contentHandler.characters(returnValue[0].toCharArray(), 0,
- returnValue[0].toCharArray().length);
+ Area areaObj = pub.getArea(this.area);
+ if (areaObj.contains(uuid, lang)) {
+ Document document = areaObj.getDocument(uuid, lang);
+ MetaData metaData = document.getMetaData(ns);
+ returnValues.addAll(Arrays.asList(metaData.getValues(key)));
+ } else if (defaultValue != null) {
+ returnValues.add(defaultValue);
+ } else {
+ String doc = this.publicationId + ":" + this.area + ":" + uuid + ":" + lang;
+ throw new SAXException("The document [" + doc
+ + "] does not exist and no default value is provided.");
+ }
+ } catch (Exception e) {
+ throw new SAXException(e);
+ }
+ if (returnValues.size() > 1) {
+ for (Iterator i = returnValues.iterator(); i.hasNext();) {
+ String value = (String) i.next();
+ AttributesImpl attributes = new AttributesImpl();
+ attributes.addAttribute("", VALUE_ELEMENT, VALUE_ELEMENT, "CDATA", value);
+ attributes.addAttribute("", ELEMENT_ATT, ELEMENT_ATT, "CDATA", key);
+ this.contentHandler.startElement(ns, VALUE_ELEMENT, PREFIX + ":"
+ + VALUE_ELEMENT, attributes);
+ this.contentHandler.endElement(ns, VALUE_ELEMENT, PREFIX + ":"
+ + VALUE_ELEMENT);
}
- } catch (PublicationException e) {
- throw new SAXException("Error by getting document for [ " + lang + "/" + uuid
- + " ]");
- } catch (MetaDataException e) {
- throw new SAXException("Error by getting meta data with ns [ " + ns
- + " ] for document for [ " + lang + "/" + uuid + " ]");
+ } else if (returnValues.size() == 1) {
+ String value = (String) returnValues.get(0);
+ this.contentHandler.characters(value.toCharArray(), 0,
+ value.toCharArray().length);
}
} else {
Modified: lenya/trunk/src/pubs/default/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/sitemap.xmap?rev=617247&r1=617246&r2=617247&view=diff
==============================================================================
--- lenya/trunk/src/pubs/default/sitemap.xmap (original)
+++ lenya/trunk/src/pubs/default/sitemap.xmap Thu Jan 31 13:37:22 2008
@@ -202,6 +202,7 @@
<map:parameter name="url" value="{page-envelope:document-url}"/>
<map:parameter name="document-path" value="{page-envelope:document-path}"/>
<map:parameter name="document-type" value="{4}"/>
+ <map:parameter name="uuid" value="{page-envelope:document-uuid}"/>
<map:parameter name="language" value="{page-envelope:document-language}"/>
<map:parameter name="contextprefix" value="{request:contextPath}"/>
<map:parameter name="lastPublishedUser" value="{access-control:user-name:{workflow:lastUser.publish}}"/>
@@ -210,19 +211,10 @@
<map:parameter name="author" value="{properties:pubs.default.author}"/>
<map:parameter name="nodeName" value="{page-envelope:document-name}"/>
</map:transform>
-
- <!--
- The stylesheet above has no chance to check if the document exists, so it
- inserts the title "404 (Page not found)" into the page.
- If the document exists in the requested language, the title is now replaced by
- the actual dublin core title.
- -->
- <map:act type="language-exists">
- <map:transform src="fallback://xslt/addXhtmlTitle.xsl">
- <map:parameter name="title" value="{dublincore:title}"/>
- </map:transform>
- </map:act>
-
+ <map:transform type="i18n">
+ <map:parameter name="locale" value="{page-envelope:language}"/>
+ </map:transform>
+
<!-- This is a demonstration of the generic meta data transformer
described in bug 39891.
@@ -240,9 +232,6 @@
<map:transform type="metaData">
<map:parameter name='pubid' value='{page-envelope:publication-id}'/>
<map:parameter name='area' value='{page-envelope:area}'/>
- </map:transform>
- <map:transform type="i18n">
- <map:parameter name="locale" value="{page-envelope:language}"/>
</map:transform>
<map:transform type="uuid2url"/>
<map:serialize type="xml"/>
Modified: lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl?rev=617247&r1=617246&r2=617247&view=diff
==============================================================================
--- lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl (original)
+++ lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl Thu Jan 31 13:37:22 2008
@@ -22,11 +22,10 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
- xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
xmlns:lenya="http://apache.org/cocoon/lenya/page-envelope/1.0"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
- exclude-result-prefixes="page xhtml dc lenya"
+ xmlns:meta="http://apache.org/lenya/meta/1.0/"
+ exclude-result-prefixes="xhtml lenya"
>
<!-- {context-prefix}/{publication-id}/{area} -->
@@ -40,6 +39,7 @@
<!-- The request url i.e. /lenya/doctypes/xhtml-document_en.html -->
<xsl:param name="url"/>
+ <xsl:param name="uuid"/>
<xsl:param name="language"/>
<xsl:param name="lastPublishedUser"/>
@@ -71,8 +71,8 @@
</xsl:choose>
<meta content="Apache Lenya" name="generator"/>
- <!-- The title will be overwritten by addXhtmlTitle.xsl if the document exists. -->
- <title><i18n:text>error-404</i18n:text></title>
+ <title><meta:value element="title" ns="http://purl.org/dc/elements/1.1/" default="error-404"
+ i18n:attr="default" uuid="{$uuid}" lang="{$language}"/></title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
</head>
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.