001: /*
002: *
003: * Copyright 2007 Florin T.PATRASCU
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package ca.flop.jpublish.i18n;
020:
021: import com.anthonyeden.lib.config.Configuration;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.jpublish.JPublishModule;
025: import org.jpublish.SiteContext;
026: import org.jpublish.action.Action;
027: import org.jpublish.action.ActionWrapper;
028:
029: import java.util.HashMap;
030: import java.util.Map;
031:
032: /**
033: * @author <a href="mailto:florin.patrascu@gmail.com">Florin T.PATRASCU</a>
034: * @since $Revision$ (created: Jul 26, 2006 2:54:38 PM)
035: */
036: public class I18nModule implements JPublishModule {
037: private static Log log = LogFactory.getLog(I18nModule.class);
038:
039: private static final String NAME = "JPublishI18n Module";
040: private static final String DESCRIPTION = "i18n support for JPublish.";
041:
042: private SiteContext site;
043: private Map actions = new HashMap(1);
044: /**
045: * The time on the script files
046: */
047: private static final long moduleStartTime;
048:
049: /**
050: * The etag (=time for us) on the script files
051: */
052: private static final String etag;
053:
054: /**
055: * Initialize the container start time
056: */
057: static {
058: // Browsers are only accurate to the second
059: long now = System.currentTimeMillis();
060: moduleStartTime = now - (now % 1000);
061:
062: etag = "\"" + moduleStartTime + '\"'; //$NON-NLS-1$
063: }
064:
065: /**
066: * Initialize the module. This corresponds with the
067: * Servlet.init() method, except that it includes a reference
068: * to the JPublish SiteContext.
069: *
070: * @param site The SiteContext
071: * @param configuration The configuration object
072: * @throws Exception
073: */
074:
075: public void init(SiteContext site, Configuration configuration)
076: throws Exception {
077: log.info(NAME + " starting for: "
078: + site.getServletContext().getServletContextName());
079:
080: this .site = site;
081:
082: Action i18nAction = new SpringI18nSupport();
083: actions.put("I18nModule.i18nAction", i18nAction);
084: site.getActionManager().getGlobalActions().add(
085: new ActionWrapper(i18nAction, configuration));
086: log.info(NAME + " started.");
087:
088: }
089:
090: /**
091: * Get a map of defined actions.
092: *
093: * @return The defined actions
094: */
095:
096: public Map getDefinedActions() {
097: return actions;
098: }
099:
100: /**
101: * Invoked when the module is destroyed. This corresponds to the
102: * Servlet.destroy() method.
103: */
104:
105: public void destroy() {
106: }
107:
108: public static String getModuleDescription() {
109: return DESCRIPTION;
110: }
111:
112: public SiteContext getSite() {
113: return site;
114: }
115:
116: public static long getModuleStartTime() {
117: return moduleStartTime;
118: }
119:
120: public static String getEtag() {
121: return etag;
122: }
123:
124: }
|