Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/PublicationAccessControllerResolver.java Tue Sep 9 17:30:20 2008
@@ -16,7 +16,6 @@
*/
/* $Id$ */
package org.apache.lenya.cms.ac;
-
import java.io.File;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
@@ -29,139 +28,128 @@
import org.apache.lenya.ac.AccessController;
import org.apache.lenya.ac.impl.AbstractAccessControllerResolver;
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.URLInformation;
-
+import org.apache.lenya.util.Globals;
/**
- * Resolves the access controller according to the <code>ac.xconf</code> file
- * of a publication.
+ * Resolves the access controller according to the <code>ac.xconf</code> file of a publication.
*/
public class PublicationAccessControllerResolver extends AbstractAccessControllerResolver implements Initializable {
- protected static final String CONFIGURATION_FILE = "config/ac/ac.xconf".replace('/', File.separatorChar);
- protected static final String TYPE_ATTRIBUTE = "type";
- /**
- * This implementation uses the publication ID in combination with the
- * context path as cache key.
- *
- * @see org.apache.lenya.ac.impl.AbstractAccessControllerResolver#generateCacheKey(java.lang.String,
- * org.apache.excalibur.source.SourceResolver)
- */
- protected Object generateCacheKey(String webappUrl, SourceResolver resolver) throws AccessControlException {
- URLInformation info = new URLInformation(webappUrl);
- String publicationId = info.getPublicationId();
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Using first URL step (might be publication ID) as cache key: [" + publicationId + "]");
- }
- return super.generateCacheKey(publicationId, resolver);
- }
- /**
- * @see org.apache.lenya.ac.impl.AbstractAccessControllerResolver#doResolveAccessController(java.lang.String)
- */
- public AccessController doResolveAccessController(String webappUrl) throws AccessControlException {
- getLogger().debug("Resolving controller for URL [" + webappUrl + "]");
- AccessController controller = null;
- Publication publication = getPublication(webappUrl);
- if (publication != null) {
- String publicationUrl = webappUrl.substring(("/" + publication.getId()).length());
- controller = resolveAccessController(publication, publicationUrl);
- }
- return controller;
- }
- /**
- * Returns the publication for the webapp URL or null if the URL is not
- * included in a publication.
- *
- * @param webappUrl
- * The webapp URL.
- * @return A publication.
- * @throws AccessControlException
- * when something went wrong.
- */
- protected Publication getPublication(String webappUrl) throws AccessControlException {
- Publication publication = null;
- // assert webappUrl.startsWith("/");
- // remove leading slash
- String url = webappUrl.substring(1);
- if (url.length() > 0) {
- URLInformation info = new URLInformation(webappUrl);
- String publicationId = info.getPublicationId();
- File contextDir = getContext();
- if (PublicationFactory.existsPublication(publicationId, contextDir.getAbsolutePath())) {
- getLogger().debug("Publication [" + publicationId + "] exists.");
- try {
- publication = PublicationFactory.getPublication(publicationId, contextDir.getAbsolutePath());
- } catch (PublicationException e) {
- throw new AccessControlException(e);
- }
- } else {
- getLogger().debug("Publication [" + publicationId + "] does not exist.");
+ protected static final String CONFIGURATION_FILE = "config/ac/ac.xconf".replace('/', File.separatorChar);
+ protected static final String TYPE_ATTRIBUTE = "type";
+ /**
+ * This implementation uses the publication ID in combination with the context path as cache key.
+ *
+ * @see org.apache.lenya.ac.impl.AbstractAccessControllerResolver#generateCacheKey(java.lang.String, org.apache.excalibur.source.SourceResolver)
+ */
+ protected Object generateCacheKey(String webappUrl, SourceResolver resolver) throws AccessControlException {
+ URLInformation info = new URLInformation(webappUrl);
+ String publicationId = info.getPublicationId();
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Using first URL step (might be publication ID) as cache key: [" + publicationId + "]");
+ }
+ return super.generateCacheKey(publicationId, resolver);
+ }
+ /**
+ * @see org.apache.lenya.ac.impl.AbstractAccessControllerResolver#doResolveAccessController(java.lang.String)
+ */
+ public AccessController doResolveAccessController(String webappUrl) throws AccessControlException {
+ getLogger().debug("Resolving controller for URL [" + webappUrl + "]");
+ AccessController controller = null;
+ Publication publication = getPublication(webappUrl);
+ if(publication != null){
+ String publicationUrl = webappUrl.substring(("/" + publication.getId()).length());
+ controller = resolveAccessController(publication, publicationUrl);
+ }
+ return controller;
+ }
+ /**
+ * Returns the publication for the webapp URL or null if the URL is not included in a publication.
+ *
+ * @param webappUrl
+ * The webapp URL.
+ * @return A publication.
+ * @throws AccessControlException
+ * when something went wrong.
+ */
+ protected Publication getPublication(String webappUrl) throws AccessControlException {
+ Publication publication = null;
+ // assert webappUrl.startsWith("/");
+ // remove leading slash
+ String url = webappUrl.substring(1);
+ if(url.length() > 0){
+ URLInformation info = new URLInformation(webappUrl);
+ String publicationId = info.getPublicationId();
+ if(Globals.existsPublication(publicationId)){
+ getLogger().debug("Publication [" + publicationId + "] exists.");
+ publication = Globals.getPublication(publicationId);
+ }else{
+ getLogger().debug("Publication [" + publicationId + "] does not exist.");
+ }
+ }
+ return publication;
+ }
+ /**
+ * Returns the servlet context.
+ *
+ * @return A file.
+ * @throws AccessControlException
+ * when something went wrong.
+ */
+ protected File getContext() throws AccessControlException {
+ return context;
+ }
+ private File context;
+ /**
+ * Resolves an access controller for a certain URL within a publication.
+ *
+ * @param publication
+ * The publication.
+ * @param url
+ * The url within the publication.
+ * @return An access controller.
+ * @throws AccessControlException
+ * when something went wrong.
+ */
+ public AccessController resolveAccessController(Publication publication, String url) throws AccessControlException {
+ // assert publication != null;
+ AccessController accessController = null;
+ File configurationFile = new File(publication.getDirectory(), CONFIGURATION_FILE);
+ if(configurationFile.isFile()){
+ try{
+ Configuration configuration = new DefaultConfigurationBuilder().buildFromFile(configurationFile);
+ String type = configuration.getAttribute(TYPE_ATTRIBUTE);
+ accessController = (AccessController) getManager().lookup(AccessController.ROLE + "/" + type);
+ if(accessController instanceof Configurable){
+ ((Configurable) accessController).configure(configuration);
}
- }
- return publication;
- }
- /**
- * Returns the servlet context.
- *
- * @return A file.
- * @throws AccessControlException
- * when something went wrong.
- */
- protected File getContext() throws AccessControlException {
- return context;
- }
- private File context;
- /**
- * Resolves an access controller for a certain URL within a publication.
- *
- * @param publication
- * The publication.
- * @param url
- * The url within the publication.
- * @return An access controller.
- * @throws AccessControlException
- * when something went wrong.
- */
- public AccessController resolveAccessController(Publication publication, String url) throws AccessControlException {
- // assert publication != null;
- AccessController accessController = null;
- File configurationFile = new File(publication.getDirectory(), CONFIGURATION_FILE);
- if (configurationFile.isFile()) {
- try {
- Configuration configuration = new DefaultConfigurationBuilder().buildFromFile(configurationFile);
- String type = configuration.getAttribute(TYPE_ATTRIBUTE);
- accessController = (AccessController) getManager().lookup(AccessController.ROLE + "/" + type);
- if (accessController instanceof Configurable) {
- ((Configurable) accessController).configure(configuration);
- }
- } catch (Exception e) {
- throw new AccessControlException(e);
+ }catch(Exception e){
+ throw new AccessControlException(e);
+ }
+ }
+ return accessController;
+ }
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+ SourceResolver resolver = null;
+ Source contextSource = null;
+ File contextDir;
+ try{
+ resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
+ contextSource = resolver.resolveURI("context:///");
+ contextDir = SourceUtil.getFile(contextSource);
+ if(contextDir == null || !contextDir.isDirectory()){
+ throw new AccessControlException("The servlet context is not a directory!");
+ }
+ }finally{
+ if(resolver != null){
+ if(contextSource != null){
+ resolver.release(contextSource);
}
- }
- return accessController;
- }
- /**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize() throws Exception {
- SourceResolver resolver = null;
- Source contextSource = null;
- File contextDir;
- try {
- resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
- contextSource = resolver.resolveURI("context:///");
- contextDir = SourceUtil.getFile(contextSource);
- if (contextDir == null || !contextDir.isDirectory()) {
- throw new AccessControlException("The servlet context is not a directory!");
- }
- } finally {
- if (resolver != null) {
- if (contextSource != null) {
- resolver.release(contextSource);
- }
- getManager().release(resolver);
- }
- }
- this.context = contextDir;
- }
+ getManager().release(resolver);
+ }
+ }
+ this.context = contextDir;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/usecase/UsecaseAuthorizer.java Tue Sep 9 17:30:20 2008
@@ -14,9 +14,7 @@
* limitations under the License.
*
*/
-
package org.apache.lenya.cms.ac.usecase;
-
import java.util.Arrays;
import java.util.List;
import org.apache.avalon.framework.activity.Disposable;
@@ -36,181 +34,160 @@
import org.apache.lenya.ac.cache.SourceCache;
import org.apache.lenya.ac.impl.PolicyAuthorizer;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
-
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.util.Globals;
/**
* Authorizer for usecases.
+ *
* @version $Id$
*/
-public class UsecaseAuthorizer
- extends AbstractLogEnabled
- implements Authorizer, Serviceable, Disposable, Parameterizable {
-
- public static final String TYPE = "usecase";
- public static final String USECASE_PARAMETER = "lenya.usecase";
-
- private SourceCache cache;
- private String configurationUri;
-
- /**
- * Returns the configuration source cache.
- *
- * @return A source cache.
- */
- public SourceCache getCache() {
- return cache;
- }
-
- /**
- * Returns the source URI of the usecase role configuration file for a certain publication.
- *
- * @param publication The publication.
- * @return A string representing a URI.
- */
- protected String getConfigurationURI(Publication publication) {
- return "context:///"
- + Publication.PUBLICATION_PREFIX_URI
- + "/"
- + publication.getId()
- + CONFIGURATION_FILE;
- }
-
- /**
- * @see org.apache.lenya.ac.Authorizer#authorize(org.apache.cocoon.environment.Request)
- */
- public boolean authorize(Request request) throws AccessControlException {
-
- String usecase = request.getParameter(USECASE_PARAMETER);
- boolean authorized = true;
-
- SourceResolver resolver = null;
- try {
- resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
- if (usecase != null) {
-
- String configurationUri;
- if (getConfigurationURI() != null) {
- configurationUri = getConfigurationURI();
- } else {
- Publication publication = PublicationFactory.getPublication(resolver, request);
- configurationUri = getConfigurationURI(publication);
- }
-
- Role[] roles = PolicyAuthorizer.getRoles(request);
- authorized = authorizeUsecase(usecase, roles, configurationUri);
- } else {
- getLogger().debug("No usecase to authorize. Granting access.");
+public class UsecaseAuthorizer extends AbstractLogEnabled implements Authorizer, Serviceable, Disposable, Parameterizable {
+ public static final String TYPE = "usecase";
+ public static final String USECASE_PARAMETER = "lenya.usecase";
+ private SourceCache cache;
+ private String configurationUri;
+ /**
+ * Returns the configuration source cache.
+ *
+ * @return A source cache.
+ */
+ public SourceCache getCache() {
+ return cache;
+ }
+ /**
+ * Returns the source URI of the usecase role configuration file for a certain publication.
+ *
+ * @param publication
+ * The publication.
+ * @return A string representing a URI.
+ */
+ protected String getConfigurationURI(Publication publication) {
+ return "context:///" + Publication.PUBLICATION_PREFIX_URI + "/" + publication.getId() + CONFIGURATION_FILE;
+ }
+ /**
+ * @see org.apache.lenya.ac.Authorizer#authorize(org.apache.cocoon.environment.Request)
+ */
+ public boolean authorize(Request request) throws AccessControlException {
+ String usecase = request.getParameter(USECASE_PARAMETER);
+ boolean authorized = true;
+ SourceResolver resolver = null;
+ try{
+ resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+ if(usecase != null){
+ String configurationUri;
+ if(getConfigurationURI() != null){
+ configurationUri = getConfigurationURI();
+ }else{
+ Publication publication = Globals.getPublication();
+ if(null == publication){
+ throw new PublicationException("UsecaseAuthorizer.authorize: No Publication.");
+ }
+ configurationUri = getConfigurationURI(publication);
}
- } catch (Exception e) {
- throw new AccessControlException(e);
- } finally {
- if (resolver != null) {
- manager.release(resolver);
- }
- }
-
- return authorized;
- }
-
- /**
- * Authorizes a usecase.
- *
- * @param usecase The usecase ID.
- * @param roles The roles of the current identity.
- * @param configurationUri The URI to retrieve the policy configuration from.
- * @return A boolean value.
- * @throws AccessControlException when something went wrong.
- */
- public boolean authorizeUsecase(String usecase, Role[] roles, String configurationUri)
- throws AccessControlException {
- getLogger().debug("Authorizing usecase [" + usecase + "]");
- boolean authorized = true;
-
- UsecaseRolesBuilder builder = new UsecaseRolesBuilder();
- UsecaseRoles usecaseRoles;
- try {
- usecaseRoles = (UsecaseRoles) getCache().get(configurationUri, builder);
- } catch (CachingException e) {
- throw new AccessControlException(e);
- }
-
- if (usecaseRoles == null) {
- throw new AccessControlException("Usecase policies configuration not found at [" + configurationUri + "]");
- }
-
- if (usecaseRoles.hasRoles(usecase)) {
-
- getLogger().debug("Roles for usecase found.");
-
- List usecaseRoleIds = Arrays.asList(usecaseRoles.getRoles(usecase));
-
- int i = 0;
- authorized = false;
- while (!authorized && i < roles.length) {
- authorized = usecaseRoleIds.contains(roles[i].getId());
- getLogger().debug(
- "Authorization for role [" + roles[i].getId() + "] is [" + authorized + "]");
- i++;
- }
- } else {
- getLogger().debug("No roles for usecase found. Granting access.");
- }
- return authorized;
- }
-
- private ServiceManager manager;
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- getLogger().debug("Servicing [" + getClass().getName() + "]");
- this.manager = manager;
- this.cache = (SourceCache) manager.lookup(SourceCache.ROLE);
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if (getCache() != null) {
- manager.release(getCache());
- }
- }
-
- public static final String CONFIGURATION_FILE = "/config/ac/usecase-policies.xml";
- public static final String PARAMETER_CONFIGURATION = "configuration";
-
- /**
- * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
- */
- public void parameterize(Parameters parameters) throws ParameterException {
- if (parameters.isParameter(PARAMETER_CONFIGURATION)) {
- this.configurationUri = parameters.getParameter(PARAMETER_CONFIGURATION);
- }
- }
-
- /**
- * Returns the configuration URL.
- *
- * @return The configuration URL.
- */
- public String getConfigurationURI() {
- return configurationUri;
- }
-
- /**
- * Authorizes a usecase.
- *
- * @param usecase The usecase to authorize.
- * @param roles The roles of the identity.
- * @param publication The publication.
- * @return A boolean value.
- * @throws AccessControlException when something went wrong.
- */
- public boolean authorizeUsecase(String usecase, Role[] roles, Publication publication)
- throws AccessControlException {
- return authorizeUsecase(usecase, roles, getConfigurationURI(publication));
- }
-
+ Role[] roles = PolicyAuthorizer.getRoles(request);
+ authorized = authorizeUsecase(usecase, roles, configurationUri);
+ }else{
+ getLogger().debug("No usecase to authorize. Granting access.");
+ }
+ }catch(Exception e){
+ throw new AccessControlException(e);
+ }finally{
+ if(resolver != null){
+ manager.release(resolver);
+ }
+ }
+ return authorized;
+ }
+ /**
+ * Authorizes a usecase.
+ *
+ * @param usecase
+ * The usecase ID.
+ * @param roles
+ * The roles of the current identity.
+ * @param configurationUri
+ * The URI to retrieve the policy configuration from.
+ * @return A boolean value.
+ * @throws AccessControlException
+ * when something went wrong.
+ */
+ public boolean authorizeUsecase(String usecase, Role[] roles, String configurationUri) throws AccessControlException {
+ getLogger().debug("Authorizing usecase [" + usecase + "]");
+ boolean authorized = true;
+ UsecaseRolesBuilder builder = new UsecaseRolesBuilder();
+ UsecaseRoles usecaseRoles;
+ try{
+ usecaseRoles = (UsecaseRoles) getCache().get(configurationUri, builder);
+ }catch(CachingException e){
+ throw new AccessControlException(e);
+ }
+ if(usecaseRoles == null){
+ throw new AccessControlException("Usecase policies configuration not found at [" + configurationUri + "]");
+ }
+ if(usecaseRoles.hasRoles(usecase)){
+ getLogger().debug("Roles for usecase found.");
+ List usecaseRoleIds = Arrays.asList(usecaseRoles.getRoles(usecase));
+ int i = 0;
+ authorized = false;
+ while(!authorized && i < roles.length){
+ authorized = usecaseRoleIds.contains(roles[i].getId());
+ getLogger().debug("Authorization for role [" + roles[i].getId() + "] is [" + authorized + "]");
+ i++;
+ }
+ }else{
+ getLogger().debug("No roles for usecase found. Granting access.");
+ }
+ return authorized;
+ }
+ private ServiceManager manager;
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ getLogger().debug("Servicing [" + getClass().getName() + "]");
+ this.manager = manager;
+ this.cache = (SourceCache) manager.lookup(SourceCache.ROLE);
+ }
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if(getCache() != null){
+ manager.release(getCache());
+ }
+ }
+ public static final String CONFIGURATION_FILE = "/config/ac/usecase-policies.xml";
+ public static final String PARAMETER_CONFIGURATION = "configuration";
+ /**
+ * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void parameterize(Parameters parameters) throws ParameterException {
+ if(parameters.isParameter(PARAMETER_CONFIGURATION)){
+ this.configurationUri = parameters.getParameter(PARAMETER_CONFIGURATION);
+ }
+ }
+ /**
+ * Returns the configuration URL.
+ *
+ * @return The configuration URL.
+ */
+ public String getConfigurationURI() {
+ return configurationUri;
+ }
+ /**
+ * Authorizes a usecase.
+ *
+ * @param usecase
+ * The usecase to authorize.
+ * @param roles
+ * The roles of the identity.
+ * @param publication
+ * The publication.
+ * @return A boolean value.
+ * @throws AccessControlException
+ * when something went wrong.
+ */
+ public boolean authorizeUsecase(String usecase, Role[] roles, Publication publication) throws AccessControlException {
+ return authorizeUsecase(usecase, roles, getConfigurationURI(publication));
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ac/workflow/WorkflowAuthorizer.java Tue Sep 9 17:30:20 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.ac.workflow;
-
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
@@ -31,97 +28,76 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.workflow.WorkflowFactory;
+import org.apache.lenya.util.Globals;
import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
-
/**
- * If the client requested invoking a workflow event, this authorizer checks if the current
- * document state and identity roles allow this transition.
+ * If the client requested invoking a workflow event, this authorizer checks if the current document state and identity roles allow this transition.
*/
public class WorkflowAuthorizer extends AbstractLogEnabled implements Authorizer, Serviceable {
-
- protected static final String EVENT_PARAMETER = "lenya.event";
-
- /**
- * @see org.apache.lenya.ac.Authorizer#authorize(org.apache.cocoon.environment.Request)
- */
- public boolean authorize(Request request) throws AccessControlException {
-
- boolean authorized = true;
-
- String requestUri = request.getRequestURI();
- String context = request.getContextPath();
-
- if (context == null) {
- context = "";
- }
-
- String url = requestUri.substring(context.length());
-
- String event = request.getParameter(EVENT_PARAMETER);
- SourceResolver resolver = null;
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Authorizing workflow for event [" + event + "]");
- }
-
- if (event != null) {
-
- try {
- resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
- Publication publication = PublicationFactory.getPublication(resolver, request);
-
- DocumentBuilder builder = publication.getDocumentBuilder();
- if (builder.isDocument(publication, url)) {
-
- Document document = builder.buildDocument(publication, url);
- WorkflowFactory factory = WorkflowFactory.newInstance();
-
- if (factory.hasWorkflow(document)) {
- SynchronizedWorkflowInstances instance =
- factory.buildSynchronizedInstance(document);
-
- authorized = false;
-
- Situation situation = WorkflowHelper.buildSituation(request);
- Event[] events = instance.getExecutableEvents(situation);
- int i = 0;
-
- while (!authorized && (i < events.length)) {
- if (events[i].getName().equals(event)) {
- authorized = true;
- }
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Event [" + events[i] + "] is executable.");
- }
-
- i++;
- }
- }
- }
-
- } catch (Exception e) {
- throw new AccessControlException(e);
- } finally {
- if (resolver != null) {
- manager.release(resolver);
- }
- }
- }
-
- return authorized;
- }
-
- private ServiceManager manager;
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
-
+ protected static final String EVENT_PARAMETER = "lenya.event";
+ /**
+ * @see org.apache.lenya.ac.Authorizer#authorize(org.apache.cocoon.environment.Request)
+ */
+ public boolean authorize(Request request) throws AccessControlException {
+ boolean authorized = true;
+ String requestUri = request.getRequestURI();
+ String context = request.getContextPath();
+ if(context == null){
+ context = "";
+ }
+ String url = requestUri.substring(context.length());
+ String event = request.getParameter(EVENT_PARAMETER);
+ SourceResolver resolver = null;
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Authorizing workflow for event [" + event + "]");
+ }
+ if(event != null){
+ try{
+ resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+ Publication publication = Globals.getPublication();
+ if(null == publication){
+ throw new PublicationException("WorkflowAuthorizer.authorize: No Publication.");
+ }
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ if(builder.isDocument(publication, url)){
+ Document document = builder.buildDocument(publication, url);
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+ if(factory.hasWorkflow(document)){
+ SynchronizedWorkflowInstances instance = factory.buildSynchronizedInstance(document);
+ authorized = false;
+ Situation situation = WorkflowHelper.buildSituation(request);
+ Event[] events = instance.getExecutableEvents(situation);
+ int i = 0;
+ while(!authorized && (i < events.length)){
+ if(events[i].getName().equals(event)){
+ authorized = true;
+ }
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(" Event [" + events[i] + "] is executable.");
+ }
+ i++;
+ }
+ }
+ }
+ }catch(Exception e){
+ throw new AccessControlException(e);
+ }finally{
+ if(resolver != null){
+ manager.release(resolver);
+ }
+ }
+ }
+ return authorized;
+ }
+ private ServiceManager manager;
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/PublicationTask.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/PublicationTask.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/PublicationTask.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/PublicationTask.java Tue Sep 9 17:30:20 2008
@@ -16,80 +16,78 @@
*/
/* $Id$ */
package org.apache.lenya.cms.ant;
-
import java.io.File;
-import java.io.IOException;
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.task.AntTask;
+import org.apache.lenya.util.Globals;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
-
/**
- * Abstract base class for publication-dependent Ant tasks. It requires some
- * project parameters that are set by the AntTask.
+ * Abstract base class for publication-dependent Ant tasks. It requires some project parameters that are set by the AntTask.
*/
public abstract class PublicationTask extends Task {
- /** Creates a new instance of PublicationTask */
- public PublicationTask() {
- }
- /**
- * Returns the publication directory.
- *
- * @return a the path to the publication directory as a <code>File</code>
- */
- protected File getPublicationDirectory() {
- return new File(getProject().getProperty(AntTask.PUBLICATION_DIRECTORY));
- }
- /**
- * Return the context prefix.
- *
- * @return the context-prefix
- */
- protected String getContextPrefix() {
- return getProject().getProperty(AntTask.CONTEXT_PREFIX);
- }
- /**
- * Returns the publication ID.
- *
- * @return the publication-id
- */
- protected String getPublicationId() {
- return getProject().getProperty(AntTask.PUBLICATION_ID);
- }
- /**
- * Returns the servlet context (e.g., <code>tomcat/webapp/lenya</code>)
- *
- * @return the servlet-context
- */
- protected File getServletContext() {
- return new File(getProject().getProperty(AntTask.SERVLET_CONTEXT_PATH));
- }
- /**
- * Get the publication
- *
- * @return the publication
- *
- * @throws BuildException
- * if the publication could not be found
- */
- protected Publication getPublication() throws BuildException {
- try {
- return PublicationFactory.getPublication(getPublicationId(), getServletContext().getCanonicalPath());
- } catch (IOException e) {
- throw new BuildException(e);
- } catch (PublicationException e) {
- throw new BuildException(e);
- }
- }
- /**
- * Utility method for assertion that a string is != null and != ""
- *
- * @param string
- * the string to check
- */
- protected void assertString(String string) {
- // assert(string != null) && !string.equals("");
- }
+ /** Creates a new instance of PublicationTask */
+ public PublicationTask() {
+ }
+ /**
+ * Returns the publication directory.
+ *
+ * @return a the path to the publication directory as a <code>File</code>
+ */
+ protected File getPublicationDirectory() {
+ return new File(getProject().getProperty(AntTask.PUBLICATION_DIRECTORY));
+ }
+ /**
+ * Return the context prefix.
+ *
+ * @return the context-prefix
+ */
+ protected String getContextPrefix() {
+ return getProject().getProperty(AntTask.CONTEXT_PREFIX);
+ }
+ /**
+ * Returns the publication ID.
+ *
+ * @return the publication-id
+ */
+ protected String getPublicationId() {
+ return getProject().getProperty(AntTask.PUBLICATION_ID);
+ }
+ /**
+ * Returns the servlet context (e.g., <code>tomcat/webapp/lenya</code>)
+ *
+ * @return the servlet-context
+ */
+ protected File getServletContext() {
+ return new File(getProject().getProperty(AntTask.SERVLET_CONTEXT_PATH));
+ }
+ /**
+ * Get the publication
+ *
+ * @return the publication
+ *
+ * @throws BuildException
+ * if the publication could not be found
+ */
+ protected Publication getPublication() throws BuildException {
+ try{
+ Publication publication = Globals.getPublication(getPublicationId());
+ if(null == publication){
+ throw new PublicationException("UsecaseAuthorizer.authorize: No Publication.");
+ }
+ return publication;
+ }catch(PublicationException e){
+ throw new BuildException(e);
+ }
+ }
+ /**
+ * Utility method for assertion that a string is != null and != ""
+ *
+ * @param string
+ * the string to check
+ */
+ protected void assertString(String string) {
+ // assert(string != null) && !string.equals("");
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java Tue Sep 9 17:30:20 2008
@@ -27,7 +27,6 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.acting.AbstractComplementaryConfigurableAction;
-import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
@@ -35,8 +34,9 @@
import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
import org.apache.lenya.cms.publication.Label;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.publication.SiteTree;
+import org.apache.lenya.util.Globals;
import org.apache.log4j.Logger;
import org.dom4j.Attribute;
import org.dom4j.Document;
@@ -82,9 +82,12 @@
* DOCUMENT ME!
*/
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
- Publication publication = PublicationFactory.getPublication(objectModel);
+ Publication publication = Globals.getPublication();
+ if(null == publication){
+ throw new PublicationException("DefaultCreatorAction.act: No Publication.");
+ }
// Get request object
- Request request = ObjectModelHelper.getRequest(objectModel);
+ Request request = Globals.getRequest();
if(request == null){
getLogger().error("No request object");
return null;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ParentChildCreatorAction.java Tue Sep 9 17:30:20 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.io.File;
import java.util.Enumeration;
import java.util.HashMap;
@@ -41,330 +38,263 @@
import org.apache.excalibur.source.Source;
import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.util.Globals;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
-
-public class ParentChildCreatorAction extends AbstractComplementaryConfigurableAction
- implements Configurable {
- private String treeAuthoringPath = null;
- private String docsPath = null;
- private String doctypesPath = null;
-
- /**
- * DOCUMENT ME!
- *
- * @param conf DOCUMENT ME!
- *
- * @throws ConfigurationException DOCUMENT ME!
- */
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
-
- treeAuthoringPath = conf.getChild("tree-authoring").getAttribute("href");
- docsPath = conf.getChild("docs").getAttribute("href");
- doctypesPath = conf.getChild("doctypes").getAttribute("href");
- getLogger().debug("CONFIGURATION:\nAUTHORING PATH OF TREE=" + treeAuthoringPath);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param redirector DOCUMENT ME!
- * @param resolver DOCUMENT ME!
- * @param objectModel DOCUMENT ME!
- * @param src DOCUMENT ME!
- * @param parameters DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src,
- Parameters parameters) throws Exception {
- Source input_source = resolver.resolveURI("");
- String sitemapParentPath = input_source.getURI();
- sitemapParentPath = sitemapParentPath.substring(5); // Remove "file:" protocol
-
- getLogger().debug(".act(): PARENT PATH OF SITEMAP: " + sitemapParentPath);
-
- // Get request object
- Request request = ObjectModelHelper.getRequest(objectModel);
-
- if (request == null) {
- getLogger().error("No request object");
-
- return null;
- }
-
- // Get parameters
- String parentid = request.getParameter("parentid");
- if (parentid == null) {
- getLogger().warn("No parentid parameter defined! It might be necessary to specify a parentid request parameter.");
- }
- String childid = request.getParameter("childid");
- if (childid == null) {
- getLogger().error("No childid parameter defined! Please specify childid as request parameter.");
- throw new Exception("No childname defined!");
- }
- String childname = request.getParameter("childname");
- if (childname == null) {
- getLogger().error("No childname defined! Please specify childname as request parameter which is being used as label within a sitetree or topic map.");
- throw new Exception("No childname defined!");
- }
- String childtype = request.getParameter("childtype");
- if (childtype == null) {
- getLogger().error("No childtype defined! Please specify childtype as request parameter with value either \"branch\" or \"leaf\".");
- throw new Exception("No childname defined!");
- }
- short childType;
-
- if (childtype.equals("branch")) {
- childType = ParentChildCreatorInterface.BRANCH_NODE;
- } else if (childtype.equals("leaf")) {
- childType = ParentChildCreatorInterface.LEAF_NODE;
- } else {
- getLogger().error("No such child type: " + childtype);
- return null;
- }
-
- String doctype = request.getParameter("doctype");
- if (doctype == null) {
- getLogger().warn("No doctype defined! Please specify doctype as request parameter, which is being used to resolve the creator within doctypes.xconf. Otherwise the DefaultCreator class is being used (see below)!");
- }
- String language = request.getParameter("language");
-
- if (!validate(parentid, childid, childname, childtype, doctype)) {
- getLogger().error("Exception: Validation of parameters failed");
-
- return null;
- }
-
- // Get session
- Session session = request.getSession(true);
-
- if (session == null) {
- getLogger().error("No session object");
-
- return null;
- }
-
- // Get creator
- ParentChildCreatorInterface creator = null;
- String absoluteDoctypesPath = sitemapParentPath + doctypesPath;
- Document doctypesDoc = new SAXReader().read("file:" + absoluteDoctypesPath +
- "doctypes.xconf");
- Attribute creator_src = (Attribute) doctypesDoc.selectSingleNode("/doctypes/doc[@type='" +
- doctype + "']/creator/@src");
-
- if (creator_src != null) {
- getLogger().info(".act(): Creator found for \"" + doctype + "\": " +
- creator_src.getName() + " " + creator_src.getPath() + " " + creator_src.getValue());
-
- // now get the constructor that accepts the configuration
- Class creatorClass = Class.forName(creator_src.getValue());
- creator = (ParentChildCreatorInterface) creatorClass.newInstance();
- } else {
- getLogger().warn("No creator found for \"" + doctype +
- "\". DefaultBranchCreator will be taken.");
- creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
- }
-
- getLogger().debug(".act(): Creator : " + creator.getClass().getName());
-
- // Init creator
- // "Read" the configuration from the DOM node
- DefaultConfigurationBuilder defaultConfigBuilder = new DefaultConfigurationBuilder();
- Configuration[] docTypeConfigs = defaultConfigBuilder.buildFromFile(absoluteDoctypesPath +
- "doctypes.xconf").getChildren();
-
- Configuration doctypeConf = null;
-
- for (int i = 0; i < docTypeConfigs.length; i++) {
- String typeName = docTypeConfigs[i].getAttribute("type");
-
- if (typeName.equals(doctype)) {
- doctypeConf = docTypeConfigs[i].getChild("creator", false);
- }
- }
-
- creator.init(doctypeConf);
-
- // Transaction should actually be started here!
- String treefilename = sitemapParentPath + treeAuthoringPath;
- getLogger().debug(".act(): Filename of tree: " + treefilename);
-
- if (!new File(treefilename).exists()) {
- getLogger().warn("No sitetree or topic map: " + treefilename);
- } else {
- if (!updateTree(childtype, childType, childid, childname, parentid, doctype, creator, treefilename)) return null;
- }
- // Transaction should actually be finished here!
-
-
- // Create actual document
- // grab all the parameters from session, request params and
- // sitemap params
- HashMap allParameters = new HashMap();
- String[] names = parameters.getNames();
-
- for (int i = 0; i < names.length; i++) {
- String name = names[i];
- String value = null;
-
- try {
- value = parameters.getParameter(name);
- } catch (ParameterException pe) {
- value = null;
- }
-
- allParameters.put(name, value);
- }
-
- Enumeration requestParameters = request.getParameterNames();
-
- while (requestParameters.hasMoreElements()) {
- String requestParameterName = (String) requestParameters.nextElement();
-
- if (allParameters.containsKey(requestParameterName)) {
- // we do not allow name clashes
- throw new ProcessingException("Name clash in request parameter " +
- "and sitemap parameter: " + requestParameterName);
- }
-
- allParameters.put(requestParameterName, request.getParameter(requestParameterName));
- }
-
- Enumeration sessionAttributeNames = session.getAttributeNames();
-
- while (sessionAttributeNames.hasMoreElements()) {
- String sessionAttributeName = (String) sessionAttributeNames.nextElement();
-
- if (allParameters.containsKey(sessionAttributeName)) {
- // we do not allow name clashes
- throw new ProcessingException("Name clash in session attribute " +
- "and request parameter or sitemap parameter: " + sessionAttributeName);
- }
-
- allParameters.put(sessionAttributeName, session.getAttribute(sessionAttributeName));
- }
-
- try {
- Publication publication = PublicationFactory.getPublication(objectModel);
- creator.create(publication, new File(absoluteDoctypesPath + "samples"),
- new File(sitemapParentPath + docsPath + parentid), parentid, childid, childType, childname, language,
- allParameters);
- } catch (Exception e) {
- getLogger().error("Creator threw exception: " + e);
- }
-
- // Redirect to referer
- String parent_uri = (String) session.getAttribute(
- "org.apache.lenya.cms.cocoon.acting.ParentChildCreatorAction.parent_uri");
- getLogger().info(".act(): Child added");
-
- HashMap actionMap = new HashMap();
- actionMap.put("parent_uri", parent_uri);
- session.removeAttribute(
- "org.apache.lenya.cms.cocoon.acting.ParentChildCreatorAction.parent_uri");
-
- return actionMap;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param parentid DOCUMENT ME!
- * @param childid DOCUMENT ME!
- * @param childname DOCUMENT ME!
- * @param childtype DOCUMENT ME!
- * @param doctype DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean validate(String parentid, String childid, String childname, String childtype,
- String doctype) {
- getLogger().debug(".validate(): parentid=" + parentid + " ; childid=" + childid +
- " ; childname=" + childname + " ; childtype=" + childtype + " ; doctype=" + doctype);
-
- if ((childid.indexOf(" ") >= 0) || (childid.length() == 0)) {
- return false;
- }
-
- if (childname.length() == 0) {
- return false;
- }
-
- return true;
- }
-
- /**
- *
- */
- private boolean updateTree(String childtype, short childType, String childid, String childname, String parentid, String doctype, ParentChildCreatorInterface creator, String treefilename) throws Exception {
- Document doc = new SAXReader().read("file:" + treefilename);
-
- // Get parent element
- StringTokenizer st = new StringTokenizer(parentid, "/");
- String xpath_string = "/tree/branch"; // Trunk of tree
-
- while (st.hasMoreTokens()) {
- xpath_string = xpath_string + "/branch[@relURI='" + st.nextToken() + "']";
- }
-
- getLogger().debug("XPATH: " + xpath_string);
-
- XPath xpathSelector = DocumentHelper.createXPath(xpath_string);
- List nodes = xpathSelector.selectNodes(doc);
-
- if (nodes.isEmpty()) {
- getLogger().error(".act(): No nodes: " + xpath_string);
- getLogger().error(".act(): No child added!");
-
- return false;
- }
-
- Element parent_element = (Element) nodes.get(0);
- getLogger().debug("PARENT ELEMENT: " + parent_element.getPath());
-
- // Set child type: branch or leaf
- childType = creator.getChildType(childType);
-
- if (childType == ParentChildCreatorInterface.BRANCH_NODE) {
- childtype = "branch";
- } else {
- childtype = "leaf";
- }
-
- // Check if child already exists
- String newChildXPath = xpath_string + "/" + childtype;
- getLogger().debug("CHECK: " + newChildXPath);
-
- if (doc.selectSingleNode(newChildXPath + "[@relURI='" +
- creator.generateTreeId(childid, childType) + "']") != null) {
- getLogger().error("Exception: XPath exists: " + newChildXPath + "[@relURI='" +
- creator.generateTreeId(childid, childType) + "']");
- getLogger().error("No child added");
-
- return false;
- }
-
- // Add node: branch or leaf
- parent_element.addElement(childtype)
- .addAttribute("relURI", creator.generateTreeId(childid, childType))
- .addAttribute("doctype", doctype).addAttribute("menuName",
- creator.getChildName(childname));
- getLogger().debug("Tree has been modified: " + doc.asXML());
-
- // Write new tree
- java.io.FileWriter fileWriter = new java.io.FileWriter(treefilename);
- doc.write(fileWriter);
- fileWriter.close();
-
- return true;
- }
+public class ParentChildCreatorAction extends AbstractComplementaryConfigurableAction implements Configurable {
+ private String treeAuthoringPath = null;
+ private String docsPath = null;
+ private String doctypesPath = null;
+ /**
+ * DOCUMENT ME!
+ *
+ * @param conf
+ * DOCUMENT ME!
+ *
+ * @throws ConfigurationException
+ * DOCUMENT ME!
+ */
+ public void configure(Configuration conf) throws ConfigurationException {
+ super.configure(conf);
+ treeAuthoringPath = conf.getChild("tree-authoring").getAttribute("href");
+ docsPath = conf.getChild("docs").getAttribute("href");
+ doctypesPath = conf.getChild("doctypes").getAttribute("href");
+ getLogger().debug("CONFIGURATION:\nAUTHORING PATH OF TREE=" + treeAuthoringPath);
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param redirector
+ * DOCUMENT ME!
+ * @param resolver
+ * DOCUMENT ME!
+ * @param objectModel
+ * DOCUMENT ME!
+ * @param src
+ * DOCUMENT ME!
+ * @param parameters
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws Exception
+ * DOCUMENT ME!
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
+ Source input_source = resolver.resolveURI("");
+ String sitemapParentPath = input_source.getURI();
+ sitemapParentPath = sitemapParentPath.substring(5); // Remove "file:" protocol
+ getLogger().debug(".act(): PARENT PATH OF SITEMAP: " + sitemapParentPath);
+ // Get request object
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ if(request == null){
+ getLogger().error("No request object");
+ return null;
+ }
+ // Get parameters
+ String parentid = request.getParameter("parentid");
+ if(parentid == null){
+ getLogger().warn("No parentid parameter defined! It might be necessary to specify a parentid request parameter.");
+ }
+ String childid = request.getParameter("childid");
+ if(childid == null){
+ getLogger().error("No childid parameter defined! Please specify childid as request parameter.");
+ throw new Exception("No childname defined!");
+ }
+ String childname = request.getParameter("childname");
+ if(childname == null){
+ getLogger().error("No childname defined! Please specify childname as request parameter which is being used as label within a sitetree or topic map.");
+ throw new Exception("No childname defined!");
+ }
+ String childtype = request.getParameter("childtype");
+ if(childtype == null){
+ getLogger().error("No childtype defined! Please specify childtype as request parameter with value either \"branch\" or \"leaf\".");
+ throw new Exception("No childname defined!");
+ }
+ short childType;
+ if(childtype.equals("branch")){
+ childType = ParentChildCreatorInterface.BRANCH_NODE;
+ }else if(childtype.equals("leaf")){
+ childType = ParentChildCreatorInterface.LEAF_NODE;
+ }else{
+ getLogger().error("No such child type: " + childtype);
+ return null;
+ }
+ String doctype = request.getParameter("doctype");
+ if(doctype == null){
+ getLogger().warn("No doctype defined! Please specify doctype as request parameter, which is being used to resolve the creator within doctypes.xconf. Otherwise the DefaultCreator class is being used (see below)!");
+ }
+ String language = request.getParameter("language");
+ if(!validate(parentid, childid, childname, childtype, doctype)){
+ getLogger().error("Exception: Validation of parameters failed");
+ return null;
+ }
+ // Get session
+ Session session = request.getSession(true);
+ if(session == null){
+ getLogger().error("No session object");
+ return null;
+ }
+ // Get creator
+ ParentChildCreatorInterface creator = null;
+ String absoluteDoctypesPath = sitemapParentPath + doctypesPath;
+ Document doctypesDoc = new SAXReader().read("file:" + absoluteDoctypesPath + "doctypes.xconf");
+ Attribute creator_src = (Attribute) doctypesDoc.selectSingleNode("/doctypes/doc[@type='" + doctype + "']/creator/@src");
+ if(creator_src != null){
+ getLogger().info(".act(): Creator found for \"" + doctype + "\": " + creator_src.getName() + " " + creator_src.getPath() + " " + creator_src.getValue());
+ // now get the constructor that accepts the configuration
+ Class creatorClass = Class.forName(creator_src.getValue());
+ creator = (ParentChildCreatorInterface) creatorClass.newInstance();
+ }else{
+ getLogger().warn("No creator found for \"" + doctype + "\". DefaultBranchCreator will be taken.");
+ creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
+ }
+ getLogger().debug(".act(): Creator : " + creator.getClass().getName());
+ // Init creator
+ // "Read" the configuration from the DOM node
+ DefaultConfigurationBuilder defaultConfigBuilder = new DefaultConfigurationBuilder();
+ Configuration[] docTypeConfigs = defaultConfigBuilder.buildFromFile(absoluteDoctypesPath + "doctypes.xconf").getChildren();
+ Configuration doctypeConf = null;
+ for(int i = 0; i < docTypeConfigs.length; i++){
+ String typeName = docTypeConfigs[i].getAttribute("type");
+ if(typeName.equals(doctype)){
+ doctypeConf = docTypeConfigs[i].getChild("creator", false);
+ }
+ }
+ creator.init(doctypeConf);
+ // Transaction should actually be started here!
+ String treefilename = sitemapParentPath + treeAuthoringPath;
+ getLogger().debug(".act(): Filename of tree: " + treefilename);
+ if(!new File(treefilename).exists()){
+ getLogger().warn("No sitetree or topic map: " + treefilename);
+ }else{
+ if(!updateTree(childtype, childType, childid, childname, parentid, doctype, creator, treefilename)) return null;
+ }
+ // Transaction should actually be finished here!
+ // Create actual document
+ // grab all the parameters from session, request params and
+ // sitemap params
+ HashMap allParameters = new HashMap();
+ String[] names = parameters.getNames();
+ for(int i = 0; i < names.length; i++){
+ String name = names[i];
+ String value = null;
+ try{
+ value = parameters.getParameter(name);
+ }catch(ParameterException pe){
+ value = null;
+ }
+ allParameters.put(name, value);
+ }
+ Enumeration requestParameters = request.getParameterNames();
+ while(requestParameters.hasMoreElements()){
+ String requestParameterName = (String) requestParameters.nextElement();
+ if(allParameters.containsKey(requestParameterName)){
+ // we do not allow name clashes
+ throw new ProcessingException("Name clash in request parameter " + "and sitemap parameter: " + requestParameterName);
+ }
+ allParameters.put(requestParameterName, request.getParameter(requestParameterName));
+ }
+ Enumeration sessionAttributeNames = session.getAttributeNames();
+ while(sessionAttributeNames.hasMoreElements()){
+ String sessionAttributeName = (String) sessionAttributeNames.nextElement();
+ if(allParameters.containsKey(sessionAttributeName)){
+ // we do not allow name clashes
+ throw new ProcessingException("Name clash in session attribute " + "and request parameter or sitemap parameter: " + sessionAttributeName);
+ }
+ allParameters.put(sessionAttributeName, session.getAttribute(sessionAttributeName));
+ }
+ try{
+ Publication publication = Globals.getPublication();
+ if(null == publication){
+ throw new PublicationException("ParentChildCreatorAction.act: No Publication.");
+ }
+ creator.create(publication, new File(absoluteDoctypesPath + "samples"), new File(sitemapParentPath + docsPath + parentid), parentid, childid, childType, childname, language, allParameters);
+ }catch(Exception e){
+ getLogger().error("Creator threw exception: " + e);
+ }
+ // Redirect to referer
+ String parent_uri = (String) session.getAttribute("org.apache.lenya.cms.cocoon.acting.ParentChildCreatorAction.parent_uri");
+ getLogger().info(".act(): Child added");
+ HashMap actionMap = new HashMap();
+ actionMap.put("parent_uri", parent_uri);
+ session.removeAttribute("org.apache.lenya.cms.cocoon.acting.ParentChildCreatorAction.parent_uri");
+ return actionMap;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parentid
+ * DOCUMENT ME!
+ * @param childid
+ * DOCUMENT ME!
+ * @param childname
+ * DOCUMENT ME!
+ * @param childtype
+ * DOCUMENT ME!
+ * @param doctype
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean validate(String parentid, String childid, String childname, String childtype, String doctype) {
+ getLogger().debug(".validate(): parentid=" + parentid + " ; childid=" + childid + " ; childname=" + childname + " ; childtype=" + childtype + " ; doctype=" + doctype);
+ if((childid.indexOf(" ") >= 0) || (childid.length() == 0)){
+ return false;
+ }
+ if(childname.length() == 0){
+ return false;
+ }
+ return true;
+ }
+ /**
+ *
+ */
+ private boolean updateTree(String childtype, short childType, String childid, String childname, String parentid, String doctype, ParentChildCreatorInterface creator, String treefilename) throws Exception {
+ Document doc = new SAXReader().read("file:" + treefilename);
+ // Get parent element
+ StringTokenizer st = new StringTokenizer(parentid, "/");
+ String xpath_string = "/tree/branch"; // Trunk of tree
+ while(st.hasMoreTokens()){
+ xpath_string = xpath_string + "/branch[@relURI='" + st.nextToken() + "']";
+ }
+ getLogger().debug("XPATH: " + xpath_string);
+ XPath xpathSelector = DocumentHelper.createXPath(xpath_string);
+ List nodes = xpathSelector.selectNodes(doc);
+ if(nodes.isEmpty()){
+ getLogger().error(".act(): No nodes: " + xpath_string);
+ getLogger().error(".act(): No child added!");
+ return false;
+ }
+ Element parent_element = (Element) nodes.get(0);
+ getLogger().debug("PARENT ELEMENT: " + parent_element.getPath());
+ // Set child type: branch or leaf
+ childType = creator.getChildType(childType);
+ if(childType == ParentChildCreatorInterface.BRANCH_NODE){
+ childtype = "branch";
+ }else{
+ childtype = "leaf";
+ }
+ // Check if child already exists
+ String newChildXPath = xpath_string + "/" + childtype;
+ getLogger().debug("CHECK: " + newChildXPath);
+ if(doc.selectSingleNode(newChildXPath + "[@relURI='" + creator.generateTreeId(childid, childType) + "']") != null){
+ getLogger().error("Exception: XPath exists: " + newChildXPath + "[@relURI='" + creator.generateTreeId(childid, childType) + "']");
+ getLogger().error("No child added");
+ return false;
+ }
+ // Add node: branch or leaf
+ parent_element.addElement(childtype).addAttribute("relURI", creator.generateTreeId(childid, childType)).addAttribute("doctype", doctype).addAttribute("menuName", creator.getChildName(childname));
+ getLogger().debug("Tree has been modified: " + doc.asXML());
+ // Write new tree
+ java.io.FileWriter fileWriter = new java.io.FileWriter(treefilename);
+ doc.write(fileWriter);
+ fileWriter.close();
+ return true;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java Tue Sep 9 17:30:20 2008
@@ -20,6 +20,7 @@
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.lenya.cms.publication.DocumentHelper;
/**
* <p>
@@ -31,18 +32,14 @@
*
* @version: $Id$
*/
-public class DocumentURLModule extends AbstractPageEnvelopeModule {
- // public class DocumentURLModule extends AbstractPageEnvelopeModule implements Serviceable {
- // private ServiceManager manager;
+public class DocumentURLModule extends AbstractInputModule {
/**
* @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 {
String url;
final String[] attributes = name.split(":");
- if(attributes.length < 3){
- throw new ConfigurationException("Invalid number of parameters: " + attributes.length + ". Expected 3 (area, document-id, language)");
- }
+ if(attributes.length < 3){ throw new ConfigurationException("Invalid number of parameters: " + attributes.length + ". Expected 3 (area, document-id, language)"); }
final String area = attributes[0];
final String documentId = attributes[1];
final String language = attributes[2];
@@ -67,10 +64,4 @@
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;
- // }
}
\ No newline at end of file
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java Tue Sep 9 17:30:20 2008
@@ -23,6 +23,7 @@
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.DublinCoreImpl;
@@ -31,23 +32,19 @@
/**
* Input module to access the dublin core values.
*/
-public class DublinCoreModule extends AbstractPageEnvelopeModule {
+public class DublinCoreModule extends AbstractInputModule {
/**
* @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 {
- if(!Arrays.asList(DublinCoreImpl.ELEMENTS).contains(name) && !Arrays.asList(DublinCoreImpl.TERMS).contains(name)){
- throw new ConfigurationException("The attribute [" + name + "] is not supported!");
- }
+ if(!Arrays.asList(DublinCoreImpl.ELEMENTS).contains(name) && !Arrays.asList(DublinCoreImpl.TERMS).contains(name)){ throw new ConfigurationException("The attribute [" + name + "] is not supported!"); }
Document document;
try{
document = PageEnvelope.getCurrent().getDocument();
}catch(PageEnvelopeException e1){
throw new ConfigurationException("Resolving page envelope failed: ", e1);
}
- if(document == null){
- throw new ConfigurationException("There is no document for this page envelope!");
- }
+ if(document == null){ throw new ConfigurationException("There is no document for this page envelope!"); }
Object value;
try{
value = document.getDublinCore().getFirstValue(name);
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java?rev=693670&r1=693669&r2=693670&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java Tue Sep 9 17:30:20 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.components.modules.input;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@@ -30,196 +27,166 @@
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.components.modules.input.AbstractInputModule;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.SourceUtil;
-
/**
* <p>
- * This module checks if a file exists in a publiation, and if not, it chooses the core file. The
- * attribute name must a path relatively to the <code>webapps/lenya/lenya</code> directory.
+ * This module checks if a file exists in a publiation, and if not, it chooses the core file. The attribute name must a path relatively to the <code>webapps/lenya/lenya</code> directory.
* </p>
* <p>
- * Example: <code>{fallback:xslt/style.xsl}</code> looks if
- * <code>lenya/pubs/(publication-id)/lenya/xslt/style.xsl</code> exists, and if not, it uses
- * <code>lenya/xslt/style.xsl</code>.
+ * Example: <code>{fallback:xslt/style.xsl}</code> looks if <code>lenya/pubs/(publication-id)/lenya/xslt/style.xsl</code> exists, and if not, it uses <code>lenya/xslt/style.xsl</code>.
*/
-public class FallbackModule extends AbstractPageEnvelopeModule implements Serviceable {
-
- private ServiceManager manager;
-
- private String[] baseUris;
-
- public static final String PATH_PREFIX = "lenya/";
-
- protected static final String ELEMENT_PATH = "directory";
-
- protected static final String ATTRIBUTE_SRC = "src";
-
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
- */
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
-
- Configuration[] pathConfigs = conf.getChildren(ELEMENT_PATH);
- List baseUriList = new ArrayList();
-
- SourceResolver resolver = null;
- try {
- resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
- Source source = null;
- for (int i = 0; i < pathConfigs.length; i++) {
- String uri = pathConfigs[i].getAttribute(ATTRIBUTE_SRC);
- try {
- source = resolver.resolveURI(uri);
- if (source.exists()) {
- File file = SourceUtil.getFile(source);
- if (file.isDirectory()) {
- baseUriList.add(uri);
- } else {
- getLogger().warn("Omitting path [" + uri + "] (not a directory).");
- }
- } else {
- getLogger().warn("Omitting path [" + uri + "] (does not exist).");
- }
- } catch (Exception e) {
- getLogger().error("Could not resolve path [" + uri + "]: ", e);
- throw e;
- } finally {
- if (source != null) {
- resolver.release(source);
- }
- }
+public class FallbackModule extends AbstractInputModule implements Serviceable {
+ private ServiceManager manager;
+ private String[] baseUris;
+ public static final String PATH_PREFIX = "lenya/";
+ protected static final String ELEMENT_PATH = "directory";
+ protected static final String ATTRIBUTE_SRC = "src";
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration conf) throws ConfigurationException {
+ super.configure(conf);
+ Configuration[] pathConfigs = conf.getChildren(ELEMENT_PATH);
+ List baseUriList = new ArrayList();
+ SourceResolver resolver = null;
+ try{
+ resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+ Source source = null;
+ for(int i = 0; i < pathConfigs.length; i++){
+ String uri = pathConfigs[i].getAttribute(ATTRIBUTE_SRC);
+ try{
+ source = resolver.resolveURI(uri);
+ if(source.exists()){
+ File file = SourceUtil.getFile(source);
+ if(file.isDirectory()){
+ baseUriList.add(uri);
+ }else{
+ getLogger().warn("Omitting path [" + uri + "] (not a directory).");
+ }
+ }else{
+ getLogger().warn("Omitting path [" + uri + "] (does not exist).");
+ }
+ }catch(Exception e){
+ getLogger().error("Could not resolve path [" + uri + "]: ", e);
+ throw e;
+ }finally{
+ if(source != null){
+ resolver.release(source);
+ }
}
- } catch (Exception e) {
- throw new ConfigurationException("Configuring failed: ", e);
- } finally {
- if (resolver != null) {
- manager.release(resolver);
+ }
+ }catch(Exception e){
+ throw new ConfigurationException("Configuring failed: ", e);
+ }finally{
+ if(resolver != null){
+ manager.release(resolver);
+ }
+ }
+ this.baseUris = (String[]) baseUriList.toArray(new String[baseUriList.size()]);
+ }
+ /**
+ * @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 {
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Resolving file for path [" + name + "]");
+ }
+ String resolvedUri = resolveURI(name, objectModel);
+ return resolvedUri;
+ }
+ /**
+ * Resolves the URI for a certain path.
+ *
+ * @param path
+ * The path.
+ * @param objectModel
+ * The object model.
+ * @return A string.
+ * @throws ConfigurationException
+ * if an error occurs.
+ */
+ protected String resolveURI(String path, Map objectModel) throws ConfigurationException {
+ String resolvedUri = null;
+ String checkedUris = "\n";
+ SourceResolver resolver = null;
+ try{
+ resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+ String[] baseUris = getBaseURIs(objectModel);
+ Source source = null;
+ int i = 0;
+ while(resolvedUri == null && i < baseUris.length){
+ String uri = baseUris[i] + "/" + path;
+ checkedUris += uri + "\n";
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Trying to resolve URI [" + uri + "]");
}
- }
-
- this.baseUris = (String[]) baseUriList.toArray(new String[baseUriList.size()]);
- }
-
- /**
- * @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 {
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Resolving file for path [" + name + "]");
- }
-
- String resolvedUri = resolveURI(name, objectModel);
- return resolvedUri;
- }
-
- /**
- * Resolves the URI for a certain path.
- * @param path The path.
- * @param objectModel The object model.
- * @return A string.
- * @throws ConfigurationException if an error occurs.
- */
- protected String resolveURI(String path, Map objectModel) throws ConfigurationException {
- String resolvedUri = null;
- String checkedUris = "\n";
-
- SourceResolver resolver = null;
- try {
- resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
-
- String[] baseUris = getBaseURIs(objectModel);
- Source source = null;
- int i = 0;
- while (resolvedUri == null && i < baseUris.length) {
- String uri = baseUris[i] + "/" + path;
-
- checkedUris += uri + "\n";
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Trying to resolve URI [" + uri + "]");
- }
-
- try {
- source = resolver.resolveURI(uri);
- if (source.exists()) {
- resolvedUri = uri;
- } else {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Skipping URI [" + uri + "] (does not exist).");
- }
- }
- } catch (Exception e) {
- getLogger().error("Could not resolve URI [" + uri + "]: ", e);
- throw e;
- } finally {
- if (source != null) {
- resolver.release(source);
- }
- }
- i++;
+ try{
+ source = resolver.resolveURI(uri);
+ if(source.exists()){
+ resolvedUri = uri;
+ }else{
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Skipping URI [" + uri + "] (does not exist).");
+ }
+ }
+ }catch(Exception e){
+ getLogger().error("Could not resolve URI [" + uri + "]: ", e);
+ throw e;
+ }finally{
+ if(source != null){
+ resolver.release(source);
+ }
}
-
- } catch (Exception e) {
- throw new ConfigurationException("Resolving attribute [" + path + "] failed: ", e);
- } finally {
- if (resolver != null) {
- manager.release(resolver);
- }
- }
-
- if (resolvedUri == null) {
- throw new ConfigurationException("Could not resolve file for path [" + path + "]."
- + "\nChecked URIs:" + checkedUris);
- }
- else {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Resolved URI: [" + resolvedUri + "]");
- }
- }
- return resolvedUri;
- }
-
- /**
- * Returns the base directory URIs in the order they should be traversed.
- * @param objectModel The object model.
- * @return An array of strings.
- * @throws ConfigurationException if an error occurs.
- */
- protected String[] getBaseURIs(Map objectModel) throws ConfigurationException {
- return this.baseUris;
- }
-
- /**
- * @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 Collections.EMPTY_SET.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;
- }
-
+ i++;
+ }
+ }catch(Exception e){
+ throw new ConfigurationException("Resolving attribute [" + path + "] failed: ", e);
+ }finally{
+ if(resolver != null){
+ manager.release(resolver);
+ }
+ }
+ if(resolvedUri == null){
+ throw new ConfigurationException("Could not resolve file for path [" + path + "]." + "\nChecked URIs:" + checkedUris);
+ }else{
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Resolved URI: [" + resolvedUri + "]");
+ }
+ }
+ return resolvedUri;
+ }
+ /**
+ * Returns the base directory URIs in the order they should be traversed.
+ *
+ * @param objectModel
+ * The object model.
+ * @return An array of strings.
+ * @throws ConfigurationException
+ * if an error occurs.
+ */
+ protected String[] getBaseURIs(Map objectModel) throws ConfigurationException {
+ return this.baseUris;
+ }
+ /**
+ * @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 Collections.EMPTY_SET.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;
+ }
}
\ No newline at end of file
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=693670&r1=693669&r2=693670&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 Tue Sep 9 17:30:20 2008
@@ -27,6 +27,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.components.modules.input.AbstractInputModule;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.commons.lang.StringUtils;
@@ -40,7 +41,7 @@
*
* @see org.apache.lenya.cms.publication.PageEnvelope
*/
-public class PageEnvelopeModule extends AbstractPageEnvelopeModule implements Serviceable {
+public class PageEnvelopeModule extends AbstractInputModule implements Serviceable {
private ServiceManager manager;
/**
* Get the the page envelope for the given objectModel.
@@ -115,8 +116,7 @@
}else if(name.equals(PageEnvelope.DOCUMENT_LANGUAGE)){
value = envelope.getDocument().getLanguage();
// LENYA1.3 - BEGIN
- if(((String) value).length() < 1)
- value = envelope.getPublication().getDefaultLanguage();
+ if(((String) value).length() < 1) value = envelope.getPublication().getDefaultLanguage();
// LENYA1.3 - END
}else if(name.equals(PageEnvelope.DOCUMENT_LANGUAGES)){
value = envelope.getDocument().getLanguages();
@@ -223,9 +223,7 @@
// 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;
+ if(index >= 0) return uri.substring(0, index);
+ else return uri;
}
}
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.