Skip to content

Commit

Permalink
Merge branch 'develop' into feature/site-settings-review
Browse files Browse the repository at this point in the history
Conflicts:
	WordPress/src/main/res/values/strings.xml
  • Loading branch information
tonyr59h committed Sep 16, 2015
2 parents 53c3a16 + 43eac0e commit 2411844
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ public void testAppendUrlParameters1() {
params.put("w", "200");
params.put("h", "300");
String url = UrlUtils.appendUrlParameters("http://wp.com/test", params);
assertEquals("http://wp.com/test?h=300&w=200", url);
if (!url.equals("http://wp.com/test?h=300&w=200") && !url.equals("http://wp.com/test?w=200&h=300")) {
assertTrue("failed test on url: " + url, false);
}
}

public void testAppendUrlParameters2() {
Map<String, String> params = new HashMap<>();
params.put("h", "300");
params.put("w", "200");
String url = UrlUtils.appendUrlParameters("/relative/test", params);
assertEquals("/relative/test?h=300&w=200", url);
if (!url.equals("/relative/test?h=300&w=200") && !url.equals("/relative/test?w=200&h=300")) {
assertTrue("failed test on url: " + url, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ public class BlogUtils {
public int compare(Object blog1, Object blog2) {
Map<String, Object> blogMap1 = (Map<String, Object>) blog1;
Map<String, Object> blogMap2 = (Map<String, Object>) blog2;
String blogName1 = getBlogNameOrHostNameFromAccountMap(blogMap1);
String blogName2 = getBlogNameOrHostNameFromAccountMap(blogMap2);
String blogName1 = getBlogNameOrHomeURLFromAccountMap(blogMap1);
String blogName2 = getBlogNameOrHomeURLFromAccountMap(blogMap2);
return blogName1.compareToIgnoreCase(blogName2);
}
};

/**
* Return a blog name or blog url (host part only) if trimmed name is an empty string
* Return a blog name or blog home URL if trimmed name is an empty string
*/
public static String getBlogNameOrHostNameFromAccountMap(Map<String, Object> account) {
public static String getBlogNameOrHomeURLFromAccountMap(Map<String, Object> account) {
String blogName = getBlogNameFromAccountMap(account);
if (blogName.trim().length() == 0) {
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
blogName = BlogUtils.getHomeURLOrHostNameFromAccountMap(account);
}
return blogName;
}
Expand All @@ -33,9 +33,16 @@ public static String getBlogNameFromAccountMap(Map<String, Object> account) {
}

/**
* Return blog url (host part only) if trimmed name is an empty string
* Return the blog home URL setting or the host name if home URL is an empty string.
*/
public static String getHostNameFromAccountMap(Map<String, Object> account) {
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
public static String getHomeURLOrHostNameFromAccountMap(Map<String, Object> account) {
String homeURL = UrlUtils.removeScheme(MapUtils.getMapStr(account, "homeURL"));
homeURL = StringUtils.removeTrailingSlash(homeURL);

if (homeURL.length() == 0) {
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
}

return homeURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ public static String capitalize(final String str) {
return new StringBuilder(strLen).append(Character.toTitleCase(firstChar)).append(str.substring(1)).toString();
}

public static String removeTrailingSlash(final String str) {
if (TextUtils.isEmpty(str) || !str.endsWith("/")) {
return str;
}

return str.substring(0, str.length() -1);
}

/*
* Wrap an image URL in a photon URL
* Check out http://developer.wordpress.com/docs/photon/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ public static String normalizeUrl(final String urlString) {
}
}


/**
* returns the passed url without the scheme
*/
public static String removeScheme(final String urlString) {
if (urlString == null) {
return null;
}

int doubleslash = urlString.indexOf("//");
if (doubleslash == -1) {
doubleslash = 0;
} else {
doubleslash += 2;
}

return urlString.substring(doubleslash, urlString.length());
}

/**
* returns the passed url without the query parameters
*/
Expand Down

0 comments on commit 2411844

Please sign in to comment.