You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2019/12/06 22:43:34 UTC
[jspwiki] 06/14: move safeGetQueryParameter from WikiEngine to
HttpUtil
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit bb06b042a2bef7349d114fdc10a43d0166a1f5d6
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 22:04:00 2019 +0100
move safeGetQueryParameter from WikiEngine to HttpUtil
---
.../src/main/java/org/apache/wiki/WikiEngine.java | 38 +-------------------
.../main/java/org/apache/wiki/util/HttpUtil.java | 40 ++++++++++++++++++++--
2 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index b34386c..4ab6b73 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -864,48 +864,12 @@ public class WikiEngine
}
/**
- * Returns the query string (the portion after the question mark).
- *
- * @param request The HTTP request to parse.
- * @return The query string. If the query string is null,
- * returns an empty string.
- *
- * @since 2.1.3
- */
- public String safeGetQueryString( final HttpServletRequest request ) {
- if (request == null) {
- return "";
- }
-
- String res = request.getQueryString();
- if( res != null ) {
- res = new String( res.getBytes( StandardCharsets.ISO_8859_1 ), getContentEncoding() );
-
- //
- // Ensure that the 'page=xyz' attribute is removed
- // FIXME: Is it really the mandate of this routine to do that?
- //
- final int pos1 = res.indexOf("page=");
- if( pos1 >= 0 ) {
- String tmpRes = res.substring( 0, pos1 );
- final int pos2 = res.indexOf( "&",pos1 ) + 1;
- if ( ( pos2 > 0 ) && ( pos2 < res.length() ) ) {
- tmpRes = tmpRes + res.substring(pos2);
- }
- res = tmpRes;
- }
- }
-
- return res;
- }
-
- /**
* Returns an URL to some other Wiki that we know.
*
* @param wikiName The name of the other wiki.
* @return null, if no such reference was found.
*/
- public String getInterWikiURL( String wikiName )
+ public String getInterWikiURL( final String wikiName )
{
return TextUtil.getStringProperty(m_properties,PROP_INTERWIKIREF+wikiName,null);
}
diff --git a/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java b/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java
index cead919..3cd7f5d 100644
--- a/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java
+++ b/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java
@@ -23,6 +23,8 @@ import org.apache.log4j.Logger;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -65,7 +67,6 @@ public final class HttpUtil {
* @param cookieName The name of the cookie to fetch.
* @return Value of the cookie, or null, if there is no such cookie.
*/
-
public static String retrieveCookieValue( HttpServletRequest request, String cookieName ) {
Cookie[] cookies = request.getCookies();
@@ -194,8 +195,43 @@ public final class HttpUtil {
return uri;
}
- static boolean notBeginningWithHttpOrHttps( String uri ) {
+ static boolean notBeginningWithHttpOrHttps( final String uri ) {
return uri.length() > 0 && !( ( uri.startsWith("http://" ) || uri.startsWith( "https://" ) ) );
}
+ /**
+ * Returns the query string (the portion after the question mark).
+ *
+ * @param request The HTTP request to parse.
+ * @return The query string. If the query string is null, returns an empty string.
+ *
+ * @since 2.1.3 (method moved from WikiEngine on 2.11.0.M6)
+ */
+ public static String safeGetQueryString( final HttpServletRequest request, final Charset contentEncoding ) {
+ if( request == null ) {
+ return "";
+ }
+
+ String res = request.getQueryString();
+ if( res != null ) {
+ res = new String( res.getBytes( StandardCharsets.ISO_8859_1 ), contentEncoding );
+
+ //
+ // Ensure that the 'page=xyz' attribute is removed
+ // FIXME: Is it really the mandate of this routine to do that?
+ //
+ final int pos1 = res.indexOf("page=");
+ if( pos1 >= 0 ) {
+ String tmpRes = res.substring( 0, pos1 );
+ final int pos2 = res.indexOf( "&",pos1 ) + 1;
+ if ( ( pos2 > 0 ) && ( pos2 < res.length() ) ) {
+ tmpRes = tmpRes + res.substring(pos2);
+ }
+ res = tmpRes;
+ }
+ }
+
+ return res;
+ }
+
}