You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by fe...@apache.org on 2007/08/14 08:32:19 UTC
svn commit: r565640 - in /cocoon/trunk/core:
cocoon-core/src/main/resources/META-INF/cocoon/avalon/cocoon-core-sitemapcomponents.xconf
cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java
Author: felixk
Date: Mon Aug 13 23:32:18 2007
New Revision: 565640
URL: http://svn.apache.org/viewvc?view=rev&rev=565640
Log:
Add sitemap action to log log a message.
This will give the possibility e.g. to log depracation messages for client side scripts (e.g. HTMLArea).
Added:
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java (with props)
Modified:
cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/avalon/cocoon-core-sitemapcomponents.xconf
Modified: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/avalon/cocoon-core-sitemapcomponents.xconf
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/avalon/cocoon-core-sitemapcomponents.xconf?view=diff&rev=565640&r1=565639&r2=565640
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/avalon/cocoon-core-sitemapcomponents.xconf (original)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/avalon/cocoon-core-sitemapcomponents.xconf Mon Aug 13 23:32:18 2007
@@ -281,6 +281,7 @@
<default-locale language="en" country="US"/>
+-->
</map:action>
+ <map:action logger="sitemap.action.log" name="log" src="org.apache.cocoon.acting.LogAction"/>
</map:actions>
Added: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java?view=auto&rev=565640
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java (added)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java Mon Aug 13 23:32:18 2007
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.cocoon.acting;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A simple Action that logs a given message for a given log level.
+ *
+ * <p>
+ * Parameters:
+ *
+ * <pre>
+ * level (optional): Indicates the log level, defaults to 'info'
+ * console (optional): Indicates weather the message is also print to console, defaults to 'false'
+ * message (optional): The message to log, defaults to 'No log message given'
+ * </pre>
+ *
+ * <p>
+ *
+ * Sitemap definition:
+ *
+ * <pre>
+ * <map:action name="log" src="org.apache.cocoon.acting.LogAction"/>
+ * </pre>
+ *
+ * <p>
+ *
+ * Example use:
+ *
+ * <pre>
+ * <map:match pattern="some-resource">
+ *
+ * <!-- do something else -->
+ *
+ * <map:act type="log">
+ * <map:parameter name="level" value="info"/>
+ * <map:parameter name="message" value="Log message from sitemap action"/>
+ * <map:parameter name="console" value="true"/>
+ * </map:act>
+ *
+ * <!-- do something else -->
+ *
+ * </map:match>
+ * </pre>
+ *
+ *
+ * @version $Id$
+ */
+public class LogAction extends AbstractAction implements ThreadSafe {
+
+ /** The default logger for this class. */
+ private Log log = LogFactory.getLog(getClass());
+
+ /** Level's parameter name */
+ private final static String PARAM_LEVEL = "level";
+
+ /** Level's default value ('info') */
+ private final static String LEVEL_DEFAULT = "info";
+
+ /** Message's parameter name */
+ private final static String PARAM_MSG = "message";
+
+ /** Message's default value ('No log message given') */
+ private final static String MSG_DEFAULT = "No log message given";
+
+ /** Console's parameter name */
+ private final static String PARAM_CONSOLE = "console";
+
+ /** Console's default value (false) */
+ private final static boolean CONSOLE_DEFAULT = false;
+
+ /**
+ * A simple Action that logs a given message for a given log level.
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters par)
+ throws Exception {
+
+ final String logLevel = (par.getParameter(PARAM_LEVEL) != null ? (String) par.getParameter(PARAM_LEVEL)
+ : LEVEL_DEFAULT);
+ final String logMsg = (par.getParameter(PARAM_MSG) != null ? (String) par.getParameter(PARAM_MSG) : MSG_DEFAULT);
+
+ if (par.getParameterAsBoolean(PARAM_CONSOLE, CONSOLE_DEFAULT)) {
+ System.out.println(logMsg);
+ }
+
+ if (logLevel.equalsIgnoreCase("info")) {
+ if (log.isInfoEnabled()) {
+ log.info(logMsg);
+ }
+ } else {
+ if (logLevel.equalsIgnoreCase("warn")) {
+ if (log.isWarnEnabled()) {
+ log.warn(logMsg);
+ }
+ } else {
+ if (logLevel.equalsIgnoreCase("error")) {
+ if (log.isErrorEnabled()) {
+ log.error(logMsg);
+ }
+ } else {
+ if (logLevel.equalsIgnoreCase("fatal")) {
+ if (log.isFatalEnabled()) {
+ log.fatal(logMsg);
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug(logMsg);
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+}
Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/acting/LogAction.java
------------------------------------------------------------------------------
svn:keywords = Id