Author: solprovider
Date: Thu Jan 31 16:23:00 2008
New Revision: 617315
URL: http://svn.apache.org/viewvc?rev=617315&view=rev
Log:
Added ModulesGenerator. Started Publication Module.
Expanded Globals. Refactoring to deprecate verbose code.
Added:
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/ModulesGenerator.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/PublicationModules.java
- copied, changed from r617035, lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationModules.java
lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/publication/
Removed:
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationModules.java
Modified:
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/Module.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/ModuleInputModule.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/ModuleSet.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/ModuleSourceFactory.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/Modules.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelope.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelopeFactory.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/Publication.java
lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/util/Globals.java
lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/edit/module.xml
lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/home/module.xml
lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/link/module.xml
lenya/branches/revolution/1.3.x/src/webapp/sitemap.xmap
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java?rev=617315&r1=617314&r2=617315&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java Thu Jan 31 16:23:00 2008
@@ -14,50 +14,43 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.components.modules.input;
-
import java.util.Map;
-
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
-
/**
* Abstract superclass for classes which need access to the page envelope.
+ *
+ * @deprecated Useless. Extend AbstractInputModule and use PageEnvelope.getCurrent() for access to the page envelope.
*/
public abstract class AbstractPageEnvelopeModule extends AbstractInputModule {
-
- /**
- * Get the the page envelope for the given objectModel.
- *
- * @param objectModel the objectModel for which the page enevelope is requested.
- *
- * @return a <code>PageEnvelope</code>
- *
- * @throws ConfigurationException if the page envelope could not be instantiated.
- */
- protected PageEnvelope getEnvelope(Map objectModel) throws ConfigurationException {
-
- PageEnvelope envelope = null;
-
- if (getLogger().isDebugEnabled()) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- getLogger().debug("Resolving page envelope for URL [" + request.getRequestURI() + "]");
- }
-
- try {
- envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- } catch (Exception e) {
- throw new ConfigurationException("Resolving page envelope failed: ", e);
- }
-
- return envelope;
- }
-
+ /**
+ * Get the the page envelope for the given objectModel.
+ *
+ * @param objectModel
+ * the objectModel for which the page enevelope is requested.
+ *
+ * @return a <code>PageEnvelope</code>
+ *
+ * @throws ConfigurationException
+ * if the page envelope could not be instantiated.
+ * @deprecated Use PageEnvelope.getCurrent() and throw new ConfigurationException("Resolving page envelope failed: ", e);
+ */
+ protected PageEnvelope getEnvelope(Map objectModel) throws ConfigurationException {
+ PageEnvelope envelope = null;
+ if(getLogger().isDebugEnabled()){
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ getLogger().debug("Resolving page envelope for URL [" + request.getRequestURI() + "]");
+ }
+ try{
+ envelope = PageEnvelope.getCurrent();
+ }catch(Exception e){
+ throw new ConfigurationException("Resolving page envelope failed: ", e);
+ }
+ return envelope;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java?rev=617315&r1=617314&r2=617315&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java Thu Jan 31 16:23:00 2008
@@ -14,17 +14,13 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.components.modules.input;
-
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
@@ -38,235 +34,198 @@
import org.apache.lenya.cms.cocoon.uriparameterizer.URIParameterizerException;
import org.apache.lenya.cms.publication.DublinCore;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
-
+import org.apache.lenya.cms.publication.PageEnvelopeException;
/**
- * Input module wrapping the page envelope. This module provides publication
- * related information such as document-id, area, publication-id.
+ * Input module wrapping the page envelope. This module provides publication related information such as document-id, area, publication-id.
*
* @see org.apache.lenya.cms.publication.PageEnvelope
*/
public class PageEnvelopeModule extends AbstractPageEnvelopeModule implements Serviceable {
-
- private ServiceManager manager;
-
- /**
- * Get the the page envelope for the given objectModel.
- *
- * @param objectModel the objectModel for which the page enevelope is requested.
- *
- * @return a <code>PageEnvelope</code>
- *
- * @throws ConfigurationException if the page envelope could not be instantiated.
- */
- protected PageEnvelope getEnvelope(Map objectModel) throws ConfigurationException {
- PageEnvelope envelope = null;
-
- if (getLogger().isDebugEnabled()) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- getLogger().debug("Resolving page envelope for URL [" + request.getRequestURI() + "]");
- }
-
- try {
- envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- } catch (Exception e) {
- throw new ConfigurationException("Resolving page envelope failed: ", e);
- }
-
- return envelope;
- }
-
- protected static final String URI_PARAMETER_DOCTYPE = "doctype";
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object getAttribute(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- PageEnvelope envelope = getEnvelope(objectModel);
- Object value = null;
-
- try {
- if (name.equals(PageEnvelope.AREA)) {
- value = envelope.getDocument().getArea();
- } else if (name.equals(PageEnvelope.CONTEXT)) {
- value = envelope.getContext();
- } else if (name.equals(PageEnvelope.PUBLICATION_ID)) {
- value = envelope.getPublication().getId();
- } else if (name.equals(PageEnvelope.PUBLICATION)) {
- value = envelope.getPublication();
- } else if (name.equals(PageEnvelope.PUBLICATION_LANGUAGES_CSV)) {
- value =
- StringUtils.join(
- envelope.getPublication().getLanguages(),
- ',');
- } else if (name.equals(PageEnvelope.DOCUMENT)) {
- value = envelope.getDocument();
- } else if (name.equals(PageEnvelope.DOCUMENT_ID)) {
- value = envelope.getDocument().getId();
- } else if (name.equals(PageEnvelope.DOCUMENT_NAME)) {
- value = envelope.getDocument().getName();
- } else if (name.equals(PageEnvelope.DOCUMENT_NODE_ID)) { // FIXME: Why is this here?
- value = envelope.getDocument().getNodeId();
- } else if (name.equals(PageEnvelope.DOCUMENT_LABEL)) { // FIXME: Why is this here?
- value = envelope.getDocument().getLabel();
- } else if (name.equals(PageEnvelope.DOCUMENT_URL)) {
- value = envelope.getDocument().getDocumentURL();
- } else if (name.equals(PageEnvelope.DOCUMENT_URL_WITHOUT_LANGUAGE)) {
- value = envelope.getDocument().getCompleteURLWithoutLanguage();
- } else if (name.equals(PageEnvelope.DOCUMENT_PATH)) {
- value = envelope.getDocumentPath();
- } else if (name.equals(PageEnvelope.DOCUMENT_FILE)) {
- value = envelope.getDocument().getFile();
- } else if (name.equals(PageEnvelope.DOCUMENT_EXTENSION)) {
- value = envelope.getDocument().getExtension();
- } else if (name.equals(PageEnvelope.DEFAULT_LANGUAGE)) {
- value = envelope.getPublication().getDefaultLanguage();
- } else if (name.equals(PageEnvelope.DOCUMENT_LANGUAGE)) {
- value = envelope.getDocument().getLanguage();
-//LENYA1.3 - BEGIN
- if(((String) value).length() < 1) value = envelope.getPublication().getDefaultLanguage();
-//LENYA1.3 - END
- } else if (name.equals(PageEnvelope.DOCUMENT_LANGUAGES)) {
- value = envelope.getDocument().getLanguages();
- } else if (name.equals(PageEnvelope.DOCUMENT_LANGUAGES_CSV)) {
- value =
- StringUtils.join(
- envelope.getDocument().getLanguages(),
- ',');
- } else if (name.equals(PageEnvelope.DOCUMENT_DC_TITLE)) {
- value =
- envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_TITLE);
- } else if (name.equals(PageEnvelope.DOCUMENT_DC_CREATOR)) {
- value =
- envelope.getDocument().getDublinCore().getFirstValue(
- DublinCore.ELEMENT_CREATOR);
- } else if (name.equals(PageEnvelope.DOCUMENT_DC_PUBLISHER)) {
- value =
- envelope.getDocument().getDublinCore().getFirstValue(
- DublinCore.ELEMENT_PUBLISHER);
- } else if (name.equals(PageEnvelope.DOCUMENT_DC_SUBJECT)) {
- value =
- envelope.getDocument().getDublinCore().getFirstValue(
- DublinCore.ELEMENT_SUBJECT);
- } else if (name.equals(PageEnvelope.DOCUMENT_DC_DESCRIPTION)) {
- value =
- envelope.getDocument().getDublinCore().getFirstValue(
- DublinCore.ELEMENT_DESCRIPTION);
- } else if (name.equals(PageEnvelope.DOCUMENT_DC_RIGHTS)) {
- value =
- envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_RIGHTS);
- } else if (name.equals(PageEnvelope.DOCUMENT_DC_DATE_CREATED)) {
- value =
- envelope.getDocument().getDublinCore().getFirstValue(DublinCore.TERM_CREATED);
- } else if (name.equals(PageEnvelope.DOCUMENT_LASTMODIFIED)) {
- Date date = envelope.getDocument().getLastModified();
- value = new SimpleDateFormat(DATE_FORMAT).format(date);
- } else if (name.equals(PageEnvelope.BREADCRUMB_PREFIX)) {
- value = envelope.getPublication().getBreadcrumbPrefix();
- } else if (name.equals(PageEnvelope.SSL_PREFIX)) {
- value = envelope.getPublication().getSSLPrefix();
- } else if (name.equals(PageEnvelope.DOCUMENT_TYPE)) {
- value = getDocumentType(objectModel, envelope);
- } else {
- throw new ConfigurationException("The attribute [" + name + "] is not supported!");
- }
-//Lenya1.3 - BEGIN
-// } catch (ConfigurationException e) {
-// throw e;
- } catch (Exception e) {
-// throw new ConfigurationException("Getting attribute for name [" + name + "] failed: ", e);
- value = "";
-//Lenya1.3 - END
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Returning [" + name + "] = [" + value + "]");
- }
-
- return value;
- }
-
- public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
-
- /**
- * Returns the document type.
- * @param objectModel The object model.
- * @param envelope The page envelope.
- * @return A string.
- * @throws ServiceException when something went wrong.
- * @throws URIParameterizerException when something went wrong.
- */
- protected String getDocumentType(Map objectModel, PageEnvelope envelope)
- throws ServiceException, URIParameterizerException {
- String documentType;
- URIParameterizer parameterizer = null;
- Map map = null;
- try {
- parameterizer = (URIParameterizer) manager.lookup(URIParameterizer.ROLE);
-
- Parameters parameters = new Parameters();
- parameters.setParameter(
- URI_PARAMETER_DOCTYPE,
- "cocoon://uri-parameter/"
- + envelope.getPublication().getId()
- + "/"
- + URI_PARAMETER_DOCTYPE);
-
- String source =
- envelope.getDocument().getArea() + envelope.getDocument().getDocumentURL();
-
- Request request = ObjectModelHelper.getRequest(objectModel);
- map = parameterizer.parameterize(filterURI(request.getRequestURI()), filterURI(source), parameters);
- documentType = (String) map.get(URI_PARAMETER_DOCTYPE);
-
- } finally {
- if (parameterizer != null) {
- manager.release(parameterizer);
- }
- }
- return documentType;
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- return Arrays.asList(PageEnvelope.PARAMETER_NAMES).iterator();
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- Object[] objects = { getAttribute(name, modeConf, objectModel)};
-
- return objects;
- }
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
-
- /**
- * uri will be filtered by certain rules
- * i.e. session information encoded within the uri will be removed.
- * @param uri The uri to be filtered
- * @return uri filtered by certain rules i.e
- */
- // FIXME Maybe make this more configureable
- private String filterURI(final String uri)
- {
- final int index = uri.indexOf(";jsessionid");
-
- if(index >= 0)
- return uri.substring(0, index);
- else
- return uri;
- }
+ private ServiceManager manager;
+ /**
+ * Get the the page envelope for the given objectModel.
+ *
+ * @param objectModel
+ * the objectModel for which the page envelope is requested.
+ *
+ * @return a <code>PageEnvelope</code>
+ *
+ * @throws ConfigurationException
+ * if the page envelope could not be instantiated.
+ * @deprecated Use PageEnvelope.getCurrent(). Catch Exception and throw new ConfigurationException("Resolving page envelope failed: ", e);
+ */
+ protected PageEnvelope getEnvelope(Map objectModel) throws ConfigurationException {
+ PageEnvelope envelope = null;
+ if(getLogger().isDebugEnabled()){
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ getLogger().debug("Resolving page envelope for URL [" + request.getRequestURI() + "]");
+ }
+ try{
+ envelope = PageEnvelope.getCurrent();
+ }catch(Exception e){
+ throw new ConfigurationException("Resolving page envelope failed: ", e);
+ }
+ return envelope;
+ }
+ protected static final String URI_PARAMETER_DOCTYPE = "doctype";
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ PageEnvelope envelope;
+ try{
+ envelope = PageEnvelope.getCurrent();
+ }catch(PageEnvelopeException e1){
+ throw new ConfigurationException("Resolving page envelope failed: ", e1);
+ }
+ Object value = null;
+ try{
+ if(name.equals(PageEnvelope.AREA)){
+ value = envelope.getDocument().getArea();
+ }else if(name.equals(PageEnvelope.CONTEXT)){
+ value = envelope.getContext();
+ }else if(name.equals(PageEnvelope.PUBLICATION_ID)){
+ value = envelope.getPublication().getId();
+ }else if(name.equals(PageEnvelope.PUBLICATION)){
+ value = envelope.getPublication();
+ }else if(name.equals(PageEnvelope.PUBLICATION_LANGUAGES_CSV)){
+ value = StringUtils.join(envelope.getPublication().getLanguages(), ',');
+ }else if(name.equals(PageEnvelope.DOCUMENT)){
+ value = envelope.getDocument();
+ }else if(name.equals(PageEnvelope.DOCUMENT_ID)){
+ value = envelope.getDocument().getId();
+ }else if(name.equals(PageEnvelope.DOCUMENT_NAME)){
+ value = envelope.getDocument().getName();
+ }else if(name.equals(PageEnvelope.DOCUMENT_NODE_ID)){ // FIXME: Why is this here?
+ value = envelope.getDocument().getNodeId();
+ }else if(name.equals(PageEnvelope.DOCUMENT_LABEL)){ // FIXME: Why is this here?
+ value = envelope.getDocument().getLabel();
+ }else if(name.equals(PageEnvelope.DOCUMENT_URL)){
+ value = envelope.getDocument().getDocumentURL();
+ }else if(name.equals(PageEnvelope.DOCUMENT_URL_WITHOUT_LANGUAGE)){
+ value = envelope.getDocument().getCompleteURLWithoutLanguage();
+ }else if(name.equals(PageEnvelope.DOCUMENT_PATH)){
+ value = envelope.getDocumentPath();
+ }else if(name.equals(PageEnvelope.DOCUMENT_FILE)){
+ value = envelope.getDocument().getFile();
+ }else if(name.equals(PageEnvelope.DOCUMENT_EXTENSION)){
+ value = envelope.getDocument().getExtension();
+ }else if(name.equals(PageEnvelope.DEFAULT_LANGUAGE)){
+ value = envelope.getPublication().getDefaultLanguage();
+ }else if(name.equals(PageEnvelope.DOCUMENT_LANGUAGE)){
+ value = envelope.getDocument().getLanguage();
+ // LENYA1.3 - BEGIN
+ if(((String) value).length() < 1)
+ value = envelope.getPublication().getDefaultLanguage();
+ // LENYA1.3 - END
+ }else if(name.equals(PageEnvelope.DOCUMENT_LANGUAGES)){
+ value = envelope.getDocument().getLanguages();
+ }else if(name.equals(PageEnvelope.DOCUMENT_LANGUAGES_CSV)){
+ value = StringUtils.join(envelope.getDocument().getLanguages(), ',');
+ }else if(name.equals(PageEnvelope.DOCUMENT_DC_TITLE)){
+ value = envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_TITLE);
+ }else if(name.equals(PageEnvelope.DOCUMENT_DC_CREATOR)){
+ value = envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_CREATOR);
+ }else if(name.equals(PageEnvelope.DOCUMENT_DC_PUBLISHER)){
+ value = envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_PUBLISHER);
+ }else if(name.equals(PageEnvelope.DOCUMENT_DC_SUBJECT)){
+ value = envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_SUBJECT);
+ }else if(name.equals(PageEnvelope.DOCUMENT_DC_DESCRIPTION)){
+ value = envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_DESCRIPTION);
+ }else if(name.equals(PageEnvelope.DOCUMENT_DC_RIGHTS)){
+ value = envelope.getDocument().getDublinCore().getFirstValue(DublinCore.ELEMENT_RIGHTS);
+ }else if(name.equals(PageEnvelope.DOCUMENT_DC_DATE_CREATED)){
+ value = envelope.getDocument().getDublinCore().getFirstValue(DublinCore.TERM_CREATED);
+ }else if(name.equals(PageEnvelope.DOCUMENT_LASTMODIFIED)){
+ Date date = envelope.getDocument().getLastModified();
+ value = new SimpleDateFormat(DATE_FORMAT).format(date);
+ }else if(name.equals(PageEnvelope.BREADCRUMB_PREFIX)){
+ value = envelope.getPublication().getBreadcrumbPrefix();
+ }else if(name.equals(PageEnvelope.SSL_PREFIX)){
+ value = envelope.getPublication().getSSLPrefix();
+ }else if(name.equals(PageEnvelope.DOCUMENT_TYPE)){
+ value = getDocumentType(objectModel, envelope);
+ }else{
+ throw new ConfigurationException("The attribute [" + name + "] is not supported!");
+ }
+ // Lenya1.3 - BEGIN
+ // } catch (ConfigurationException e) {
+ // throw e;
+ }catch(Exception e){
+ // throw new ConfigurationException("Getting attribute for name [" + name + "] failed: ", e);
+ value = "";
+ // Lenya1.3 - END
+ }
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Returning [" + name + "] = [" + value + "]");
+ }
+ return value;
+ }
+ public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+ /**
+ * Returns the document type.
+ *
+ * @param objectModel
+ * The object model.
+ * @param envelope
+ * The page envelope.
+ * @return A string.
+ * @throws ServiceException
+ * when something went wrong.
+ * @throws URIParameterizerException
+ * when something went wrong.
+ */
+ protected String getDocumentType(Map objectModel, PageEnvelope envelope) throws ServiceException, URIParameterizerException {
+ String documentType;
+ URIParameterizer parameterizer = null;
+ Map map = null;
+ try{
+ parameterizer = (URIParameterizer) manager.lookup(URIParameterizer.ROLE);
+ Parameters parameters = new Parameters();
+ parameters.setParameter(URI_PARAMETER_DOCTYPE, "cocoon://uri-parameter/" + envelope.getPublication().getId() + "/" + URI_PARAMETER_DOCTYPE);
+ String source = envelope.getDocument().getArea() + envelope.getDocument().getDocumentURL();
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ map = parameterizer.parameterize(filterURI(request.getRequestURI()), filterURI(source), parameters);
+ documentType = (String) map.get(URI_PARAMETER_DOCTYPE);
+ }finally{
+ if(parameterizer != null){
+ manager.release(parameterizer);
+ }
+ }
+ return documentType;
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Iterator getAttributeNames(Configuration modeConf, Map objectModel) throws ConfigurationException {
+ return Arrays.asList(PageEnvelope.PARAMETER_NAMES).iterator();
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ Object[] objects = {getAttribute(name, modeConf, objectModel)};
+ return objects;
+ }
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+ /**
+ * uri will be filtered by certain rules i.e. session information encoded within the uri will be removed.
+ *
+ * @param uri
+ * The uri to be filtered
+ * @return uri filtered by certain rules i.e
+ */
+ // FIXME Maybe make this more configureable
+ private String filterURI(final String uri) {
+ final int index = uri.indexOf(";jsessionid");
+ if(index >= 0)
+ return uri.substring(0, index);
+ else
+ return uri;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java?rev=617315&r1=617314&r2=617315&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SiteTreeGenerator.java Thu Jan 31 16:23:00 2008
@@ -1,213 +1,213 @@
-/*
- * 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 java.io.IOException;
-import java.io.Serializable;
-import java.util.Map;
-
-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.ProcessingException;
-import org.apache.cocoon.caching.CacheableProcessingComponent;
-import org.apache.cocoon.environment.SourceResolver;
-import org.apache.cocoon.generation.ServiceableGenerator;
-import org.apache.excalibur.source.SourceValidity;
-import org.apache.excalibur.source.impl.validity.TimeStampValidity;
-import org.apache.lenya.cms.publication.Label;
-import org.apache.lenya.cms.publication.LastModified;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.publication.PublicationFactory;
-import org.apache.lenya.cms.publication.SiteTree;
-import org.apache.lenya.cms.publication.SiteTreeException;
-import org.apache.lenya.cms.publication.SiteTreeNode;
-import org.apache.log4j.Logger;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-import org.xml.sax.helpers.NamespaceSupport;
-
-/**
- * Site tree generator.
- *
- * @version $Id:$
- */
-public class SiteTreeGenerator extends ServiceableGenerator implements Parameterizable,
- CacheableProcessingComponent {
- 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";
- protected final static String HREF_ATTRIBUTE = "href";
- protected final static String LINK_ATTRIBUTE = "link";
- protected final static String VISIBLEINNAV_ATTRIBUTE = "visibleinnav";
- protected final static String SUFFIX_ATTRIBUTE = "suffix";
-
- protected final static String Q_LANG_ATTRIBUTE = "xml:lang";
-
- /**
- * The area of the site tree.
- */
- public final static String AREA_PARAMETER = "area";
-
- private final AttributesImpl atts = new AttributesImpl();
-
- SiteTree sitetree = null;
- String area = null;
-
- /**
- * 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.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
- * java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
- */
- public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
- throws ProcessingException, SAXException, IOException {
- log.debug("setup");
- try {
- Publication publication = PublicationFactory.getPublication(objectModel);
- area = par.getParameter(AREA_PARAMETER);
- sitetree = publication.getTree(area);
- } catch (PublicationException e) {
- throw new ProcessingException("Unable to get sitetree: publication exception.", e);
- } catch (ParameterException e) {
- throw new ProcessingException("Unable to get sitetree: parameter 'area' not found.", e);
- } catch (SiteTreeException e) {
- throw new ProcessingException("Unable to get sitetree.", e);
- }
- }
-
- /**
- * @see org.apache.cocoon.generation.Generator#generate()
- */
- public void generate() throws SAXException {
- log.debug("generate");
- // 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 tree) 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[] topNodes = tree.getTopNodes();
- for (int i = 0; i < topNodes.length; i++) {
- generateNodes(topNodes[i]);
- }
-
- 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());
- if (node.getHref() != null)
- atts.addAttribute("", HREF_ATTRIBUTE, HREF_ATTRIBUTE, CDATA, node.getHref());
- if (node.getSuffix() != null)
- atts.addAttribute("", SUFFIX_ATTRIBUTE, SUFFIX_ATTRIBUTE, CDATA, node.getSuffix());
- atts.addAttribute("", LINK_ATTRIBUTE, LINK_ATTRIBUTE, CDATA, Boolean.toString(node
- .hasLink()));
- atts.addAttribute("", VISIBLEINNAV_ATTRIBUTE, VISIBLEINNAV_ATTRIBUTE, CDATA, Boolean
- .toString(node.visibleInNav()));
-
- 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]);
- SiteTreeNode[] children = node.getChildren();
- for (int i = 0; i < children.length; i++)
- generateNodes(children[i]);
-
- this.contentHandler.endElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT);
- }
-
- private void generateLabels(Label label) throws SAXException {
- atts.clear();
- atts.addAttribute(NamespaceSupport.XMLNS, 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() {
- log.debug("recycle");
- super.recycle();
- sitetree = null;
- area = null;
- }
-
- /**
- * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
- */
- public Serializable getKey() {
- return area;
- }
-
- /**
- * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
- */
- public SourceValidity getValidity() {
- // Check if sitetree implementation supports last modified
- if (!(sitetree instanceof LastModified)) {
- return null;
- } else {
- return new TimeStampValidity(((LastModified) sitetree).getLastModified());
- }
- }
+/*
+ * 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 java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+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.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.generation.ServiceableGenerator;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.TimeStampValidity;
+import org.apache.lenya.cms.publication.Label;
+import org.apache.lenya.cms.publication.LastModified;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.SiteTree;
+import org.apache.lenya.cms.publication.SiteTreeException;
+import org.apache.lenya.cms.publication.SiteTreeNode;
+import org.apache.log4j.Logger;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.NamespaceSupport;
+
+/**
+ * Site tree generator.
+ *
+ * @version $Id:$
+ */
+public class SiteTreeGenerator extends ServiceableGenerator implements Parameterizable,
+ CacheableProcessingComponent {
+ 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";
+ protected final static String HREF_ATTRIBUTE = "href";
+ protected final static String LINK_ATTRIBUTE = "link";
+ protected final static String VISIBLEINNAV_ATTRIBUTE = "visibleinnav";
+ protected final static String SUFFIX_ATTRIBUTE = "suffix";
+
+ protected final static String Q_LANG_ATTRIBUTE = "xml:lang";
+
+ /**
+ * The area of the site tree.
+ */
+ public final static String AREA_PARAMETER = "area";
+
+ private final AttributesImpl atts = new AttributesImpl();
+
+ SiteTree sitetree = null;
+ String area = null;
+
+ /**
+ * 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.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
+ * java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
+ throws ProcessingException, SAXException, IOException {
+ log.debug("setup");
+ try {
+ Publication publication = PublicationFactory.getPublication(objectModel);
+ area = par.getParameter(AREA_PARAMETER);
+ sitetree = publication.getTree(area);
+ } catch (PublicationException e) {
+ throw new ProcessingException("Unable to get sitetree: publication exception.", e);
+ } catch (ParameterException e) {
+ throw new ProcessingException("Unable to get sitetree: parameter 'area' not found.", e);
+ } catch (SiteTreeException e) {
+ throw new ProcessingException("Unable to get sitetree.", e);
+ }
+ }
+
+ /**
+ * @see org.apache.cocoon.generation.Generator#generate()
+ */
+ public void generate() throws SAXException {
+ log.debug("generate");
+ // 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 tree) 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[] topNodes = tree.getTopNodes();
+ for (int i = 0; i < topNodes.length; i++) {
+ generateNodes(topNodes[i]);
+ }
+
+ 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());
+ if (node.getHref() != null)
+ atts.addAttribute("", HREF_ATTRIBUTE, HREF_ATTRIBUTE, CDATA, node.getHref());
+ if (node.getSuffix() != null)
+ atts.addAttribute("", SUFFIX_ATTRIBUTE, SUFFIX_ATTRIBUTE, CDATA, node.getSuffix());
+ atts.addAttribute("", LINK_ATTRIBUTE, LINK_ATTRIBUTE, CDATA, Boolean.toString(node
+ .hasLink()));
+ atts.addAttribute("", VISIBLEINNAV_ATTRIBUTE, VISIBLEINNAV_ATTRIBUTE, CDATA, Boolean
+ .toString(node.visibleInNav()));
+
+ 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]);
+ SiteTreeNode[] children = node.getChildren();
+ for (int i = 0; i < children.length; i++)
+ generateNodes(children[i]);
+
+ this.contentHandler.endElement(SiteTree.NAMESPACE_URI, NODE_ELEMENT, NODE_ELEMENT);
+ }
+
+ private void generateLabels(Label label) throws SAXException {
+ atts.clear();
+ atts.addAttribute(NamespaceSupport.XMLNS, 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() {
+ log.debug("recycle");
+ super.recycle();
+ sitetree = null;
+ area = null;
+ }
+
+ /**
+ * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
+ */
+ public Serializable getKey() {
+ return area;
+ }
+
+ /**
+ * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
+ */
+ public SourceValidity getValidity() {
+ // Check if sitetree implementation supports last modified
+ if (!(sitetree instanceof LastModified)) {
+ return null;
+ } else {
+ return new TimeStampValidity(((LastModified) sitetree).getLastModified());
+ }
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java?rev=617315&r1=617314&r2=617315&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java Thu Jan 31 16:23:00 2008
@@ -1,496 +1,496 @@
-/*
- * 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.
- *
- */
-
-/* @version $Id$*/
-
-package org.apache.lenya.cms.cocoon.generation;
-
-import java.io.IOException;
-import java.util.Map;
-
-import org.apache.avalon.framework.parameters.Parameters;
-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.cocoon.generation.AbstractGenerator;
-import org.apache.lenya.cms.publication.Label;
-import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.SiteTree;
-import org.apache.lenya.cms.publication.SiteTreeException;
-import org.apache.lenya.cms.publication.SiteTreeNode;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-
-/**
- * Generates a fragment of the XML from the sitetree, corresponding to a given
- * node. The node is specified by the sitemap parameters area/documentid. If the
- * sitemap parameter initialTree is true, the top nodes of the tree will be
- * generated and the node given by the sitemap parameters area/documentid will
- * be unfolded. If initialTree is false, only the children of the selected node
- * will be generated.
- *
- */
-public class SitetreeFragmentGenerator extends AbstractGenerator {
-
- protected Publication publication;
-
- /** Parameter which denotes the documentid of the clicked node */
- protected String documentid;
-
- /** Parameter which denotes the area of the clicked node */
- protected String area;
-
- /**
- * Parameter which decides if the initial tree with the root nodes is
- * generated
- */
- protected boolean initialTree;
-
- /**
- * Parameter which denotes a comma-separated list of areas, for which the
- * xml will be generated.
- */
- protected String[] areas = null;
-
- /**
- * Convenience object, so we don't need to create an AttributesImpl for
- * every element.
- */
- protected AttributesImpl attributes;
-
- protected static final String PARAM_AREA = "area";
-
- protected static final String PARAM_DOCUMENTID = "documentid";
-
- protected static final String PARAM_INITIAL = "initial";
-
- protected static final String PARAM_AREAS = "areas";
-
- /** The URI of the namespace of this generator. */
- protected static final String URI = "http://apache.org/cocoon/lenya/sitetree/1.0";
-
- protected static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
-
- /** The namespace prefix for this namespace. */
- protected static final String PREFIX = "site";
-
- protected static final String XML_PREFIX = "xml";
-
- protected static final String NODE_NODE = "node";
-
- protected static final String NODE_LABEL = "label";
-
- protected static final String NODE_SITE = "site";
-
- protected static final String NODE_FRAGMENT = "fragment";
-
- protected static final String ATTR_ID = "id";
-
- protected static final String ATTR_FOLDER = "folder";
-
- protected static final String ATTR_AREA = "area";
-
- protected static final String ATTR_LABEL = "label";
-
- protected static final String ATTR_VISIBLEINNAV = "visibleinnav";
-
- protected static final String ATTR_LINK = "link";
-
- protected static final String ATTR_BASE = "base";
-
- protected static final String ATTR_SUFFIX = "suffix";
-
- protected static final String ATTR_HREF = "href";
-
- protected static final String ATTR_LANG = "lang";
-
- /**
- * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
- * java.util.Map, java.lang.String,
- * org.apache.avalon.framework.parameters.Parameters)
- */
- public void setup(SourceResolver resolver, Map objectModel, String src,
- Parameters par) throws ProcessingException, SAXException,
- IOException {
- super.setup(resolver, objectModel, src, par);
-
- PageEnvelope envelope = null;
-
- if (getLogger().isDebugEnabled()) {
- Request request = ObjectModelHelper.getRequest(objectModel);
- getLogger().debug(
- "Resolving page envelope for URL ["
- + request.getRequestURI() + "]");
- }
-
- this.area = par.getParameter(PARAM_AREA, null);
- this.documentid = par.getParameter(PARAM_DOCUMENTID, null);
-
- if (par.isParameter(PARAM_INITIAL)) {
- this.initialTree = Boolean.valueOf(
- par.getParameter(PARAM_INITIAL, null)).booleanValue();
- } else {
- this.initialTree = false;
- }
-
- if (par.isParameter(PARAM_AREAS)) {
- String parAreas = par.getParameter(PARAM_AREAS, null);
- this.areas = parAreas.split(",");
- } else {
- String temp[] = { "authoring", "archive", "trash" };
- this.areas = temp;
- }
-
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("Parameter area: " + this.area);
- this.getLogger().debug("Parameter documentid: " + this.documentid);
- this.getLogger()
- .debug("Parameter initialTree: " + this.initialTree);
- String areasStr = "";
- for (int i = 0; i < this.areas.length; i++)
- areasStr += this.areas[i] + " ";
- this.getLogger().debug("Parameter areas: " + areasStr);
- }
-
- try {
- envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(
- objectModel);
- } catch (Exception e) {
- throw new ProcessingException("Resolving page envelope failed: ", e);
- }
-
- this.publication = envelope.getPublication();
- this.attributes = new AttributesImpl();
-
- }
-
- /**
- * @see org.apache.cocoon.generation.Generator#generate()
- */
- public void generate() throws IOException, SAXException,
- ProcessingException {
-
- try {
-
- this.contentHandler.startDocument();
- this.contentHandler.startPrefixMapping(PREFIX, URI);
-
- attributes.clear();
- if (!initialTree) {
- attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA",
- this.area);
- attributes.addAttribute("", ATTR_BASE, ATTR_BASE, "CDATA",
- this.documentid);
- }
-
- this.contentHandler.startElement(URI, NODE_FRAGMENT, PREFIX + ':'
- + NODE_FRAGMENT, this.attributes);
-
- if (this.initialTree) {
- for (int i = 0; i < this.areas.length; i++) {
- generateFragmentInitial(this.areas[i]);
- }
- } else {
- generateFragment();
- }
-
- this.contentHandler.endElement(URI, NODE_FRAGMENT, PREFIX + ':'
- + NODE_FRAGMENT);
-
- this.contentHandler.endPrefixMapping(PREFIX);
- this.contentHandler.endDocument();
-
- } catch (SAXException e) {
- throw new ProcessingException(e);
- } catch (SiteTreeException e) {
- throw new ProcessingException(e);
- }
-
- }
-
- /**
- * Generates a fragment of the tree which contains the children of a given
- * node.
- *
- * @throws SiteTreeException
- * @throws SAXException
- * @throws ProcessingException
- */
- protected void generateFragment() throws SiteTreeException, SAXException,
- ProcessingException {
-
- SiteTree siteTree = null;
- if (!this.area.equals(Publication.AUTHORING_AREA)
- && !this.area.equals(Publication.ARCHIVE_AREA)
- && !this.area.equals(Publication.TRASH_AREA)
- && !this.area.equals(Publication.STAGING_AREA)
- && !this.area.equals(Publication.LIVE_AREA)) {
- throw new ProcessingException("Invalid area: " + this.area);
- }
- siteTree = publication.getTree(this.area);
-
- SiteTreeNode node = siteTree.getNode(this.documentid);
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Node with documentid " + documentid + " found.");
- }
- if (node == null)
- throw new SiteTreeException("Node with documentid " + documentid
- + " not found.");
-
- SiteTreeNode[] children = node.getChildren();
-
- for (int i = 0; i < children.length; i++) {
- startNode(NODE_NODE, children[i]);
- addLabels(children[i]);
- endNode(NODE_NODE);
- }
- }
-
- /**
- * Generates the top node of the given area and then calls a recursive
- * method to traverse the tree, if the node given by area/documentid is in
- * this area.
- *
- * @param siteArea
- * @throws SiteTreeException
- * @throws SAXException
- * @throws ProcessingException
- */
- protected void generateFragmentInitial(String siteArea)
- throws SiteTreeException, SAXException, ProcessingException {
-
- SiteTree siteTree = publication.getTree(siteArea);
-
- String label = "";
- String isFolder = "";
-
- // FIXME: don't hardcode area label
- if (siteArea.equals(Publication.AUTHORING_AREA))
- label = "Authoring";
- if (siteArea.equals(Publication.ARCHIVE_AREA))
- label = "Archive";
- if (siteArea.equals(Publication.TRASH_AREA))
- label = "Trash";
- if (siteArea.equals(Publication.LIVE_AREA))
- label = "Live";
- if (siteArea.equals(Publication.STAGING_AREA))
- label = "Staging";
-
- if (siteTree.getTopNodes().length > 0)
- isFolder = "true";
- else
- isFolder = "false";
-
- this.attributes.clear();
- this.attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA",
- siteArea);
- this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA",
- isFolder);
- this.attributes
- .addAttribute("", ATTR_LABEL, ATTR_LABEL, "CDATA", label);
-
- startNode(NODE_SITE);
-
- if (area.equals(siteArea)) {
- generateFragmentRecursive(siteTree.getTopNodes(), this.documentid);
- }
-
- endNode(NODE_SITE);
- }
-
- /**
- * Follows the documentid to find the way in the sitetree to the specified
- * node and opens all folders on its way.
- *
- * @param nodes
- * @param docid
- * @throws SiteTreeException
- * @throws SAXException
- */
- protected void generateFragmentRecursive(SiteTreeNode[] nodes, String docid)
- throws SiteTreeException, SAXException {
- String nodeid;
- String childid;
-
- if (nodes == null)
- return;
- if (docid.startsWith("/"))
- docid = docid.substring(1);
- if (docid.indexOf("/") != -1) {
- nodeid = docid.substring(0, docid.indexOf("/"));
- childid = docid.substring(docid.indexOf("/") + 1);
- } else {
- nodeid = docid;
- childid = "";
- }
-
- for (int i = 0; i < nodes.length; i++) {
- startNode(NODE_NODE, nodes[i]);
- addLabels(nodes[i]);
- if (nodes[i].getId().equals(nodeid)) {
- generateFragmentRecursive(nodes[i].getChildren(), childid);
- }
- endNode(NODE_NODE);
- }
- }
-
- /**
- * Begins a named node and calls setNodeAttributes to set its attributes.
- *
- * @param nodeName
- * the name of the new node
- * @throws SAXException
- * if an error occurs while creating the node
- */
- protected void startNode(String nodeName) throws SAXException {
- this.contentHandler.startElement(URI, nodeName,
- PREFIX + ':' + nodeName, this.attributes);
- }
-
- /**
- * Begins a named node and calls setNodeAttributes to set its attributes.
- *
- * @param nodeName
- * the name of the new node
- * @param node
- * The attributes are taken from this node
- * @throws SAXException
- * if an error occurs while creating the node
- */
- protected void startNode(String nodeName, SiteTreeNode node)
- throws SAXException {
- setNodeAttributes(node);
- this.contentHandler.startElement(URI, nodeName,
- PREFIX + ':' + nodeName, this.attributes);
- }
-
- /**
- * Sets the attributes for a given node. Sets attributes id, href, folder,
- * suffix, basic-url, language-suffix.
- *
- * @param node
- * @throws SAXException
- * if an error occurs while setting the attributes
- */
- protected void setNodeAttributes(SiteTreeNode node) throws SAXException {
- this.attributes.clear();
-
- String id = node.getId();
- String isVisible = Boolean.toString(node.visibleInNav());
- String hasLink = Boolean.toString(node.hasLink());
- String href = node.getHref();
- String suffix = node.getSuffix();
- String isFolder = isFolder(node);
-
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("adding attribute id: " + id);
- this.getLogger().debug(
- "adding attribute visibleinnav: " + isVisible);
- this.getLogger().debug("adding attribute link: " + hasLink);
- if (href != null)
- this.getLogger().debug("adding attribute href: " + href);
- if (suffix != null)
- this.getLogger().debug("adding attribute suffix: " + suffix);
- this.getLogger().debug("adding attribute folder: " + isFolder);
- }
- this.attributes.addAttribute("", ATTR_ID, ATTR_ID, "CDATA", id);
- this.attributes.addAttribute("", ATTR_VISIBLEINNAV, ATTR_VISIBLEINNAV,
- "CDATA", isVisible);
- this.attributes
- .addAttribute("", ATTR_LINK, ATTR_LINK, "CDATA", hasLink);
- if (href != null)
- this.attributes.addAttribute("", ATTR_HREF, ATTR_HREF, "CDATA",
- href);
- if (suffix != null)
- this.attributes.addAttribute("", ATTR_SUFFIX, ATTR_SUFFIX, "CDATA",
- suffix);
- this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA",
- isFolder);
- }
-
- /**
- * Returns a value to indicate whether a node is a folder (contains
- * subnodes). With the incremental sitetree loading, we sometimes load nodes
- * which are folders, but we don't load their children. But we still have to
- * know if it's a folder or not, i.e. if it can be opened.
- *
- * @param node
- * @return "true" or "false"
- */
- protected String isFolder(SiteTreeNode node) {
- if (node.getChildren().length > 0)
- return "true";
- else
- return "false";
- }
-
- /**
- * Ends the named node.
- *
- * @param nodeName
- * the name of the new node
- * @throws SAXException
- * if an error occurs while closing the node
- */
- protected void endNode(String nodeName) throws SAXException {
- this.contentHandler.endElement(URI, nodeName, PREFIX + ':' + nodeName);
- }
-
- /**
- * Finds all the label children of a node and adds them to the nav xml.
- *
- * @param node
- * @throws SAXException
- */
- protected void addLabels(SiteTreeNode node) throws SAXException {
- Label[] labels = node.getLabels();
-
- for (int i = 0; i < labels.length; i++) {
- String lang = labels[i].getLanguage();
- if (lang == null)
- lang = "";
- addLabel(labels[i].getLabel(), lang);
- }
- }
-
- /**
- * Adds a label element of a given language.
- *
- * @param label
- * the value of the label
- * @param language
- * the language of the label
- * @throws SAXException
- */
- protected void addLabel(String label, String language) throws SAXException {
- this.attributes.clear();
- this.attributes.addAttribute(XML_URI, ATTR_LANG, XML_PREFIX + ":"
- + ATTR_LANG, "CDATA", language);
-
- this.contentHandler.startElement(URI, NODE_LABEL, PREFIX + ':'
- + NODE_LABEL, this.attributes);
- char[] labelArray = label.toCharArray();
- this.contentHandler.characters(labelArray, 0, labelArray.length);
- this.contentHandler.endElement(URI, NODE_LABEL, PREFIX + ':'
- + NODE_LABEL);
- }
-
-}
+/*
+ * 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.
+ *
+ */
+
+/* @version $Id$*/
+
+package org.apache.lenya.cms.cocoon.generation;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+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.cocoon.generation.AbstractGenerator;
+import org.apache.lenya.cms.publication.Label;
+import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeFactory;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.SiteTree;
+import org.apache.lenya.cms.publication.SiteTreeException;
+import org.apache.lenya.cms.publication.SiteTreeNode;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Generates a fragment of the XML from the sitetree, corresponding to a given
+ * node. The node is specified by the sitemap parameters area/documentid. If the
+ * sitemap parameter initialTree is true, the top nodes of the tree will be
+ * generated and the node given by the sitemap parameters area/documentid will
+ * be unfolded. If initialTree is false, only the children of the selected node
+ * will be generated.
+ *
+ */
+public class SitetreeFragmentGenerator extends AbstractGenerator {
+
+ protected Publication publication;
+
+ /** Parameter which denotes the documentid of the clicked node */
+ protected String documentid;
+
+ /** Parameter which denotes the area of the clicked node */
+ protected String area;
+
+ /**
+ * Parameter which decides if the initial tree with the root nodes is
+ * generated
+ */
+ protected boolean initialTree;
+
+ /**
+ * Parameter which denotes a comma-separated list of areas, for which the
+ * xml will be generated.
+ */
+ protected String[] areas = null;
+
+ /**
+ * Convenience object, so we don't need to create an AttributesImpl for
+ * every element.
+ */
+ protected AttributesImpl attributes;
+
+ protected static final String PARAM_AREA = "area";
+
+ protected static final String PARAM_DOCUMENTID = "documentid";
+
+ protected static final String PARAM_INITIAL = "initial";
+
+ protected static final String PARAM_AREAS = "areas";
+
+ /** The URI of the namespace of this generator. */
+ protected static final String URI = "http://apache.org/cocoon/lenya/sitetree/1.0";
+
+ protected static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
+
+ /** The namespace prefix for this namespace. */
+ protected static final String PREFIX = "site";
+
+ protected static final String XML_PREFIX = "xml";
+
+ protected static final String NODE_NODE = "node";
+
+ protected static final String NODE_LABEL = "label";
+
+ protected static final String NODE_SITE = "site";
+
+ protected static final String NODE_FRAGMENT = "fragment";
+
+ protected static final String ATTR_ID = "id";
+
+ protected static final String ATTR_FOLDER = "folder";
+
+ protected static final String ATTR_AREA = "area";
+
+ protected static final String ATTR_LABEL = "label";
+
+ protected static final String ATTR_VISIBLEINNAV = "visibleinnav";
+
+ protected static final String ATTR_LINK = "link";
+
+ protected static final String ATTR_BASE = "base";
+
+ protected static final String ATTR_SUFFIX = "suffix";
+
+ protected static final String ATTR_HREF = "href";
+
+ protected static final String ATTR_LANG = "lang";
+
+ /**
+ * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
+ * java.util.Map, java.lang.String,
+ * org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void setup(SourceResolver resolver, Map objectModel, String src,
+ Parameters par) throws ProcessingException, SAXException,
+ IOException {
+ super.setup(resolver, objectModel, src, par);
+
+ PageEnvelope envelope = null;
+
+ if (getLogger().isDebugEnabled()) {
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ getLogger().debug(
+ "Resolving page envelope for URL ["
+ + request.getRequestURI() + "]");
+ }
+
+ this.area = par.getParameter(PARAM_AREA, null);
+ this.documentid = par.getParameter(PARAM_DOCUMENTID, null);
+
+ if (par.isParameter(PARAM_INITIAL)) {
+ this.initialTree = Boolean.valueOf(
+ par.getParameter(PARAM_INITIAL, null)).booleanValue();
+ } else {
+ this.initialTree = false;
+ }
+
+ if (par.isParameter(PARAM_AREAS)) {
+ String parAreas = par.getParameter(PARAM_AREAS, null);
+ this.areas = parAreas.split(",");
+ } else {
+ String temp[] = { "authoring", "archive", "trash" };
+ this.areas = temp;
+ }
+
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("Parameter area: " + this.area);
+ this.getLogger().debug("Parameter documentid: " + this.documentid);
+ this.getLogger()
+ .debug("Parameter initialTree: " + this.initialTree);
+ String areasStr = "";
+ for (int i = 0; i < this.areas.length; i++)
+ areasStr += this.areas[i] + " ";
+ this.getLogger().debug("Parameter areas: " + areasStr);
+ }
+
+ try {
+ envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(
+ objectModel);
+ } catch (Exception e) {
+ throw new ProcessingException("Resolving page envelope failed: ", e);
+ }
+
+ this.publication = envelope.getPublication();
+ this.attributes = new AttributesImpl();
+
+ }
+
+ /**
+ * @see org.apache.cocoon.generation.Generator#generate()
+ */
+ public void generate() throws IOException, SAXException,
+ ProcessingException {
+
+ try {
+
+ this.contentHandler.startDocument();
+ this.contentHandler.startPrefixMapping(PREFIX, URI);
+
+ attributes.clear();
+ if (!initialTree) {
+ attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA",
+ this.area);
+ attributes.addAttribute("", ATTR_BASE, ATTR_BASE, "CDATA",
+ this.documentid);
+ }
+
+ this.contentHandler.startElement(URI, NODE_FRAGMENT, PREFIX + ':'
+ + NODE_FRAGMENT, this.attributes);
+
+ if (this.initialTree) {
+ for (int i = 0; i < this.areas.length; i++) {
+ generateFragmentInitial(this.areas[i]);
+ }
+ } else {
+ generateFragment();
+ }
+
+ this.contentHandler.endElement(URI, NODE_FRAGMENT, PREFIX + ':'
+ + NODE_FRAGMENT);
+
+ this.contentHandler.endPrefixMapping(PREFIX);
+ this.contentHandler.endDocument();
+
+ } catch (SAXException e) {
+ throw new ProcessingException(e);
+ } catch (SiteTreeException e) {
+ throw new ProcessingException(e);
+ }
+
+ }
+
+ /**
+ * Generates a fragment of the tree which contains the children of a given
+ * node.
+ *
+ * @throws SiteTreeException
+ * @throws SAXException
+ * @throws ProcessingException
+ */
+ protected void generateFragment() throws SiteTreeException, SAXException,
+ ProcessingException {
+
+ SiteTree siteTree = null;
+ if (!this.area.equals(Publication.AUTHORING_AREA)
+ && !this.area.equals(Publication.ARCHIVE_AREA)
+ && !this.area.equals(Publication.TRASH_AREA)
+ && !this.area.equals(Publication.STAGING_AREA)
+ && !this.area.equals(Publication.LIVE_AREA)) {
+ throw new ProcessingException("Invalid area: " + this.area);
+ }
+ siteTree = publication.getTree(this.area);
+
+ SiteTreeNode node = siteTree.getNode(this.documentid);
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug(
+ "Node with documentid " + documentid + " found.");
+ }
+ if (node == null)
+ throw new SiteTreeException("Node with documentid " + documentid
+ + " not found.");
+
+ SiteTreeNode[] children = node.getChildren();
+
+ for (int i = 0; i < children.length; i++) {
+ startNode(NODE_NODE, children[i]);
+ addLabels(children[i]);
+ endNode(NODE_NODE);
+ }
+ }
+
+ /**
+ * Generates the top node of the given area and then calls a recursive
+ * method to traverse the tree, if the node given by area/documentid is in
+ * this area.
+ *
+ * @param siteArea
+ * @throws SiteTreeException
+ * @throws SAXException
+ * @throws ProcessingException
+ */
+ protected void generateFragmentInitial(String siteArea)
+ throws SiteTreeException, SAXException, ProcessingException {
+
+ SiteTree siteTree = publication.getTree(siteArea);
+
+ String label = "";
+ String isFolder = "";
+
+ // FIXME: don't hardcode area label
+ if (siteArea.equals(Publication.AUTHORING_AREA))
+ label = "Authoring";
+ if (siteArea.equals(Publication.ARCHIVE_AREA))
+ label = "Archive";
+ if (siteArea.equals(Publication.TRASH_AREA))
+ label = "Trash";
+ if (siteArea.equals(Publication.LIVE_AREA))
+ label = "Live";
+ if (siteArea.equals(Publication.STAGING_AREA))
+ label = "Staging";
+
+ if (siteTree.getTopNodes().length > 0)
+ isFolder = "true";
+ else
+ isFolder = "false";
+
+ this.attributes.clear();
+ this.attributes.addAttribute("", ATTR_AREA, ATTR_AREA, "CDATA",
+ siteArea);
+ this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA",
+ isFolder);
+ this.attributes
+ .addAttribute("", ATTR_LABEL, ATTR_LABEL, "CDATA", label);
+
+ startNode(NODE_SITE);
+
+ if (area.equals(siteArea)) {
+ generateFragmentRecursive(siteTree.getTopNodes(), this.documentid);
+ }
+
+ endNode(NODE_SITE);
+ }
+
+ /**
+ * Follows the documentid to find the way in the sitetree to the specified
+ * node and opens all folders on its way.
+ *
+ * @param nodes
+ * @param docid
+ * @throws SiteTreeException
+ * @throws SAXException
+ */
+ protected void generateFragmentRecursive(SiteTreeNode[] nodes, String docid)
+ throws SiteTreeException, SAXException {
+ String nodeid;
+ String childid;
+
+ if (nodes == null)
+ return;
+ if (docid.startsWith("/"))
+ docid = docid.substring(1);
+ if (docid.indexOf("/") != -1) {
+ nodeid = docid.substring(0, docid.indexOf("/"));
+ childid = docid.substring(docid.indexOf("/") + 1);
+ } else {
+ nodeid = docid;
+ childid = "";
+ }
+
+ for (int i = 0; i < nodes.length; i++) {
+ startNode(NODE_NODE, nodes[i]);
+ addLabels(nodes[i]);
+ if (nodes[i].getId().equals(nodeid)) {
+ generateFragmentRecursive(nodes[i].getChildren(), childid);
+ }
+ endNode(NODE_NODE);
+ }
+ }
+
+ /**
+ * Begins a named node and calls setNodeAttributes to set its attributes.
+ *
+ * @param nodeName
+ * the name of the new node
+ * @throws SAXException
+ * if an error occurs while creating the node
+ */
+ protected void startNode(String nodeName) throws SAXException {
+ this.contentHandler.startElement(URI, nodeName,
+ PREFIX + ':' + nodeName, this.attributes);
+ }
+
+ /**
+ * Begins a named node and calls setNodeAttributes to set its attributes.
+ *
+ * @param nodeName
+ * the name of the new node
+ * @param node
+ * The attributes are taken from this node
+ * @throws SAXException
+ * if an error occurs while creating the node
+ */
+ protected void startNode(String nodeName, SiteTreeNode node)
+ throws SAXException {
+ setNodeAttributes(node);
+ this.contentHandler.startElement(URI, nodeName,
+ PREFIX + ':' + nodeName, this.attributes);
+ }
+
+ /**
+ * Sets the attributes for a given node. Sets attributes id, href, folder,
+ * suffix, basic-url, language-suffix.
+ *
+ * @param node
+ * @throws SAXException
+ * if an error occurs while setting the attributes
+ */
+ protected void setNodeAttributes(SiteTreeNode node) throws SAXException {
+ this.attributes.clear();
+
+ String id = node.getId();
+ String isVisible = Boolean.toString(node.visibleInNav());
+ String hasLink = Boolean.toString(node.hasLink());
+ String href = node.getHref();
+ String suffix = node.getSuffix();
+ String isFolder = isFolder(node);
+
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("adding attribute id: " + id);
+ this.getLogger().debug(
+ "adding attribute visibleinnav: " + isVisible);
+ this.getLogger().debug("adding attribute link: " + hasLink);
+ if (href != null)
+ this.getLogger().debug("adding attribute href: " + href);
+ if (suffix != null)
+ this.getLogger().debug("adding attribute suffix: " + suffix);
+ this.getLogger().debug("adding attribute folder: " + isFolder);
+ }
+ this.attributes.addAttribute("", ATTR_ID, ATTR_ID, "CDATA", id);
+ this.attributes.addAttribute("", ATTR_VISIBLEINNAV, ATTR_VISIBLEINNAV,
+ "CDATA", isVisible);
+ this.attributes
+ .addAttribute("", ATTR_LINK, ATTR_LINK, "CDATA", hasLink);
+ if (href != null)
+ this.attributes.addAttribute("", ATTR_HREF, ATTR_HREF, "CDATA",
+ href);
+ if (suffix != null)
+ this.attributes.addAttribute("", ATTR_SUFFIX, ATTR_SUFFIX, "CDATA",
+ suffix);
+ this.attributes.addAttribute("", ATTR_FOLDER, ATTR_FOLDER, "CDATA",
+ isFolder);
+ }
+
+ /**
+ * Returns a value to indicate whether a node is a folder (contains
+ * subnodes). With the incremental sitetree loading, we sometimes load nodes
+ * which are folders, but we don't load their children. But we still have to
+ * know if it's a folder or not, i.e. if it can be opened.
+ *
+ * @param node
+ * @return "true" or "false"
+ */
+ protected String isFolder(SiteTreeNode node) {
+ if (node.getChildren().length > 0)
+ return "true";
+ else
+ return "false";
+ }
+
+ /**
+ * Ends the named node.
+ *
+ * @param nodeName
+ * the name of the new node
+ * @throws SAXException
+ * if an error occurs while closing the node
+ */
+ protected void endNode(String nodeName) throws SAXException {
+ this.contentHandler.endElement(URI, nodeName, PREFIX + ':' + nodeName);
+ }
+
+ /**
+ * Finds all the label children of a node and adds them to the nav xml.
+ *
+ * @param node
+ * @throws SAXException
+ */
+ protected void addLabels(SiteTreeNode node) throws SAXException {
+ Label[] labels = node.getLabels();
+
+ for (int i = 0; i < labels.length; i++) {
+ String lang = labels[i].getLanguage();
+ if (lang == null)
+ lang = "";
+ addLabel(labels[i].getLabel(), lang);
+ }
+ }
+
+ /**
+ * Adds a label element of a given language.
+ *
+ * @param label
+ * the value of the label
+ * @param language
+ * the language of the label
+ * @throws SAXException
+ */
+ protected void addLabel(String label, String language) throws SAXException {
+ this.attributes.clear();
+ this.attributes.addAttribute(XML_URI, ATTR_LANG, XML_PREFIX + ":"
+ + ATTR_LANG, "CDATA", language);
+
+ this.contentHandler.startElement(URI, NODE_LABEL, PREFIX + ':'
+ + NODE_LABEL, this.attributes);
+ char[] labelArray = label.toCharArray();
+ this.contentHandler.characters(labelArray, 0, labelArray.length);
+ this.contentHandler.endElement(URI, NODE_LABEL, PREFIX + ':'
+ + NODE_LABEL);
+ }
+
+}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java?rev=617315&r1=617314&r2=617315&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Content.java Thu Jan 31 16:23:00 2008
@@ -1,18 +1,16 @@
package org.apache.lenya.cms.content;
-
/**
*
* @author solprovider
* @since 1.3
*/
-public interface Content{
+public interface Content {
public static final String TYPE_FLAT = "flat";
public static final String TYPE_HIERARCHICAL = "hierarchical";
-
+ public static final String TYPE_DEFAULT = "all";
public String getURI(String unid, String language, String revision);
public String getMetaURI(String unid, String language, String revision);
public String getNewURI(String unid, String language);
-
public String getUNID(String structure, String id);
public String getIndexFilename(String indexName, String language);
public String[] getLanguages();
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/Module.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/Module.java?rev=617315&r1=617314&r2=617315&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/Module.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/modules/Module.java Thu Jan 31 16:23:00 2008
@@ -26,14 +26,13 @@
Map variables = new HashMap(); // nameString = valueString
Map files; // filename -> actual location as String (Better as File or Source?)
File moduleDirectory;
- String type = Content.TYPE_HIERARCHICAL;
+ private String type = Content.TYPE_DEFAULT;
String id;
String name;
String minimum = "1.3";
String maximum = "";
String created = "1.3";
- String content = "all";
- String modified = "1.3";
+ long modified = 1;
String resource = "";
String description = "";
String usage = "";
@@ -53,9 +52,20 @@
minimum = config.getAttribute("minimum", minimum);
maximum = config.getAttribute("maximum", maximum);
created = config.getAttribute("created", created);
- content = config.getAttribute("content", content);
- modified = config.getAttribute("modified", modified);
+ type = config.getAttribute("content", type);
+ try{
+ modified = Long.parseLong(config.getAttribute("modified", "" + modified));
+ }catch(NumberFormatException nfe){
+ modified = 1;
+ }
resource = config.getAttribute("resource", "");
+ if((resource.length() > 0) && !resource.endsWith("/" + id)){
+ if(resource.endsWith("/")){
+ resource += id;
+ }else{
+ resource += "/" + id;
+ }
+ }
// Description
Configuration descriptionConf = config.getChild("description");
description = descriptionConf.getValue("");
@@ -131,7 +141,7 @@
}
}
}
- public String getType() {
+ public String getContentType() {
return type;
}
public int getModified() {
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.