Author: andreas
Date: Fri Jan 25 05:31:48 2008
New Revision: 615217
URL: http://svn.apache.org/viewvc?rev=615217&view=rev
Log:
Enhancing Publication interface: add setters, prepare Proxy interface for modifiability
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Proxy.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java?rev=615217&r1=615216&r2=615217&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java Fri Jan 25 05:31:48 2008
@@ -23,12 +23,17 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.lenya.cms.repository.Node;
import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.util.Assert;
/**
* A publication's configuration. Keep in sync with
@@ -38,13 +43,21 @@
private String id;
private String name;
+ private String description;
+ private String version;
+ private String lenyaVersion;
+ private String lenyaRevision;
+ private String cocoonVersion;
+
private File servletContext;
private DocumentIdToPathMapper mapper = null;
- private ArrayList languages = new ArrayList();
+ private SortedSet languages = new TreeSet();
private String defaultLanguage = null;
private String breadcrumbprefix = null;
private String instantiatorHint = null;
private String contentDir = null;
+ private SortedSet modules = new TreeSet();
+ private String contextPath;
private boolean isConfigLoaded = false;
@@ -59,7 +72,6 @@
// properties marked with "*" are currently not parsed by this class.
private static final String ELEMENT_NAME = "name";
private static final String ELEMENT_DESCRIPTION = "description"; // *
- private static final String ELEMENT_LONGDESC = "longdesc"; // *
private static final String ELEMENT_VERSION = "version"; // *
private static final String ELEMENT_LENYA_VERSION = "lenya-version"; // *
private static final String ELEMENT_LENYA_REVISION = "lenya-revision"; // *
@@ -87,18 +99,23 @@
private static final String ATTRIBUTE_AREA = "area";
private static final String ATTRIBUTE_URL = "url";
private static final String ATTRIBUTE_SSL = "ssl";
+
+ protected static final String NAMESPACE = "http://apache.org/cocoon/lenya/publication/1.1";
+ protected static final String NS_PREFIX = "";
/**
* Creates a new instance of Publication
* @param _id the publication id
- * @param servletContextPath the servlet context of this publication
+ * @param servletContextPath the servlet context directory of this publication
+ * @param servletContextUrlPath The servlet context path (URL snippet).
* @throws PublicationException if there was a problem reading the config
* file
*/
- protected PublicationConfiguration(String _id, String servletContextPath)
+ protected PublicationConfiguration(String _id, String servletContextPath, String servletContextUrlPath)
throws PublicationException {
this.id = _id;
this.servletContext = new File(servletContextPath);
+ this.contextPath = servletContextUrlPath;
}
/**
@@ -145,6 +162,12 @@
else {
this.name = pubName;
}
+
+ this.description = config.getChild(ELEMENT_DESCRIPTION).getValue("");
+ this.version = config.getChild(ELEMENT_VERSION).getValue("");
+ this.lenyaVersion = config.getChild(ELEMENT_LENYA_VERSION).getValue("");
+ this.lenyaRevision = config.getChild(ELEMENT_LENYA_REVISION).getValue("");
+ this.cocoonVersion = config.getChild(ELEMENT_COCOON_VERSION).getValue("");
try {
// one sanity check for the proper namespace. we should really
@@ -196,14 +219,13 @@
String ssl = proxyConfigs[i].getAttribute(ATTRIBUTE_SSL);
String area = proxyConfigs[i].getAttribute(ATTRIBUTE_AREA);
- Proxy proxy = new Proxy();
- proxy.setUrl(url);
-
Object key = getProxyKey(area, Boolean.valueOf(ssl).booleanValue());
+ Proxy proxy = new Proxy(getDefaultProxyUrl(area));
+ proxy.setUrl(url);
this.areaSsl2proxy.put(key, proxy);
if (getLogger().isDebugEnabled()) {
getLogger().debug(
- "Adding proxy: [" + proxy + "] for area=[" + area + "] SSL=[" + ssl
+ "Adding proxy URL: [" + url + "] for area=[" + area + "] SSL=[" + ssl
+ "]");
}
}
@@ -255,6 +277,15 @@
}
}
+ Configuration modulesConf = config.getChild(ELEMENT_MODULES);
+ if (modulesConf != null) {
+ Configuration[] modulesConfigs = modulesConf.getChildren(ELEMENT_MODULE);
+ for (int i = 0; i < modulesConfigs.length; i++) {
+ String name = modulesConfigs[i].getAttribute(ATTRIBUTE_NAME);
+ this.modules.add(name);
+ }
+ }
+
} catch (final Exception e) {
throw new RuntimeException("Problem with config file: " + configFile.getAbsolutePath(),
e);
@@ -264,6 +295,10 @@
isConfigLoaded = true;
}
+
+ protected String getDefaultProxyUrl(String area) {
+ return this.contextPath + "/" + this.id + "/" + area;
+ }
/**
* @return The configuration file ({@link #CONFIGURATION_FILE}).
@@ -341,6 +376,11 @@
* @param language the default language
*/
public void setDefaultLanguage(String language) {
+ Assert.notNull(language);
+ if (!Arrays.asList(getLanguages()).contains(language)) {
+ throw new IllegalArgumentException("The publication [" + this +
+ "] doesn't contain the language [" + language + "]!");
+ }
this.defaultLanguage = language;
}
@@ -405,47 +445,31 @@
* @param isSslProtected If the proxy is assigned for SSL-protected pages.
* @return An object.
*/
- protected Object getProxyKey(String area, boolean isSslProtected) {
+ protected String getProxyKey(String area, boolean isSslProtected) {
return area + ":" + isSslProtected;
}
+
+ protected String getProxyUrl(String area, boolean isSslProtected) {
+ loadConfiguration();
+ Object key = getProxyKey(area, isSslProtected);
+ return (String) this.areaSsl2proxy.get(key);
+ }
- /**
- * @see org.apache.lenya.cms.publication.Publication#getProxy(org.apache.lenya.cms.publication.Document,
- * boolean)
- */
+
public Proxy getProxy(Document document, boolean isSslProtected) {
- Proxy proxy = getProxy(document.getArea(), isSslProtected);
-
- if (getLogger().isDebugEnabled()) {
- getLogger()
- .debug("Resolving proxy for [" + document + "] SSL=[" + isSslProtected + "]");
- getLogger().debug("Resolved proxy: [" + proxy + "]");
- }
-
- return proxy;
+ return getProxy(document.getArea(), isSslProtected);
}
- /**
- * @see org.apache.lenya.cms.publication.Publication#getProxy(java.lang.String,
- * boolean)
- */
public Proxy getProxy(String area, boolean isSslProtected) {
- loadConfiguration();
- Object key = getProxyKey(area, isSslProtected);
+ String key = getProxyKey(area, isSslProtected);
Proxy proxy = (Proxy) this.areaSsl2proxy.get(key);
+ if (proxy == null) {
+ proxy = new Proxy(getDefaultProxyUrl(area));
+ this.areaSsl2proxy.put(key, proxy);
+ }
return proxy;
}
-
- /**
- * @param area The area.
- * @param isSslProtected If the proxy is for SSL-protected URLs.
- * @param proxy The proxy to set.
- */
- protected void setProxy(String area, boolean isSslProtected, Proxy proxy) {
- Object key = getProxyKey(area, isSslProtected);
- this.areaSsl2proxy.put(key, proxy);
- }
-
+
private String siteManagerName;
/**
@@ -488,11 +512,15 @@
public String getContentDir() {
loadConfiguration();
if (this.contentDir == null) {
- this.contentDir = new File(getDirectory(), CONTENT_PATH).getAbsolutePath();
+ this.contentDir = getDefaultContentDir();
}
return this.contentDir;
}
+ protected String getDefaultContentDir() {
+ return new File(getDirectory(), CONTENT_PATH).getAbsolutePath();
+ }
+
/**
* @see org.apache.lenya.cms.publication.Publication#getSourceURI()
*/
@@ -513,11 +541,10 @@
* @see org.apache.lenya.cms.publication.Publication#getWorkflowSchema(org.apache.lenya.cms.publication.ResourceType)
*/
public String getWorkflowSchema(ResourceType resourceType) {
- String workflow = (String) this.resourceType2workflow.get(resourceType.getName());
- return workflow;
+ return (String) this.resourceType2workflow.get(resourceType.getName());
}
- private List resourceTypes = new ArrayList();
+ private SortedSet resourceTypes = new TreeSet();
/**
* @see org.apache.lenya.cms.publication.Publication#getResourceTypeNames()
@@ -566,6 +593,153 @@
public Session getSession() {
throw new UnsupportedOperationException();
+ }
+
+ public void addLanguage(String language) {
+ Assert.notNull("language", language);
+ this.languages.add(language);
+ }
+
+ public void removeLanguage(String language) {
+ Assert.notNull("language", language);
+ if (!Arrays.asList(getLanguages()).contains(language)) {
+ throw new IllegalArgumentException("The publication [" + this +
+ "] doesn't contain the language [" + language + "]!");
+ }
+ if (language.equals(getDefaultLanguage())) {
+ throw new IllegalArgumentException("Can't remove the language [" + language +
+ "] because it is the default language.");
+ }
+ this.languages.remove(language);
+ }
+
+ public void setName(String name) {
+ Assert.notNull("name", name);
+ Assert.isTrue("name not empty", name.length() > 0);
+ this.name = name;
+ }
+
+ protected DefaultConfiguration createConfig(String name) {
+ return new DefaultConfiguration(name, "", NAMESPACE, NS_PREFIX);
+ }
+
+ protected DefaultConfiguration createConfig(String name, String value) {
+ DefaultConfiguration config = createConfig(name);
+ config.setValue(value);
+ return config;
+ }
+
+ protected DefaultConfiguration createConfig(String name, String attrName, String attrValue) {
+ DefaultConfiguration config = createConfig(name);
+ config.setAttribute(attrName, attrValue);
+ return config;
+ }
+
+ public void saveConfiguration() {
+ File configFile = getConfigurationFile();
+
+ DefaultConfiguration config = new DefaultConfiguration("publication", "", NAMESPACE, NS_PREFIX);
+
+ try {
+
+ config.addChild(createConfig(ELEMENT_NAME, getName()));
+ config.addChild(createConfig(ELEMENT_DESCRIPTION, this.description));
+ config.addChild(createConfig(ELEMENT_VERSION, this.version));
+ config.addChild(createConfig(ELEMENT_LENYA_VERSION, this.lenyaVersion));
+ config.addChild(createConfig(ELEMENT_LENYA_REVISION, this.lenyaRevision));
+ config.addChild(createConfig(ELEMENT_COCOON_VERSION, this.cocoonVersion));
+
+ config.addChild(createConfig(ELEMENT_PATH_MAPPER, getPathMapper().getClass().getName()));
+ config.addChild(createConfig(ELEMENT_DOCUMENT_BUILDER, ATTRIBUTE_NAME, getDocumentBuilderHint()));
+
+ String[] languages = getLanguages();
+ String defaultLanguage = getDefaultLanguage();
+
+ DefaultConfiguration languagesConfig = createConfig(ELEMENT_LANGUAGES);
+ for (int i = 0; i < languages.length; i++) {
+ DefaultConfiguration languageConfig = createConfig(ELEMENT_LANGUAGE);
+ languageConfig.setValue(languages[i]);
+ if (languages[i].equals(defaultLanguage)) {
+ languageConfig.setAttribute(ATTRIBUTE_DEFAULT_LANGUAGE, true);
+ }
+ languagesConfig.addChild(languageConfig);
+ }
+ config.addChild(languagesConfig);
+
+ config.addChild(createConfig(ELEMENT_SITE_MANAGER, ATTRIBUTE_NAME, getSiteManagerHint()));
+
+ DefaultConfiguration proxiesConfig = createConfig(ELEMENT_PROXIES);
+ config.addChild(proxiesConfig);
+ Boolean[] booleans = { Boolean.FALSE, Boolean.TRUE };
+ String[] areas = getAreaNames();
+ for (int b = 0; b < booleans.length; b++) {
+ for (int a = 0; a < areas.length; a++) {
+ boolean ssl = booleans[b].booleanValue();
+
+ Proxy proxy = getProxy(areas[a], ssl);
+
+ // add only proxy URLs for non-default proxies
+ if (!proxy.getUrl().equals(proxy.getDefaultUrl())) {
+ DefaultConfiguration proxyConf = createConfig(ELEMENT_PROXY);
+ proxyConf.setAttribute(ATTRIBUTE_AREA, areas[a]);
+ proxyConf.setAttribute(ATTRIBUTE_SSL, ssl);
+ proxyConf.setAttribute(ATTRIBUTE_URL, proxy.getUrl());
+ proxiesConfig.addChild(proxyConf);
+ }
+
+ }
+ }
+
+ String[] templates = getTemplateIds();
+ if (templates.length > 0) {
+ config.addChild(createConfig(ELEMENT_TEMPLATE, ATTRIBUTE_ID, templates[0]));
+ }
+
+ String instantiatorHint = getInstantiatorHint();
+ if (instantiatorHint != null) {
+ config.addChild(createConfig(ELEMENT_TEMPLATE_INSTANTIATOR, ATTRIBUTE_NAME, instantiatorHint));
+ }
+
+ String contentDir = getContentDir();
+ if (!contentDir.equals(getDefaultContentDir())) {
+ config.addChild(createConfig(ELEMENT_CONTENT_DIR, ATTRIBUTE_SRC, this.contentDir));
+ }
+
+ DefaultConfiguration resourceTypesConf = createConfig(ELEMENT_RESOURCE_TYPES);
+ config.addChild(resourceTypesConf);
+ String[] resourceTypes = getResourceTypeNames();
+ for (int i = 0; i < resourceTypes.length; i++) {
+ String type = resourceTypes[i];
+ DefaultConfiguration resourceTypeConf = createConfig(ELEMENT_RESOURCE_TYPE, ATTRIBUTE_NAME, type);
+ if (this.resourceType2workflow.containsKey(type)) {
+ resourceTypeConf.setAttribute(ATTRIBUTE_WORKFLOW, (String)
+ this.resourceType2workflow.get(type));
+ }
+ resourceTypesConf.addChild(resourceTypeConf);
+ }
+
+ DefaultConfiguration modulesConf = createConfig(ELEMENT_MODULES);
+ config.addChild(modulesConf);
+ String[] modules = getModuleNames();
+ for (int i = 0; i < modules.length; i++) {
+ DefaultConfiguration moduleConf = createConfig(ELEMENT_MODULE, ATTRIBUTE_NAME, modules[i]);
+ modulesConf.addChild(moduleConf);
+ }
+
+ config.addChild(createConfig(ELEMENT_BREADCRUMB_PREFIX, getBreadcrumbPrefix()));
+
+ DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
+ serializer.setIndent(true);
+ serializer.serializeToFile(getConfigurationFile(), config);
+
+ } catch (final Exception e) {
+ throw new RuntimeException("Problem with config file: " + configFile.getAbsolutePath(),
+ e);
+ }
+ }
+
+ public String[] getModuleNames() {
+ return (String[]) this.modules.toArray(new String[this.modules.size()]);
}
}
Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java?rev=615217&r1=615216&r2=615217&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java Fri Jan 25 05:31:48 2008
@@ -113,14 +113,7 @@
}
public Proxy getProxy(String area, boolean isSslProtected) {
- Proxy proxy = delegate.getProxy(area, isSslProtected);
- if (proxy == null) {
- String url = getDefaultProxyUrl(area);
- proxy = new Proxy();
- proxy.setUrl(url);
- this.delegate.setProxy(area, isSslProtected, proxy);
- }
- return proxy;
+ return delegate.getProxy(area, isSslProtected);
}
private String contextPath;
@@ -143,14 +136,6 @@
return this.contextPath;
}
- /**
- * @param area The area.
- * @return The proxy URL if no proxy is declared in {@link PublicationConfiguration#CONFIGURATION_FILE}.
- */
- protected String getDefaultProxyUrl(String area) {
- return getContextPath() + "/" + getId() + "/" + area;
- }
-
private List allResourceTypes;
protected String getFirstTemplateId() {
@@ -257,6 +242,26 @@
public Session getSession() {
return getFactory().getSession();
+ }
+
+ public void addLanguage(String language) {
+ this.delegate.addLanguage(language);
+ }
+
+ public String[] getModuleNames() {
+ return this.delegate.getModuleNames();
+ }
+
+ public void removeLanguage(String language) {
+ this.delegate.removeLanguage(language);
+ }
+
+ public void saveConfiguration() {
+ this.delegate.saveConfiguration();
+ }
+
+ public void setName(String name) {
+ this.delegate.setName(name);
}
}
Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java?rev=615217&r1=615216&r2=615217&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java Fri Jan 25 05:31:48 2008
@@ -39,6 +39,7 @@
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.SourceUtil;
+import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
import org.apache.lenya.cms.repository.RepositoryException;
import org.apache.lenya.util.Assert;
@@ -152,10 +153,21 @@
if (id2config.containsKey(pubId)) {
throw new PublicationException("The publication [" + pubId + "] already exists.");
}
- PublicationConfiguration config = new PublicationConfiguration(pubId,
- this.servletContextPath);
- ContainerUtil.enableLogging(config, getLogger());
- id2config.put(pubId, config);
+ ContextUtility context = null;
+ try {
+ context = (ContextUtility) this.manager.lookup(ContextUtility.ROLE);
+ PublicationConfiguration config = new PublicationConfiguration(pubId,
+ this.servletContextPath, context.getRequest().getContextPath());
+ ContainerUtil.enableLogging(config, getLogger());
+ id2config.put(pubId, config);
+ } catch (ServiceException e) {
+ throw new PublicationException(e);
+ }
+ finally {
+ if (context != null) {
+ this.manager.release(context);
+ }
+ }
}
protected String getServletContextPath() {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Proxy.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Proxy.java?rev=615217&r1=615216&r2=615217&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Proxy.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Proxy.java Fri Jan 25 05:31:48 2008
@@ -17,6 +17,8 @@
*/
package org.apache.lenya.cms.publication;
+import org.apache.lenya.util.Assert;
+
/**
* <p>
* An object of this class represents a proxy configuration.
@@ -36,10 +38,32 @@
* @version $Id$
*/
public class Proxy {
-
+
+ private String defaultUrl;
private String url;
/**
+ * @param defaultUrl The default proxy URL.
+ */
+ public Proxy(String defaultUrl) {
+ Assert.notNull("default URL", defaultUrl);
+ this.defaultUrl = defaultUrl;
+ }
+
+ /**
+ */
+ public Proxy() {
+ }
+
+ /**
+ * @param area The area.
+ * @return The proxy URL if no proxy is declared in {@link PublicationConfiguration#CONFIGURATION_FILE}.
+ */
+ public String getDefaultUrl() {
+ return this.defaultUrl;
+ }
+
+ /**
* Returns the absolute URL of a particular document.
* @param document The document.
* @return A string.
@@ -53,7 +77,15 @@
* @return A string.
*/
public String getUrl() {
- return this.url;
+ if (this.url != null) {
+ return this.url;
+ }
+ else if (this.defaultUrl != null) {
+ return this.defaultUrl;
+ }
+ else {
+ throw new IllegalStateException("This proxy has no URL.");
+ }
}
/**
@@ -61,6 +93,7 @@
* @param _url The url to set.
*/
public void setUrl(String _url) {
+ Assert.notNull("url", _url);
this.url = _url;
}
@@ -70,4 +103,5 @@
public String toString() {
return "Proxy URL=[" + getUrl() + "]";
}
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java?rev=615217&r1=615216&r2=615217&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java Fri Jan 25 05:31:48 2008
@@ -93,6 +93,11 @@
* @return The name of the publication as specified in the configuration file.
*/
String getName();
+
+ /**
+ * @param name The name of the publication.
+ */
+ void setName(String name);
/**
* Returns the servlet context this publication belongs to (usually, the
@@ -139,7 +144,8 @@
/**
* Set the default language
- * @param language the default language
+ * @param language The default language.
+ * @throws IllegalArgumentException if the publication doesn't contain this language.
*/
void setDefaultLanguage(String language);
@@ -148,6 +154,19 @@
* @return an <code>Array</code> of languages
*/
String[] getLanguages();
+
+ /**
+ * @param language The language to add.
+ * @throws IllegalArgumentException if the language is invalid or already contained.
+ */
+ void addLanguage(String language);
+
+ /**
+ * @param language The language to remove.
+ * @throws IllegalArgumentException if the language is not contained or if the language
+ * is the default language.
+ */
+ void removeLanguage(String language);
/**
* Get the breadcrumb prefix. It can be used as a prefix if a publication is part of a larger
@@ -254,5 +273,15 @@
* @return The document factory.
*/
public DocumentFactory getFactory();
+
+ /**
+ * Saves the configuration of this publication.
+ */
+ void saveConfiguration();
+
+ /**
+ * @return The names of all modules which are used by this publication.
+ */
+ String[] getModuleNames();
}
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.