You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/03/17 10:16:50 UTC
svn commit: r157923 - in lenya/trunk/src/java/org/apache/lenya/cms: ac/
cocoon/source/ publication/ publication/templating/ publication/usecases/
scheduler/ usecase/
Author: andreas
Date: Thu Mar 17 01:16:44 2005
New Revision: 157923
URL: http://svn.apache.org/viewcvs?view=rev&rev=157923
Log:
Replaced PublicationFactory.existsPublication() by Publication.exists(). This way, all PublicationFactory.getPublication() methods can be used to check if a publication exits. The change was possible because of the publication config lazy loading.
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/ExistingUsecaseResolver.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java
lenya/trunk/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java
lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java Thu Mar 17 01:16:44 2005
@@ -104,19 +104,17 @@
String publicationId = info.getPublicationId();
File contextDir = getContext();
- if (PublicationFactory.existsPublication(publicationId, contextDir.getAbsolutePath())) {
-
+ PublicationFactory factory = PublicationFactory.getInstance(getLogger());
+ try {
+ publication = factory.getPublication(webappUrl, contextDir);
+ } catch (PublicationException e) {
+ throw new AccessControlException(e);
+ }
+ if (publication.exists()) {
getLogger().debug("Publication [" + publicationId + "] exists.");
- try {
- PublicationFactory factory = PublicationFactory.getInstance(getLogger());
- publication = factory.getPublication(publicationId, contextDir
- .getAbsolutePath());
- } catch (PublicationException e) {
- throw new AccessControlException(e);
- }
-
} else {
getLogger().debug("Publication [" + publicationId + "] does not exist.");
+ publication = null;
}
}
return publication;
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java Thu Mar 17 01:16:44 2005
@@ -28,9 +28,7 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.cocoon.Constants;
import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.Request;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceFactory;
@@ -109,8 +107,8 @@
URLInformation info = new URLInformation(webappUrl);
String publicationId = info.getPublicationId();
- if (publicationId != null && PublicationFactory.existsPublication(publicationId, contextPath)) {
- Publication pub = factory.getPublication(publicationId, contextPath);
+ Publication pub = factory.getPublication(publicationId, contextPath);
+ if (pub.exists()) {
templateManager.setup(pub);
ExistingSourceResolver resolver = new ExistingSourceResolver();
templateManager.visit(path, resolver);
@@ -154,9 +152,6 @@
private org.apache.avalon.framework.context.Context context;
- /** The environment context */
- private Context envContext;
-
/** The ServiceManager */
private ServiceManager manager;
@@ -173,7 +168,6 @@
*/
public void contextualize(org.apache.avalon.framework.context.Context _context)
throws ContextException {
- this.envContext = (Context) _context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
this.context = _context;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Publication.java Thu Mar 17 01:16:44 2005
@@ -54,50 +54,6 @@
*/
String TRASH_AREA = "trash";
/**
- * <code>ELEMENT_PATH_MAPPER</code> The path mapper element
- */
- String ELEMENT_PATH_MAPPER = "path-mapper";
- /**
- * <code>ELEMENT_DOCUMENT_BUILDER</code> The document buider element
- */
- String ELEMENT_DOCUMENT_BUILDER = "document-builder";
- /**
- * <code>ELEMENT_SITE_STRUCTURE</code> The site structure element
- */
- String ELEMENT_SITE_STRUCTURE = "site-structure";
- /**
- * <code>ATTRIBUTE_TYPE</code> The type attribute
- */
- String ATTRIBUTE_TYPE = "type";
- /**
- * <code>ATTRIBUTE_SRC</code> The src attribute
- */
- String ATTRIBUTE_SRC = "type";
- /**
- * <code>LANGUAGES</code> The languages
- */
- String LANGUAGES = "languages";
- /**
- * <code>LANGUAGE</code> The language
- */
- String LANGUAGE = "language";
- /**
- * <code>DEFAULT_LANGUAGE_ATTR</code> The default language attribute
- */
- String DEFAULT_LANGUAGE_ATTR = "default";
- /**
- * <code>BREADCRUMB_PREFIX</code> The breadcrumb prefix
- */
- String BREADCRUMB_PREFIX = "breadcrumb-prefix";
- /**
- * <code>SSL_PREFIX</code> The SSL prefix
- */
- String SSL_PREFIX = "ssl-prefix";
- /**
- * <code>LIVE_MOUNT_POINT</code> The live mount point
- */
- String LIVE_MOUNT_POINT = "live-mount-point";
- /**
* <code>PUBLICATION_PREFIX</code> The publication prefix
*/
String PUBLICATION_PREFIX = "lenya" + File.separator + "pubs";
@@ -129,10 +85,6 @@
* <code>SEARCH_AREA_PREFIX</code> The search area prefix
*/
String SEARCH_AREA_PREFIX = "search-";
- /**
- * <code>CONFIGURATION_FILE</code> The publication configuration file
- */
- String CONFIGURATION_FILE = CONFIGURATION_PATH + File.separator + "publication.xconf";
/**
* Returns the publication ID.
@@ -146,6 +98,11 @@
* @return A <code>File</code> object.
*/
File getServletContext();
+
+ /**
+ * @return if this publication exists.
+ */
+ boolean exists();
/**
* Returns the publication directory.
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationFactory.java Thu Mar 17 01:16:44 2005
@@ -104,11 +104,9 @@
if (keyToPublication.containsKey(key)) {
publication = (Publication) keyToPublication.get(key);
} else {
- if (PublicationFactory.existsPublication(id, servletContextPath)) {
- publication = new PublicationImpl(id, servletContextPath);
- ContainerUtil.enableLogging(publication, getLogger());
- keyToPublication.put(key, publication);
- }
+ publication = new PublicationImpl(id, servletContextPath);
+ ContainerUtil.enableLogging(publication, getLogger());
+ keyToPublication.put(key, publication);
}
if (publication == null) {
@@ -173,28 +171,6 @@
}
/**
- * Checks if a publication with a certain ID exists in a certain context.
- * @param id The publication ID.
- * @param servletContextPath The webapp context path.
- * @return <code>true</code> if the publication exists, <code>false</code> otherwise.
- */
- public static boolean existsPublication(String id, String servletContextPath) {
-
- if (servletContextPath.endsWith("/")) {
- servletContextPath = servletContextPath.substring(0, servletContextPath.length() - 1);
- }
-
- File publicationDirectory = new File(servletContextPath + File.separator
- + Publication.PUBLICATION_PREFIX + File.separator + id);
-
- boolean exists = true;
- exists = exists && publicationDirectory.isDirectory();
- exists = exists && new File(publicationDirectory, Publication.CONFIGURATION_FILE).exists();
-
- return exists;
- }
-
- /**
* Creates a publication using a source resolver and a request.
* @param resolver The source resolver.
* @param request The request.
@@ -282,10 +258,8 @@
for (int i = 0; i < publicationDirectories.length; i++) {
String publicationId = publicationDirectories[i].getName();
- if (existsPublication(publicationId, servletContextPath)) {
- Publication publication = getPublication(publicationId, servletContextPath);
- publications.add(publication);
- }
+ Publication publication = getPublication(publicationId, servletContextPath);
+ publications.add(publication);
}
} catch (Exception e) {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/PublicationImpl.java Thu Mar 17 01:16:44 2005
@@ -58,6 +58,57 @@
private boolean isConfigLoaded = false;
/**
+ * <code>CONFIGURATION_FILE</code> The publication configuration file
+ */
+ public static final String CONFIGURATION_FILE = CONFIGURATION_PATH + File.separator
+ + "publication.xconf";
+
+ /**
+ * <code>ELEMENT_PATH_MAPPER</code> The path mapper element
+ */
+ String ELEMENT_PATH_MAPPER = "path-mapper";
+ /**
+ * <code>ELEMENT_DOCUMENT_BUILDER</code> The document buider element
+ */
+ String ELEMENT_DOCUMENT_BUILDER = "document-builder";
+ /**
+ * <code>ELEMENT_SITE_STRUCTURE</code> The site structure element
+ */
+ String ELEMENT_SITE_STRUCTURE = "site-structure";
+ /**
+ * <code>ATTRIBUTE_TYPE</code> The type attribute
+ */
+ String ATTRIBUTE_TYPE = "type";
+ /**
+ * <code>ATTRIBUTE_SRC</code> The src attribute
+ */
+ String ATTRIBUTE_SRC = "type";
+ /**
+ * <code>LANGUAGES</code> The languages
+ */
+ String LANGUAGES = "languages";
+ /**
+ * <code>LANGUAGE</code> The language
+ */
+ String LANGUAGE = "language";
+ /**
+ * <code>DEFAULT_LANGUAGE_ATTR</code> The default language attribute
+ */
+ String DEFAULT_LANGUAGE_ATTR = "default";
+ /**
+ * <code>BREADCRUMB_PREFIX</code> The breadcrumb prefix
+ */
+ String BREADCRUMB_PREFIX = "breadcrumb-prefix";
+ /**
+ * <code>SSL_PREFIX</code> The SSL prefix
+ */
+ String SSL_PREFIX = "ssl-prefix";
+ /**
+ * <code>LIVE_MOUNT_POINT</code> The live mount point
+ */
+ String LIVE_MOUNT_POINT = "live-mount-point";
+
+ /**
* Creates a new instance of Publication
* @param _id the publication id
* @param servletContextPath the servlet context of this publication
@@ -76,12 +127,18 @@
if (isConfigLoaded) {
return;
}
-
+
if (getLogger().isDebugEnabled()) {
getLogger().debug("Loading configuration for publication [" + getId() + "]");
}
- File configFile = new File(getDirectory(), CONFIGURATION_FILE);
+ File configFile = getConfigurationFile();
+
+ if (!configFile.exists()) {
+ throw new RuntimeException("The configuration file [" + configFile
+ + "] does not exist!");
+ }
+
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
Configuration config;
@@ -160,6 +217,14 @@
}
/**
+ * @return The configuration file (publication.xconf).
+ */
+ protected File getConfigurationFile() {
+ File configFile = new File(getDirectory(), CONFIGURATION_FILE);
+ return configFile;
+ }
+
+ /**
* Returns the publication ID.
* @return A string value.
*/
@@ -360,5 +425,12 @@
throw new SiteException(e);
}
return manager;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.publication.Publication#exists()
+ */
+ public boolean exists() {
+ return getConfigurationFile().exists();
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/ExistingUsecaseResolver.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/ExistingUsecaseResolver.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/ExistingUsecaseResolver.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/ExistingUsecaseResolver.java Thu Mar 17 01:16:44 2005
@@ -21,6 +21,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationImpl;
/**
* Publication visitor which returns the first publication implementing a certain usecase.
@@ -50,7 +51,7 @@
public void visit(Publication _publication) {
if (this.publication == null) {
- File configFile = new File(_publication.getDirectory(), Publication.CONFIGURATION_FILE);
+ File configFile = new File(_publication.getDirectory(), PublicationImpl.CONFIGURATION_FILE);
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
try {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/templating/PublicationTemplateManagerImpl.java Thu Mar 17 01:16:44 2005
@@ -32,6 +32,7 @@
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.PublicationImpl;
/**
* Manager for publication templates.
@@ -63,7 +64,7 @@
public void setup(Publication _publication) throws ConfigurationException {
this.publication = _publication;
- File configFile = new File(_publication.getDirectory(), Publication.CONFIGURATION_FILE);
+ File configFile = new File(_publication.getDirectory(), PublicationImpl.CONFIGURATION_FILE);
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
try {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/usecases/CreatePublicationFromTemplate.java Thu Mar 17 01:16:44 2005
@@ -89,24 +89,10 @@
if (publicationId.trim().equals("")) {
addErrorMessage("Please enter a publication ID!");
} else {
-
- SourceResolver resolver = null;
- Source source = null;
- try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- Source context = resolver.resolveURI("context://");
- String contextPath = SourceUtil.getFile(context).getAbsolutePath();
-
- if (PublicationFactory.existsPublication(publicationId, contextPath)) {
- addErrorMessage("A publication with this ID already exists.");
- }
- } finally {
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- this.manager.release(resolver);
- }
+ PublicationFactory factory = PublicationFactory.getInstance(getLogger());
+ Publication publication = factory.getPublication(this.manager, publicationId);
+ if (publication.exists()) {
+ addErrorMessage("A publication with this ID already exists.");
}
}
}
@@ -141,25 +127,15 @@
}
- protected static final String[] sourcesToCopy = {
- "publication.xml",
- "config/publication.xconf",
- "config/ac/passwd/visit.rml",
- "config/ac/passwd/reviewer.gml",
- "config/ac/passwd/review.rml",
- "config/ac/passwd/localhost.ipml",
- "config/ac/passwd/lenya.iml",
- "config/ac/passwd/ldap.properties.sample",
- "config/ac/passwd/editor.gml",
- "config/ac/passwd/edit.rml",
- "config/ac/passwd/alice.iml",
- "config/ac/passwd/admin.rml",
- "config/ac/passwd/admin.gml",
- "config/ac/ac.xconf",
- "config/doctypes/doctypes.xconf",
- "config/workflow/workflow.xml",
- "content/authoring/sitetree.xml",
- "content/authoring/index/index_en.xml" };
+ protected static final String[] sourcesToCopy = { "publication.xml",
+ "config/publication.xconf", "config/ac/passwd/visit.rml",
+ "config/ac/passwd/reviewer.gml", "config/ac/passwd/review.rml",
+ "config/ac/passwd/localhost.ipml", "config/ac/passwd/lenya.iml",
+ "config/ac/passwd/ldap.properties.sample", "config/ac/passwd/editor.gml",
+ "config/ac/passwd/edit.rml", "config/ac/passwd/alice.iml",
+ "config/ac/passwd/admin.rml", "config/ac/passwd/admin.gml", "config/ac/ac.xconf",
+ "config/doctypes/doctypes.xconf", "config/workflow/workflow.xml",
+ "content/authoring/sitetree.xml", "content/authoring/index/index_en.xml" };
/**
* Creates a publication from a template.
@@ -233,7 +209,7 @@
}
}
-
+
protected void copySource(Publication template, String publicationId, SourceResolver resolver,
String publicationsUri, String source) throws MalformedURLException, IOException {
Source templateSource = null;
Modified: lenya/trunk/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java Thu Mar 17 01:16:44 2005
@@ -407,8 +407,14 @@
for (int i = 0; i < publicationDirectories.length; i++) {
File directory = publicationDirectories[i];
String publicationId = directory.getName();
- if (PublicationFactory.existsPublication(publicationId, getServletContextDirectory()
- .getAbsolutePath())) {
+ PublicationFactory factory = PublicationFactory.getInstance(new ConsoleLogger());
+ Publication publication;
+ try {
+ publication = factory.getPublication(publicationId, getServletContextDirectory());
+ } catch (PublicationException e) {
+ throw new SchedulerException(e);
+ }
+ if (publication.exists()) {
getScheduler().restoreJobs(publicationId);
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java?view=diff&r1=157922&r2=157923
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/usecase/UsecaseResolverImpl.java Thu Mar 17 01:16:44 2005
@@ -27,9 +27,6 @@
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.environment.Request;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.excalibur.source.SourceUtil;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
import org.apache.lenya.cms.publication.URLInformation;
@@ -140,32 +137,20 @@
* @return A publication.
*/
protected Publication getPublication(String webappUrl) {
-
- SourceResolver resolver = null;
- Source source = null;
Publication publication = null;
try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = resolver.resolveURI("context://");
- String contextPath = SourceUtil.getFile(source).getAbsolutePath();
-
URLInformation info = new URLInformation(webappUrl);
String publicationId = info.getPublicationId();
- if (publicationId != null
- && PublicationFactory.existsPublication(publicationId, contextPath)) {
+ if (publicationId != null) {
PublicationFactory factory = PublicationFactory.getInstance(getLogger());
- publication = factory.getPublication(webappUrl, SourceUtil.getFile(source));
+ Publication pub = factory.getPublication(this.manager, webappUrl);
+ if (pub.exists()) {
+ publication = pub;
+ }
}
} catch (Exception e) {
throw new RuntimeException(e);
- } finally {
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- this.manager.release(resolver);
- }
}
return publication;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org