dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18296
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7660: moved some utils from WebUtils => ContextUtils
------------------------------------------------------------
revno: 7660
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-07-21 17:45:19 +0200
message:
moved some utils from WebUtils => ContextUtils
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java 2012-07-13 20:45:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java 2012-07-21 15:45:19 +0000
@@ -31,12 +31,18 @@
import java.io.PrintWriter;
import java.util.Calendar;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javassist.util.proxy.ProxyObject;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.dxf2.metadata.ExchangeClasses;
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.system.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
import static org.hisp.dhis.setting.SystemSettingManager.KEY_CACHE_STRATEGY;
import static org.apache.commons.lang.StringUtils.trimToNull;
@@ -157,4 +163,65 @@
// Ignore
}
}
+
+ public static HttpServletRequest getRequest()
+ {
+ return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+ }
+
+ public static String getPathWithUid( IdentifiableObject identifiableObject )
+ {
+ return getPath( identifiableObject.getClass() ) + "/" + identifiableObject.getUid();
+ }
+
+ public static String getPath( Class<?> clazz )
+ {
+ if ( ProxyObject.class.isAssignableFrom( clazz ) )
+ {
+ clazz = clazz.getSuperclass();
+ }
+
+ String resourcePath = ExchangeClasses.getExportMap().get( clazz );
+
+ return getRootPath( getRequest() ) + "/" + resourcePath;
+ }
+
+ public static String getRootPath( HttpServletRequest request )
+ {
+ StringBuilder builder = new StringBuilder();
+ String xForwardedProto = request.getHeader( "X-Forwarded-Proto" );
+ String xForwardedPort = request.getHeader( "X-Forwarded-Port" );
+
+ if ( xForwardedProto != null && (xForwardedProto.equalsIgnoreCase( "http" ) || xForwardedProto.equalsIgnoreCase( "https" )) )
+ {
+ builder.append( xForwardedProto );
+ }
+ else
+ {
+ builder.append( request.getScheme() );
+ }
+
+ builder.append( "://" ).append( request.getServerName() );
+
+ int port;
+
+ try
+ {
+ port = Integer.parseInt( xForwardedPort );
+ }
+ catch ( NumberFormatException e )
+ {
+ port = request.getServerPort();
+ }
+
+ if ( port != 80 && port != 443 )
+ {
+ builder.append( ":" ).append( port );
+ }
+
+ builder.append( request.getContextPath() );
+ builder.append( request.getServletPath() );
+
+ return builder.toString();
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2012-07-20 10:15:43 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2012-07-21 15:45:19 +0000
@@ -84,7 +84,7 @@
if ( metaData.getPager() != null && baseType != null )
{
- String basePath = getPath( baseType );
+ String basePath = ContextUtils.getPath( baseType );
Pager pager = metaData.getPager();
if ( pager.getPage() < pager.getPageCount() )
@@ -110,7 +110,7 @@
@SuppressWarnings( "unchecked" )
public static void generateLinks( IdentifiableObject identifiableObject )
{
- identifiableObject.setHref( getPathWithUid( identifiableObject ) );
+ identifiableObject.setHref( ContextUtils.getPathWithUid( identifiableObject ) );
Collection<Field> fields = ReflectionUtils.collectFields( identifiableObject.getClass(), alwaysTrue );
@@ -123,7 +123,7 @@
if ( object != null )
{
IdentifiableObject idObject = (IdentifiableObject) object;
- idObject.setHref( getPathWithUid( idObject ) );
+ idObject.setHref( ContextUtils.getPathWithUid( idObject ) );
}
}
else if ( ReflectionUtils.isCollection( field.getName(), identifiableObject, IdentifiableObject.class ) )
@@ -138,73 +138,11 @@
{
if ( object != null )
{
- object.setHref( getPathWithUid( object ) );
+ object.setHref( ContextUtils.getPathWithUid( object ) );
}
}
}
}
}
}
-
- public static HttpServletRequest getRequest()
- {
- return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
- }
-
- public static String getPathWithUid( IdentifiableObject identifiableObject )
- {
- return getPath( identifiableObject.getClass() ) + "/" + identifiableObject.getUid();
- }
-
- public static String getPath( Class<?> clazz )
- {
- if ( ProxyObject.class.isAssignableFrom( clazz ) )
- {
- clazz = clazz.getSuperclass();
- }
-
- String resourcePath = ExchangeClasses.getExportMap().get( clazz );
-
- return getRootPath( getRequest() ) + "/" + resourcePath;
- }
-
- private static String getRootPath( HttpServletRequest request )
- {
- StringBuilder builder = new StringBuilder();
- String xForwardedProto = request.getHeader( "X-Forwarded-Proto" );
- String xForwardedPort = request.getHeader( "X-Forwarded-Port" );
-
- if ( xForwardedProto != null && (xForwardedProto.equalsIgnoreCase( "http" ) || xForwardedProto.equalsIgnoreCase( "https" )) )
- {
- builder.append( xForwardedProto );
- }
- else
- {
- builder.append( request.getScheme() );
- }
-
- builder.append( "://" ).append( request.getServerName() );
-
- int port;
-
- try
- {
- port = Integer.parseInt( xForwardedPort );
- }
- catch ( NumberFormatException e )
- {
- port = request.getServerPort();
- }
-
- if ( port != 80 && port != 443 )
- {
- builder.append( ":" ).append( port );
- }
-
- builder.append( request.getContextPath() );
- builder.append( request.getServletPath() );
-
- return builder.toString();
- }
-
}