3333
3434public class SetupBlog {
3535 private static final String DEFAULT_IMAGE_SIZE = "2000" ;
36-
3736 private String mUsername ;
3837 private String mPassword ;
3938 private String mHttpUsername = "" ;
@@ -46,7 +45,6 @@ public class SetupBlog {
4645
4746 private boolean mHttpAuthRequired ;
4847 private boolean mErroneousSslCertificate ;
49- private boolean mCurrentSslCertificatesForcedTrusted ;
5048
5149 public SetupBlog () {
5250 }
@@ -59,12 +57,12 @@ public String getXmlrpcUrl() {
5957 return mXmlrpcUrl ;
6058 }
6159
62- public void setUsername (String mUsername ) {
63- this . mUsername = mUsername ;
60+ public void setUsername (String username ) {
61+ mUsername = username ;
6462 }
6563
66- public void setPassword (String mPassword ) {
67- this . mPassword = mPassword ;
64+ public void setPassword (String password ) {
65+ mPassword = password ;
6866 }
6967
7068 public String getPassword () {
@@ -75,20 +73,20 @@ public String getUsername() {
7573 return mUsername ;
7674 }
7775
78- public void setHttpUsername (String mHttpUsername ) {
79- this . mHttpUsername = mHttpUsername ;
76+ public void setHttpUsername (String httpUsername ) {
77+ mHttpUsername = httpUsername ;
8078 }
8179
82- public void setHttpPassword (String mHttpPassword ) {
83- this . mHttpPassword = mHttpPassword ;
80+ public void setHttpPassword (String httpPassword ) {
81+ mHttpPassword = httpPassword ;
8482 }
8583
86- public void setSelfHostedURL (String mSelfHostedURL ) {
87- this . mSelfHostedURL = mSelfHostedURL ;
84+ public void setSelfHostedURL (String selfHostedURL ) {
85+ mSelfHostedURL = selfHostedURL ;
8886 }
8987
90- public void setHttpAuthRequired (boolean mHttpAuthRequired ) {
91- this . mHttpAuthRequired = mHttpAuthRequired ;
88+ public void setHttpAuthRequired (boolean httpAuthRequired ) {
89+ mHttpAuthRequired = httpAuthRequired ;
9290 }
9391
9492 public boolean isHttpAuthRequired () {
@@ -99,36 +97,32 @@ public boolean isErroneousSslCertificates() {
9997 return mErroneousSslCertificate ;
10098 }
10199
102- public List <Map <String , Object >> getBlogList () {
103- if (mSelfHostedURL != null && mSelfHostedURL .length () != 0 ) {
104- mXmlrpcUrl = getSelfHostedXmlrpcUrl (mSelfHostedURL );
105- } else {
106- mXmlrpcUrl = Constants .wpcomXMLRPCURL ;
107- }
108-
109- if (mXmlrpcUrl == null ) {
110- if (!mHttpAuthRequired && mErrorMsgId == 0 ) {
100+ private void handleXmlRpcFault (XMLRPCFault xmlRpcFault ) {
101+ AppLog .e (T .NUX , "XMLRPCFault received from XMLRPC call wp.getUsersBlogs" , xmlRpcFault );
102+ switch (xmlRpcFault .getFaultCode ()) {
103+ case 403 :
104+ mErrorMsgId = R .string .username_or_password_incorrect ;
105+ break ;
106+ case 404 :
107+ mErrorMsgId = R .string .xmlrpc_error ;
108+ break ;
109+ case 425 :
110+ mErrorMsgId = R .string .account_two_step_auth_enabled ;
111+ break ;
112+ default :
111113 mErrorMsgId = R .string .no_site_error ;
112- }
113- return null ;
114- }
115-
116- // Validate the URL found before calling the client. Prevent a crash that can occur
117- // during the setup of self-hosted sites.
118- URI uri ;
119- try {
120- uri = URI .create (mXmlrpcUrl );
121- } catch (Exception e1 ) {
122- mErrorMsgId = R .string .no_site_error ;
123- return null ;
114+ break ;
124115 }
116+ }
125117
118+ private List <Map <String , Object >> getUsersBlogsRequest (URI uri ) {
126119 XMLRPCClientInterface client = XMLRPCFactory .instantiate (uri , mHttpUsername , mHttpPassword );
127120 Object [] params = {mUsername , mPassword };
128121 try {
129122 Object [] userBlogs = (Object []) client .call ("wp.getUsersBlogs" , params );
130- if (userBlogs == null ) { // Could happen if the returned server response is truncated
131- mErrorMsgId = R .string .xmlrpc_error ;;
123+ if (userBlogs == null ) {
124+ // Could happen if the returned server response is truncated
125+ mErrorMsgId = R .string .xmlrpc_error ;
132126 return null ;
133127 }
134128 Arrays .sort (userBlogs , Utils .BlogNameComparator );
@@ -141,29 +135,12 @@ public List<Map<String, Object>> getBlogList() {
141135 }
142136 }
143137 return userBlogList ;
144- }
145- catch (XmlPullParserException parserException ) {
138+ } catch (XmlPullParserException parserException ) {
146139 mErrorMsgId = R .string .xmlrpc_error ;
147140 AppLog .e (T .NUX , "invalid data received from XMLRPC call wp.getUsersBlogs" , parserException );
148- }
149- catch (XMLRPCFault xmlRpcFault ) {
150- AppLog .e (T .NUX , "XMLRPCFault received from XMLRPC call wp.getUsersBlogs" , xmlRpcFault );
151- switch (xmlRpcFault .getFaultCode ()) {
152- case 403 :
153- mErrorMsgId = R .string .username_or_password_incorrect ;
154- break ;
155- case 404 :
156- mErrorMsgId = R .string .xmlrpc_error ;
157- break ;
158- case 425 :
159- mErrorMsgId = R .string .account_two_step_auth_enabled ;
160- break ;
161- default :
162- mErrorMsgId = R .string .no_site_error ;
163- break ;
164- }
165- }
166- catch (XMLRPCException xmlRpcException ) {
141+ } catch (XMLRPCFault xmlRpcFault ) {
142+ handleXmlRpcFault (xmlRpcFault );
143+ } catch (XMLRPCException xmlRpcException ) {
167144 AppLog .e (T .NUX , "XMLRPCException received from XMLRPC call wp.getUsersBlogs" , xmlRpcException );
168145 mErrorMsgId = R .string .no_site_error ;
169146 } catch (SSLHandshakeException e ) {
@@ -178,6 +155,32 @@ public List<Map<String, Object>> getBlogList() {
178155 return null ;
179156 }
180157
158+ public List <Map <String , Object >> getBlogList () {
159+ if (mSelfHostedURL != null && mSelfHostedURL .length () != 0 ) {
160+ mXmlrpcUrl = getSelfHostedXmlrpcUrl (mSelfHostedURL );
161+ } else {
162+ mXmlrpcUrl = Constants .wpcomXMLRPCURL ;
163+ }
164+
165+ if (mXmlrpcUrl == null ) {
166+ if (!mHttpAuthRequired && mErrorMsgId == 0 ) {
167+ mErrorMsgId = R .string .no_site_error ;
168+ }
169+ return null ;
170+ }
171+
172+ // Validate the URL found before calling the client. Prevent a crash that can occur
173+ // during the setup of self-hosted sites.
174+ URI uri ;
175+ try {
176+ uri = URI .create (mXmlrpcUrl );
177+ return getUsersBlogsRequest (uri );
178+ } catch (Exception e ) {
179+ mErrorMsgId = R .string .no_site_error ;
180+ return null ;
181+ }
182+ }
183+
181184 private String getRsdUrl (String baseUrl ) throws SSLHandshakeException {
182185 String rsdUrl ;
183186 rsdUrl = ApiHelper .getRSDMetaTagHrefRegEx (baseUrl );
@@ -257,13 +260,13 @@ private String getmXmlrpcByUserEnteredPath(String baseUrl) {
257260 // 2: Take whatever URL the user entered to see if that returns a correct response
258261 // 3: Finally, just guess as to what the xmlrpc url should be
259262 private String getSelfHostedXmlrpcUrl (String url ) {
260- String xmlrpcUrl = null ;
263+ String xmlrpcUrl ;
261264
262265 // Convert IDN names to punycode if necessary
263266 url = UrlUtils .convertUrlToPunycodeIfNeeded (url );
264267
265268 // Add http to the beginning of the URL if needed
266- url = UrlUtils .addHttpProcolIfNeeded (url , mCurrentSslCertificatesForcedTrusted );
269+ url = UrlUtils .addUrlSchemeIfNeeded (url , false );
267270
268271 if (!URLUtil .isValidUrl (url )) {
269272 mErrorMsgId = R .string .invalid_url_message ;
@@ -311,13 +314,16 @@ public Blog addBlog(String blogName, String xmlRpcUrl, String homeUrl, String bl
311314 blog .setHttpuser (mHttpUsername );
312315 blog .setHttppassword (mHttpPassword );
313316 blog .setBlogName (blogName );
314- blog .setImagePlacement ("" ); //deprecated
317+ // deprecated
318+ blog .setImagePlacement ("" );
315319 blog .setFullSizeImage (false );
316320 blog .setMaxImageWidth (DEFAULT_IMAGE_SIZE );
317- blog .setMaxImageWidthId (0 ); //deprecated
321+ // deprecated
322+ blog .setMaxImageWidthId (0 );
318323 blog .setRemoteBlogId (Integer .parseInt (blogId ));
319324 blog .setDotcomFlag (xmlRpcUrl .contains ("wordpress.com" ));
320- blog .setWpVersion ("" ); // assigned later in getOptions call
325+ // assigned later in getOptions call
326+ blog .setWpVersion ("" );
321327 blog .setAdmin (isAdmin );
322328 WordPress .wpDB .saveBlog (blog );
323329 } else {
0 commit comments