Permalink
Browse files

[cleanup] Apply codestyle

  • Loading branch information...
1 parent 21db6cb commit 69ac58e87fc0e12363ee85ff2b0a0d1bb512615f @tmortagne tmortagne committed May 3, 2012
@@ -227,7 +227,7 @@ public URL createURL(String web, String name, String action, String querystring,
if (!StringUtils.isEmpty(querystring)) {
newpath.append("?");
- newpath.append(StringUtils.chomp(StringUtils.chomp(querystring, "&"), "&"));
+ newpath.append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&"));
// newpath.append(querystring.replaceAll("&","&"));
}
@@ -344,6 +344,7 @@ public URL createSkinURL(String filename, String web, String name, String xwikid
}
}
+ @Override
public URL createResourceURL(String filename, boolean forceSkinAction, XWikiContext context)
{
StringBuffer newpath = new StringBuffer(this.contextPath);
@@ -407,7 +408,7 @@ public URL createAttachmentURL(String filename, String web, String name, String
if (!StringUtils.isEmpty(querystring)) {
newpath.append("?");
- newpath.append(StringUtils.chomp(StringUtils.chomp(querystring, "&"), "&"));
+ newpath.append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&"));
}
try {
@@ -465,7 +466,7 @@ public URL createAttachmentRevisionURL(String filename, String web, String name,
qstring += "&" + querystring;
}
newpath.append("?");
- newpath.append(StringUtils.chomp(StringUtils.chomp(qstring, "&"), "&"));
+ newpath.append(StringUtils.removeEnd(StringUtils.removeEnd(qstring, "&"), "&"));
try {
return new URL(getServerURL(xwikidb, context), newpath.toString());
@@ -503,51 +504,56 @@ public URL createAttachmentRevisionURL(String filename, String web, String name,
@Override
public String getURL(URL url, XWikiContext context)
{
+ String relativeURL = "";
+
try {
- if (url == null) {
- return "";
- }
+ if (url != null) {
+ String surl = url.toString();
- String surl = url.toString();
- if (!surl.startsWith(serverURL.toString())) {
- // External URL: leave it as is.
- return surl;
- } else {
- // Internal XWiki URL: convert to relative.
- StringBuffer sbuf = new StringBuffer(url.getPath());
- String querystring = url.getQuery();
- if (!StringUtils.isEmpty(querystring)) {
- sbuf.append("?");
- sbuf.append(StringUtils.chomp(StringUtils.chomp(querystring, "&"), "&"));
- // sbuf.append(querystring.replaceAll("&","&"));
- }
+ if (!surl.startsWith(serverURL.toString())) {
+ // External URL: leave it as is.
+ relativeURL = surl;
+ } else {
+ // Internal XWiki URL: convert to relative.
+ StringBuffer sbuf = new StringBuffer(url.getPath());
+ String querystring = url.getQuery();
+ if (!StringUtils.isEmpty(querystring)) {
+ sbuf.append("?");
+ sbuf.append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&"));
+ // sbuf.append(querystring.replaceAll("&","&"));
+ }
- String anchor = url.getRef();
- if (!StringUtils.isEmpty(anchor)) {
- sbuf.append("#");
- sbuf.append(anchor);
+ String anchor = url.getRef();
+ if (!StringUtils.isEmpty(anchor)) {
+ sbuf.append("#");
+ sbuf.append(anchor);
+ }
+
+ relativeURL = Util.escapeURL(sbuf.toString());
}
- return Util.escapeURL(sbuf.toString());
}
} catch (Exception e) {
- e.printStackTrace();
- return "";
+ LOGGER.error("Failed to create URL", e);
}
+
+ return relativeURL;
}
@Override
public URL getRequestURL(XWikiContext context)
{
final URL url = super.getRequestURL(context);
+
try {
final URL servurl = getServerURL(context);
// if use apache mod_proxy we needed to know external host address
return new URL(servurl.getProtocol(), servurl.getHost(), servurl.getPort(), url.getFile());
- } catch (MalformedURLException ex) {
+ } catch (MalformedURLException e) {
// This should not happen
- ex.printStackTrace();
- return url;
+ LOGGER.error("Failed to create request URL", e);
}
+
+ return url;
}
public XWikiAttachment findAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename,

0 comments on commit 69ac58e

Please sign in to comment.