4141 */
4242package org .netbeans .modules .php .wordpress ;
4343
44- import java .awt .Component ;
4544import java .io .BufferedReader ;
4645import java .io .IOException ;
4746import java .io .InputStreamReader ;
8382import org .netbeans .modules .php .wordpress .util .NetUtils ;
8483import org .netbeans .modules .php .wordpress .util .WPFileUtils ;
8584import org .netbeans .modules .php .wordpress .util .WPZipEntryFilter ;
85+ import org .netbeans .modules .php .wordpress .wpapis .WordPressVersionCheckApi ;
8686import org .openide .filesystems .FileObject ;
8787import org .openide .filesystems .FileUtil ;
8888import org .openide .util .Exceptions ;
8989import org .openide .util .HelpCtx ;
90+ import org .openide .util .NbBundle ;
9091
9192/**
9293 *
@@ -112,6 +113,7 @@ public class WordPressPhpModuleExtender extends PhpModuleExtender {
112113 private static final Set <String > CONFIG_KEYS = new HashSet <String >();
113114 private static final Map <String , String > CONFIG_MAP = new HashMap <String , String >();
114115 private boolean isInternetReachable = true ;
116+ private String errorMessage ;
115117 private static final Logger LOGGER = Logger .getLogger (WordPressPhpModuleExtender .class .getName ());
116118
117119 static {
@@ -150,31 +152,32 @@ public HelpCtx getHelp() {
150152 return null ;
151153 }
152154
155+ @ NbBundle .Messages ("WordPressPhpModuleExtender.no.installation=There is no available installation method." )
153156 @ Override
154157 public boolean isValid () {
155158 String url = panel .getUrlLabel ();
156159 String localFile = panel .getLocalFileLabel ();
157160 if (!isInternetReachable || url .isEmpty ()) {
158161 if (localFile .isEmpty ()) {
159- Component [] components = panel . getComponents ();
160- for ( Component component : components ) {
161- component . setEnabled ( false );
162- }
162+ // disable all field
163+ panel . setAllEnabled ( panel , false );
164+ panel . setAllEnabled ( panel . getWpConfigPanel (), false );
165+ errorMessage = Bundle . WordPressPhpModuleExtender_no_installation ();
163166 return false ;
164-
165167 }
166168 }
169+ errorMessage = null ;
167170 return true ;
168171 }
169172
170173 @ Override
171174 public String getErrorMessage () {
172- return null ;
175+ return errorMessage ;
173176 }
174177
175178 @ Override
176179 public String getWarningMessage () {
177- return null ;
180+ return errorMessage ;
178181 }
179182
180183 /**
@@ -282,27 +285,31 @@ public Set<FileObject> extend(PhpModule pm) throws ExtendingException {
282285 */
283286 private String getDownloadUrl () {
284287 String downloadUrl = WordPressOptions .getInstance ().getDownloadUrl ();
285- if (downloadUrl != null && ! downloadUrl .isEmpty ()) {
288+ if (! StringUtils .isEmpty (downloadUrl )) {
286289 return downloadUrl ;
287290 }
288- Locale locale = Locale .getDefault ();
289- String language = locale .getLanguage ();
290- String urlPath = WP_DL_URL_DEFAULT ;
291- if (language != null && !language .isEmpty ()) {
292- if (!language .equals ("en" )) { // NOI18N
293- urlPath = String .format (WP_DL_URL_FORMAT , language , language );
291+
292+ // get url from version check api
293+ String wpLocale = WordPressOptions .getInstance ().getWpLocale ();
294+ if (StringUtils .isEmpty (wpLocale )) {
295+ Locale locale = Locale .getDefault ();
296+ wpLocale = locale .getLanguage ();
297+ }
298+ if (!StringUtils .isEmpty (wpLocale )) {
299+ WordPressVersionCheckApi versionCheckApi = new WordPressVersionCheckApi (wpLocale );
300+ try {
301+ versionCheckApi .parse ();
302+ downloadUrl = versionCheckApi .getDownload ();
303+ } catch (IOException ex ) {
304+ downloadUrl = WP_DL_URL_DEFAULT ;
294305 }
295306 }
296- try {
297- URL check = new URL (urlPath );
298- URLConnection connection = check .openConnection ();
299- connection .connect ();
300- } catch (MalformedURLException ex ) {
301- Exceptions .printStackTrace (ex );
302- } catch (IOException ex ) {
303- urlPath = WP_DL_URL_DEFAULT ;
307+ if (!StringUtils .isEmpty (downloadUrl )) {
308+ return downloadUrl ;
304309 }
305- return urlPath ;
310+
311+ // default url
312+ return WP_DL_URL_DEFAULT ;
306313 }
307314
308315 private void createWpConfig (FileObject sample ) {
@@ -379,7 +386,7 @@ private List<String> getSecretKey() {
379386 HttpsURLConnection httpsConnection = (HttpsURLConnection ) connection ;
380387 BufferedReader reader = new BufferedReader (new InputStreamReader (httpsConnection .getInputStream (), Charset .UTF8 )); // NOI18N
381388 try {
382- String line = null ;
389+ String line ;
383390 while ((line = reader .readLine ()) != null ) {
384391 keys .add (line );
385392 }
0 commit comments