1 19 20 21 package org.netbeans.modules.i18n; 22 23 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import org.netbeans.api.java.classpath.ClassPath; 27 import org.openide.filesystems.FileObject; 28 29 import org.openide.loaders.DataObject; 30 import org.openide.util.MapFormat; 31 32 33 47 public class I18nString { 48 49 53 protected I18nSupport support; 54 55 56 protected String key; 57 58 59 protected String value; 60 61 62 protected String comment; 63 64 65 protected String replaceFormat; 66 67 68 73 protected I18nString(I18nSupport support) { 74 if(support == null) throw new NullPointerException (); 75 76 this.support = support; 77 78 replaceFormat = I18nUtil.getOptions().getReplaceJavaCode(); 80 } 81 82 85 protected I18nString(I18nString copy) { 86 this.key = copy.key; 87 this.value = copy.value; 88 this.comment = copy.comment; 89 this.replaceFormat = copy.replaceFormat; 90 this.support = copy.support; 91 } 92 93 97 public void become(I18nString copy) { 98 this.key = copy.key; 99 this.value = copy.value; 100 this.comment = copy.comment; 101 this.replaceFormat = copy.replaceFormat; 102 this.support = copy.support; 103 } 104 105 108 public Object clone() { 109 return new I18nString(this); 110 } 111 112 113 public I18nSupport getSupport() { 114 return support; 115 } 116 117 118 public String getKey() { 119 return key; 120 } 121 122 123 public void setKey(String key) { 124 if(this.key == key || (this.key != null && this.key.equals(key))) 125 return; 126 127 this.key = key; 128 } 129 130 131 public String getValue() { 132 return value; 133 } 134 135 136 public void setValue(String value) { 137 if(this.value == value || (this.value != null && this.value.equals(value))) 138 return; 139 140 this.value = value; 141 } 142 143 144 public String getComment() { 145 return comment; 146 } 147 148 149 public void setComment(String comment) { 150 if(this.comment == comment || (this.comment != null && this.comment.equals(comment))) 151 return; 152 153 this.comment = comment; 154 } 155 156 157 public String getReplaceFormat() { 158 return replaceFormat; 159 } 160 161 162 public void setReplaceFormat(String replaceFormat) { 163 this.replaceFormat = replaceFormat; 164 } 165 166 179 public String getReplaceString() { 180 if(getKey() == null || getSupport() == null || getSupport().getResourceHolder().getResource() == null) 181 return null; 182 183 if(replaceFormat == null) 184 replaceFormat = I18nUtil.getOptions().getReplaceJavaCode(); 185 186 188 DataObject sourceDataObject = getSupport().getSourceDataObject(); 189 190 FileObject fo = getSupport().getResourceHolder().getResource().getPrimaryFile(); 191 ClassPath cp = Util.getExecClassPath(sourceDataObject.getPrimaryFile(), fo); 192 Map map = new HashMap (4); 193 194 map.put("key", getKey()); map.put("bundleNameSlashes", cp.getResourceName( fo, '/', false ) ); map.put("bundleNameDots", cp.getResourceName( fo, '.', false ) ); map.put("sourceFileName", sourceDataObject == null ? "" : sourceDataObject.getPrimaryFile().getName()); 199 fillFormatMap(map); 200 201 return MapFormat.format(replaceFormat, map); 202 } 203 204 210 protected void fillFormatMap(Map subst) { 211 } 212 } 213 | Popular Tags |