add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / messages / package.html
1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2 <!--
3  Licensed to the Apache Software Foundation (ASF) under one or more
4  contributor license agreements.  See the NOTICE file distributed with
5  this work for additional information regarding copyright ownership.
6  The ASF licenses this file to You under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with
8  the License.  You may obtain a copy of the License at
9
10      http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 -->
18 <html>
19 <head>
20    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
21 </head>
22 <body>
23
24 For Native Language Support (NLS), system of software internationalization.
25
26 <h2>NLS message API</h2>
27 <p>
28 This utility API, adds support for NLS messages in the apache code.
29 It is currently used by the lucene "New Flexible Query PArser".
30 </p>
31 <p>
32 Features:
33     <ol>
34         <li>Message reference in the code, using static Strings</li>
35         <li>Message resource validation at class load time, for easier debugging</li>
36         <li>Allows for message IDs to be re-factored using eclipse or other code re-factor tools</li>
37         <li>Allows for reference count on messages, just like code</li>
38                 <li>Lazy loading of Message Strings</li>        
39         <li>Normal loading Message Strings</li>                  
40     </ol>
41 </p>
42
43 <br/>
44 <br/>
45 <p>
46 Lazy loading of Message Strings
47
48 <pre class="prettyprint">
49         public class MessagesTestBundle extends NLS {
50         
51           private static final String BUNDLE_NAME = MessagesTestBundle.class.getName();
52         
53           private MessagesTestBundle() {
54             // should never be instantiated
55           }
56         
57           static {
58             // register all string ids with NLS class and initialize static string
59             // values
60             NLS.initializeMessages(BUNDLE_NAME, MessagesTestBundle.class);
61           }
62         
63           // static string must match the strings in the property files.
64           public static String Q0001E_INVALID_SYNTAX;
65           public static String Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION;
66         
67           // this message is missing from the properties file
68           public static String Q0005E_MESSAGE_NOT_IN_BUNDLE;
69         }
70
71     // Create a message reference
72     Message invalidSyntax = new MessageImpl(MessagesTestBundle.Q0001E_INVALID_SYNTAX, "XXX");
73     
74     // Do other stuff in the code...
75     // when is time to display the message to the user or log the message on a file
76     // the message is loaded from the correct bundle
77     
78     String message1 = invalidSyntax.getLocalizedMessage();
79     String message2 = invalidSyntax.getLocalizedMessage(Locale.JAPANESE);
80 </pre>
81 </p>
82
83 <br/>
84 <br/>
85 <p>
86 Normal loading of Message Strings
87
88 <pre class="prettyprint">
89         String message1 = NLS.getLocalizedMessage(MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION);
90         String message2 = NLS.getLocalizedMessage(MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, Locale.JAPANESE);
91 </pre>
92 </p>
93
94 <p>
95 The org.apache.lucene.messages.TestNLS junit contains several other examples.
96 The TestNLS java code is available from the Apache Lucene code repository.
97 </p>
98 </body>
99 </html>