KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > i18n > java > JavaI18nString


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.i18n.java;
22
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.netbeans.modules.i18n.I18nString;
28 import org.netbeans.modules.i18n.I18nSupport;
29
30 import org.openide.util.MapFormat;
31
32
33 /**
34  * This is <code>I18nString</code> for java sources.
35  *
36  * @author Peter Zavadsky
37  * @author Petr Kuzel
38  */

39 public class JavaI18nString extends I18nString {
40
41     /**
42      * Arguments used by creation replacing code enclapsulating
43      * in java.util.MessageFormat.format method call.
44      */

45     protected String JavaDoc[] arguments;
46
47     /** Creates 'empty' <code>JavaI18nString</code>.*/
48     public JavaI18nString(I18nSupport i18nSupport) {
49         super(i18nSupport);
50     }
51
52     /**
53      * Copy contructor.
54      */

55     protected JavaI18nString(JavaI18nString copy) {
56         super(copy);
57         if (arguments == null) return;
58         this.arguments = (String JavaDoc[]) copy.arguments.clone();
59     }
60     
61     public void become(JavaI18nString i18nString) {
62         super.become(i18nString);
63         
64         JavaI18nString peer = (JavaI18nString) i18nString;
65         this.setArguments(peer.arguments);
66     }
67     
68     public Object JavaDoc clone() {
69         return new JavaI18nString(this);
70     }
71     
72     /** Getter for property arguments.
73      * @return Value of property arguments.
74      */

75     public String JavaDoc[] getArguments() {
76         if(arguments == null)
77             arguments = new String JavaDoc[0];
78         return arguments;
79     }
80     
81     /** Setter for property arguments.
82      * @param arguments New value of property arguments.
83      */

84     public void setArguments(String JavaDoc[] arguments) {
85         String JavaDoc[] oldArguments = arguments;
86         this.arguments = arguments;
87     }
88     
89     /**
90      * Add java specific replacing values.
91      */

92     protected void fillFormatMap(Map JavaDoc map) {
93         map.put("identifier", ((JavaI18nSupport)getSupport()).getIdentifier()); // NOI18N
94

95         // Arguments.
96
String JavaDoc[] arguments = getArguments();
97         StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
98         stringBuffer.append("new Object[] {"); // NOI18N
99

100         for(int i=0; i<arguments.length; i++) {
101             stringBuffer.append(arguments[i]);
102             
103             if(i<arguments.length - 1)
104                 stringBuffer.append(", "); // NOI18N
105
}
106         
107         stringBuffer.append("}"); // NOI18N
108

109         map.put("arguments", stringBuffer.toString());
110     }
111     
112 }
113
Popular Tags