View Javadoc

1   /**
2    * This file is part of the equanda project.
3    *
4    * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
7    *
8    * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
9    * ANY KIND, either express or implied. See the License for the specific language governing rights and
10   * limitations under the License.
11   *
12   * Alternatively, the contents of this file may be used under the terms of
13   * either the GNU General Public License Version 2 or later (the "GPL"), or
14   * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
15   * in which case the provisions of the GPL or the LGPL are applicable instead
16   * of those above. If you wish to allow use of your version of this file only
17   * under the terms of either the GPL or the LGPL, and not to allow others to
18   * use your version of this file under the terms of the MPL, indicate your
19   * decision by deleting the provisions above and replace them with the notice
20   * and other provisions required by the GPL or the LGPL. If you do not delete
21   * the provisions above, a recipient may use your version of this file under
22   * the terms of any one of the MPL, the GPL or the LGPL.
23   */
24  
25  package org.equanda.tapestry5.services;
26  
27  import org.apache.tapestry5.Translator;
28  import org.apache.tapestry5.ioc.Configuration;
29  import org.apache.tapestry5.ioc.MappedConfiguration;
30  import org.apache.tapestry5.ioc.OrderedConfiguration;
31  import org.apache.tapestry5.ioc.annotations.InjectService;
32  import org.apache.tapestry5.services.*;
33  import org.equanda.tapestry5.bindings.ManifestBindingPrefixFactory;
34  import org.equanda.tapestry5.translators.BooleanTranslator;
35  import org.equanda.tapestry5.translators.DoubleTranslator;
36  import org.equanda.tapestry5.translators.TimestampTranslator;
37  
38  import java.io.IOException;
39  
40  /**
41   * Module definition
42   *
43   * @author <a href="mailto:joachim@progs.be">Joachim Van der Auwera</a>
44   */
45  public final class EquandaModule
46  {
47      private EquandaModule() {}
48      
49      public static void contributeComponentClassResolver( Configuration<LibraryMapping> configuration )
50      {
51          configuration.add( new LibraryMapping( "equanda", "org.equanda.tapestry5" ) );
52      }
53  
54      /**
55       * Contributes the following translators: <ul> <li>Double : which allows both both and comma as decimal
56       * separator</li> <li>Timestamp : translator for timestamp values</li> <li>Boolean : for boolean values</li> </ul>
57       *
58       * @param configuration configuration to add to
59       */
60      public static void contributeTranslatorSource( Configuration<Translator> configuration )
61      {
62          configuration.add( new DoubleTranslator() );
63          configuration.add( new TimestampTranslator() );
64          configuration.add( new BooleanTranslator() );
65      }
66  
67      public static void contributeFactoryDefaults( MappedConfiguration<String, String> configuration )
68      {
69          configuration.add( "equanda.truncate.default.length", "30" );
70          configuration.add( "equanda.truncate.default.suffix", "..." );
71          configuration.add( "equanda.inlinelinklist.additional.row.count", "5" );
72          configuration.add( "equanda.inlineprimitivelist.additional.row.count", "5" );
73      }
74  
75      public static RequestFilter buildUtf8Filter(
76          @InjectService( "RequestGlobals" ) final RequestGlobals requestGlobals )
77      {
78          return new RequestFilter()
79          {
80              public boolean service( Request request, Response response, RequestHandler handler )
81                  throws IOException
82              {
83                  requestGlobals.getHTTPServletRequest().setCharacterEncoding( "UTF-8" );
84                  return handler.service( request, response );
85              }
86          };
87      }
88  
89      public static void contributeRequestHandler( OrderedConfiguration<RequestFilter> configuration,
90                                                   @InjectService( "Utf8Filter" ) final RequestFilter utf8Filter )
91      {
92          configuration.add( "Utf8Filter", utf8Filter ); // handle UTF-8
93      }
94  
95      /**
96       * Contributes the factory for equanda binding prefixes
97       *
98       * @param configuration configuration to add to
99       */
100     public static void contributeBindingSource( MappedConfiguration<String, BindingFactory> configuration )
101     {
102         configuration.add( "manifest", new ManifestBindingPrefixFactory() );
103     }
104 
105 }