1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Locale ; 27 import java.util.Set ; 28 import org.openide.modules.Dependency; 29 import org.openide.modules.ModuleInfo; 30 import org.openide.modules.SpecificationVersion; 31 import org.openide.util.NbBundle; 32 import org.w3c.dom.*; 33 34 39 class L10NUpdate extends ModuleUpdate { 40 41 private static final String ATTR_LONG_DESC = "OpenIDE-Module-Long-Description"; 43 private String langcode; 44 45 46 private String brandingcode; 47 48 49 private SpecificationVersion specversion; 50 51 52 private int majorversion; 53 54 55 private String l10nname; 56 57 58 private String l10ndesc; 59 60 private L10NModuleInfo remoteinfo; 61 62 L10NUpdate( URL xmlURL, Node node, Element documentElement ) { 63 super( xmlURL, node, documentElement ); 64 } 65 66 67 L10NUpdate( File nbmFile, Node node, Element documentElement ) { 68 super( nbmFile, node, documentElement ); 69 } 70 71 ModuleInfo readRemoteInfo() throws IllegalArgumentException { 72 NodeList nodeList = ((Element)getNode()).getElementsByTagName( ModuleUpdate.ELEMENT_L10N ); 73 74 if ( nodeList.getLength() > 0 ) { 75 Node n = nodeList.item( 0 ); 76 77 langcode = getAttribute( n, "langcode" ); brandingcode = getAttribute( n, "brandingcode" ); specversion = new SpecificationVersion ( getAttribute( n, "module_spec_version" ) ); String mvAttr = getAttribute( n, "module_major_version" ); if ( mvAttr != null ) { 82 majorversion = Integer.parseInt( mvAttr ); 83 } 84 else { 85 majorversion = -1; 86 } 87 l10nname = getAttribute( n, "OpenIDE-Module-Name" ); l10ndesc = getAttribute( n, ATTR_LONG_DESC ); 89 if ( getDescription() == null || getDescription().equals ("") ) setDescription( l10ndesc ); 91 } 92 93 remoteinfo = new L10NModuleInfo(); 94 remoteinfo.setName( l10nname ); 95 remoteinfo.setCodeNameBase( getInfoCodenamebase() ); 96 remoteinfo.setMajorversion( majorversion ); 97 remoteinfo.setSpecificationVersion( specversion ); 98 remoteinfo.setDependency( getInfoCodenamebase(), majorversion ); 99 100 return remoteinfo; 101 } 102 103 ModuleInfo readLocalInfo() { 104 ModuleInfo localmodule = super.readLocalInfo(); 105 L10NModuleInfo localinfo = null; 106 107 if ( localmodule != null ) { 108 if ( l10nname == null || l10nname.equals ("") ) remoteinfo.setName( localmodule.getDisplayName() ); 110 if ( getDescription() == null || getDescription().equals ("") ) setDescription( (String ) localmodule.getLocalizedAttribute( ATTR_LONG_DESC ) ); 112 113 SafeModule.ModuleStatus status = SafeModule.getModuleStatus( getInfoCodenamebase() ); 115 if ( status != null ) { 116 String jarpath = status.getJarPath() + "locale/" + status.getJarName(); if ( brandingcode != null && brandingcode.length() > 0 ) { 118 jarpath = jarpath + "_" + brandingcode; } 120 if ( langcode != null && langcode.length() > 0 ) { 121 jarpath = jarpath + "_" + langcode; } 123 jarpath = jarpath + ".jar"; SpecificationVersion specvers = getTrackingSpecVersion( jarpath ); 125 localinfo = new L10NModuleInfo(); 126 localinfo.setName( remoteinfo.getDisplayName() ); 127 localinfo.setCodeNameBase( getInfoCodenamebase() ); 128 if ( specvers != null ) { 129 localinfo.setSpecificationVersion( specvers ); 130 } 131 } 132 markNamesWithL10N(); 133 } 134 135 return localinfo; 136 } 137 138 private void markNamesWithL10N() { 139 String desc = ""; 140 if ( langcode != null && langcode.length() > 0 ) { 141 String lang = new Locale ( langcode, "" ).getDisplayLanguage(); desc = NbBundle.getMessage( L10NUpdate.class, "TXT_L10N_Prefix", lang ); 144 } 145 if ( brandingcode != null && brandingcode.length() > 0 ) { 146 if ( langcode != null && langcode.length() > 0 ) 147 desc = desc + ", "; desc = desc + NbBundle.getMessage( L10NUpdate.class, "TXT_L10N_Branding", brandingcode ); 150 } 151 if ( desc.length() > 0 ) { 152 desc = desc + NbBundle.getMessage (L10NUpdate.class, "TXT_L10N_DescEnd"); } 154 155 desc = desc + getDescription(); 156 setDescription( desc ); 157 158 if ( l10nname == null || l10nname.equals ("") ) { String dname = remoteinfo.getDisplayName() + " ("; 160 if ( langcode != null && langcode.length() > 0 ) { 161 dname = dname + langcode; } 163 if ( brandingcode != null && brandingcode.length() > 0 ) { 164 if ( langcode != null && langcode.length() > 0 ) 165 dname = dname + " "; dname = dname + brandingcode; 167 } 168 dname = dname + ")"; 169 remoteinfo.setName( dname ); } 171 } 172 173 private SpecificationVersion getTrackingSpecVersion(String jarpath) { 174 Iterator it = org.netbeans.updater.UpdateTracking.clusters (true).iterator (); 175 while (it.hasNext ()) { 176 File clusterDir = (File )it.next (); 177 org.netbeans.updater.UpdateTracking tracking; 178 tracking = org.netbeans.updater.UpdateTracking.getTracking (clusterDir, false); 179 if (tracking == null) { 180 continue; 182 } 183 184 String specversU = tracking.getL10NSpecificationVersion( getInfoCodenamebase(), true, jarpath ); 185 String specversI = tracking.getL10NSpecificationVersion( getInfoCodenamebase(), false, jarpath ); 186 if ( specversU == null && specversI == null ) 187 continue; 188 189 SpecificationVersion svU = ( specversU != null ) ? new SpecificationVersion( specversU ) : null; 190 SpecificationVersion svI = ( specversI != null ) ? new SpecificationVersion( specversI ) : null; 191 192 if ( svI != null && svU == null) 193 return svI; 194 else if ( svI == null && svU != null ) 195 return svU; 196 197 if ( svI.compareTo( svU ) > 0 ) 198 return svI; 199 else 200 return svU; 201 } 202 return null; 203 } 204 205 private String getAttribute(Node n, String attribute) { 206 Node attr = n.getAttributes().getNamedItem( attribute ); 207 return attr == null ? null : attr.getNodeValue(); 208 } 209 210 214 String getLangcode() { 215 return langcode; 216 } 217 218 222 String getBrandingcode() { 223 return brandingcode; 224 } 225 226 230 int getMajorversion() { 231 return majorversion; 232 } 233 234 238 String getL10nname() { 239 return l10nname; 240 } 241 242 246 String getL10ndesc() { 247 return l10ndesc; 248 } 249 250 252 253 boolean isUpdateAvailable() { 254 if ( getLocalModule() != null && 255 ( getLocalModule().getSpecificationVersion() == null 256 || getLocalModule().getSpecificationVersion().compareTo( remoteinfo.getSpecificationVersion() ) < 0 257 ) ) { 258 return true; 259 } 260 261 return false; 262 } 263 264 boolean isRemoteModuleAvailable( List modules ) { 265 Iterator it = modules.iterator(); 266 while ( it.hasNext() ) { 267 ModuleUpdate module = (ModuleUpdate) it.next(); 268 if ( module.getCodeNameBase().equals( remoteinfo.getCodeNameBase() ) 269 && module.getRemoteModule().getSpecificationVersion().compareTo( remoteinfo.getSpecificationVersion()) <= 0) { if ( remoteinfo.getDisplayName() == null || remoteinfo.getDisplayName().equals ("") ) remoteinfo.setName( module.getRemoteModule().getDisplayName() ); 272 if ( getDescription() == null || getDescription().equals ("") ) setDescription( (String ) module.getRemoteModule().getLocalizedAttribute( ATTR_LONG_DESC ) ); 274 markNamesWithL10N(); 275 return true; 276 } 277 } 278 279 return false; 280 } 281 282 class L10NModuleInfo extends ModuleInfo { 283 284 private SpecificationVersion specversion; 285 private String name; 286 private Set dep; 287 private String codenamebase; 288 private int majorversion; 289 290 public L10NModuleInfo() { 291 } 292 293 void setSpecificationVersion(SpecificationVersion specversion) { 294 this.specversion = specversion; 295 } 296 297 void setName(String name) { 298 this.name = name; 299 } 300 301 void setCodeNameBase(String codenamebase) { 302 this.codenamebase = codenamebase; 303 } 304 305 void setMajorversion(int majorversion) { 306 this.majorversion = majorversion; 307 } 308 309 void setDependency(String codenamebase, int majorversion) { 310 String body = codenamebase; 311 if ( majorversion > 0 ) 312 body = body + "/" + majorversion; dep = Dependency.create( Dependency.TYPE_MODULE, body ); 314 } 315 316 318 public SpecificationVersion getSpecificationVersion() { 319 return specversion; 320 } 321 322 public String getDisplayName() { 323 return name; 324 } 325 326 331 public Object getAttribute(String attr) { 332 return null; 333 } 334 335 336 public String getCodeName() { 337 return codenamebase + "/" + majorversion; } 339 340 341 public String getCodeNameBase() { 342 return codenamebase; 343 } 344 345 346 public int getCodeNameRelease() { 347 return majorversion; 348 } 349 350 351 public Set getDependencies() { 352 return dep; 353 } 354 355 360 public Object getLocalizedAttribute(String attr) { 361 return null; 362 } 363 364 365 public boolean isEnabled() { 366 return false; 367 } 368 369 376 public boolean owns(Class clazz) { 377 return false; 378 } 379 380 } 381 382 } 383 | Popular Tags |