You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by mi...@apache.org on 2005/03/24 23:21:42 UTC
svn commit: r158960 - in
lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon: ./
generation/ generation/SiteTreeGenerator.java
Author: michi
Date: Thu Mar 24 14:21:41 2005
New Revision: 158960
URL: http://svn.apache.org/viewcvs?view=rev&rev=158960
Log:
sitetree generator added to get rid of filesystem dependency
Added:
lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon/
lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon/generation/
lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java
Added: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java?view=auto&rev=158960
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java (added)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java Thu Mar 24 14:21:41 2005
@@ -0,0 +1,128 @@
+/*
+ * Copyright 1999-2004 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:$ */
+
+package org.apache.lenya.cms.cocoon.generation;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.generation.ServiceableGenerator;
+import org.apache.lenya.cms.publication.Label;
+import org.apache.lenya.cms.publication.SiteTree;
+import org.apache.lenya.cms.publication.SiteTreeNode;
+import org.apache.log4j.Logger;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+public class SiteTreeGenerator extends ServiceableGenerator
+ implements Parameterizable
+{
+ private static Logger log = Logger.getLogger(SiteTreeGenerator.class);
+
+ protected final static String I18N_PX = "i18n";
+ protected final static String I18N_NS = "http://apache.org/cocoon/i18n/2.1";
+
+ protected final static String CDATA = "CDATA";
+
+ protected final static String SITE_ELEMENT = "site";
+ protected final static String NODE_ELEMENT = "node";
+ protected final static String LABEL_ELEMENT = "label";
+
+ protected final static String LABEL_ATTRIBUTE = "label";
+ protected final static String ATTR_ATTRIBUTE = "attr";
+ protected final static String Q_ATTR_ATTRIBUTE = I18N_PX + ":" + ATTR_ATTRIBUTE;
+ protected final static String ID_ATTRIBUTE = "id";
+ protected final static String LANG_ATTRIBUTE = "lang";
+ // TODO: is this correct re xml namespace?
+ protected final static String Q_LANG_ATTRIBUTE = "xml:lang";
+
+ private final AttributesImpl atts = new AttributesImpl();
+
+ /**
+ * No parameters implemented.
+ * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void parameterize(Parameters parameters) throws ParameterException {
+ }
+
+ /**
+ * @see org.apache.cocoon.generation.Generator#generate()
+ */
+ public void generate() throws SAXException {
+ SiteTree sitetree = null;
+
+ // Start the document and set the namespace.
+ this.contentHandler.startDocument();
+ // Default namespace.
+ this.contentHandler.startPrefixMapping("", SiteTree.NAMESPACE_URI);
+ this.contentHandler.startPrefixMapping(I18N_PX, I18N_NS);
+
+ generateSiteTree(sitetree);
+
+ // End the document.
+ this.contentHandler.endPrefixMapping("");
+ this.contentHandler.endDocument();
+ }
+
+ private void generateSiteTree(SiteTree sitetree) throws SAXException {
+ atts.clear();
+ // TODO: Do not hardcode "Authoring" label!!!
+ atts.addAttribute("", LABEL_ATTRIBUTE, LABEL_ATTRIBUTE, CDATA, "Authoring");
+ atts.addAttribute(I18N_NS, ATTR_ATTRIBUTE, Q_ATTR_ATTRIBUTE, CDATA, "label");
+
+ this.contentHandler.startElement(SiteTree.NAMESPACE_URI, SITE_ELEMENT, SITE_ELEMENT, atts);
+
+ SiteTreeNode node = null;
+ generateNodes(node);
+
+ this.contentHandler.endElement(SiteTree.NAMESPACE_URI, SITE_ELEMENT, SITE_ELEMENT);
+ }
+
+ private void generateNodes(SiteTreeNode node) throws SAXException {
+ atts.clear();
+ atts.addAttribute("", ID_ATTRIBUTE, ID_ATTRIBUTE, CDATA, node.getId());
+
+ this.contentHandler.startElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT, atts);
+
+ Label[] labels = node.getLabels();
+ for (int i=0; i<labels.length; i++)
+ generateLabels(labels[i]);
+
+ this.contentHandler.endElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT);
+ }
+
+ private void generateLabels(Label label) throws SAXException {
+ atts.clear();
+ atts.addAttribute("", LANG_ATTRIBUTE, Q_LANG_ATTRIBUTE, CDATA, label.getLanguage());
+
+ this.contentHandler.startElement(SiteTree.NAMESPACE_URI, LABEL_ELEMENT, LABEL_ELEMENT, atts);
+ char[] labelA = label.getLabel().toCharArray();
+ this.contentHandler.characters(labelA, 0, labelA.length);
+ this.contentHandler.endElement(SiteTree.NAMESPACE_URI, LABEL_ELEMENT, LABEL_ELEMENT);
+
+ }
+
+ /**
+ * Recycle the generator
+ */
+ public void recycle() {
+ super.recycle();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org