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/01/03 14:52:05 UTC

svn commit: r123968 - /lenya/trunk/src/java/org/apache/lenya/cms/cocoon/matching /lenya/trunk/src/java/org/apache/lenya/cms/cocoon/matching/UsecaseRegistrationMatcher.java

Author: andreas
Date: Mon Jan  3 05:52:04 2005
New Revision: 123968

URL: http://svn.apache.org/viewcvs?view=rev&rev=123968
Log:
added matcher to match registered usecases
Added:
   lenya/trunk/src/java/org/apache/lenya/cms/cocoon/matching/
   lenya/trunk/src/java/org/apache/lenya/cms/cocoon/matching/UsecaseRegistrationMatcher.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/matching/UsecaseRegistrationMatcher.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/matching/UsecaseRegistrationMatcher.java?view=auto&rev=123968
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/matching/UsecaseRegistrationMatcher.java	Mon Jan  3 05:52:04 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.cocoon.matching;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.parameters.Parameters;
+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.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.sitemap.PatternException;
+import org.apache.lenya.cms.usecase.UsecaseResolver;
+
+/**
+ * Matches if the request calls a usecase which is registered for the Usecase Framework.
+ */
+public class UsecaseRegistrationMatcher extends AbstractLogEnabled implements Matcher, Serviceable {
+
+    /**
+     * @see org.apache.cocoon.matching.Matcher#match(java.lang.String,
+     *      java.util.Map, org.apache.avalon.framework.parameters.Parameters)
+     */
+    public Map match(String pattern, Map objectModel, Parameters parameters)
+            throws PatternException {
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        String usecaseName = request.getParameter("lenya.usecase");
+
+        Map result = null;
+
+        UsecaseResolver resolver = null;
+        try {
+            resolver = (UsecaseResolver) this.manager.lookup(UsecaseResolver.ROLE);
+            if (resolver.isRegistered(usecaseName)) {
+                result = Collections.EMPTY_MAP;
+            }
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Usecase [" + usecaseName + "] exists: [" + !(result == null) + "]");
+            }
+        } catch (ServiceException e) {
+            throw new PatternException(e);
+        } finally {
+            if (resolver != null) {
+                this.manager.release(resolver);
+            }
+        }
+
+        return result;
+    }
+
+    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;
+    }
+
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org