org.codehaus.groovy.grails.commons
Class GrailsResourceUtils

java.lang.Object
  extended by org.codehaus.groovy.grails.commons.GrailsResourceUtils

public class GrailsResourceUtils
extends java.lang.Object

Utility methods for working with Grails resources and URLs that represent artifacts within a Grails application

Since:
0.2 Created: 20th June 2006
Author:
Graeme Rocher

Field Summary
static java.util.regex.Pattern[] COMPILER_ROOT_PATTERNS
           
static java.util.regex.Pattern DOMAIN_PATH_PATTERN
           
static java.lang.String GRAILS_APP_DIR
          The name of the Grails application directory
static java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_FIFTH_MATCH
           
static java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_FIRST_MATCH
           
static java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_FOURTH_MATCH
           
static java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_SECOND_MATCH
           
static java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_SIXTH_MATCH
           
static java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_THIRD_MATCH
           
static java.util.regex.Pattern[] patterns
           
static java.util.regex.Pattern RESOURCE_PATH_PATTERN
           
static java.util.regex.Pattern SPRING_SCRIPTS_PATH_PATTERN
           
static java.lang.String VIEWS_DIR_PATH
          The path to the views directory
static java.lang.String WEB_APP_DIR
          The name of the Web app dir within Grails
static java.lang.String WEB_INF
          The relative path to the WEB-INF directory
 
Constructor Summary
GrailsResourceUtils()
           
 
Method Summary
static org.springframework.core.io.Resource getAppDir(org.springframework.core.io.Resource resource)
           
static java.lang.String getClassName(org.springframework.core.io.Resource resource)
          Gets the class name of the specified Grails resource
static java.lang.String getClassName(java.lang.String path)
          Returns the class name for a Grails resource
static java.lang.String getPathFromRoot(java.lang.String path)
          Get the path relative to an artefact folder under grails-app i.e: Input: /usr/joe/project/grails-app/conf/BootStrap.groovy Output: BootStrap.groovy Input: /usr/joe/project/grails-app/domain/com/mystartup/Book.groovy Output: com/mystartup/Book.groovy
static java.lang.String getRelativeInsideWebInf(org.springframework.core.io.Resource resource)
          This method will take a Grails resource (one located inside the grails-app dir) and get its relative path inside the WEB-INF directory when deployed
static java.lang.String getStaticResourcePathForResource(org.springframework.core.io.Resource resource, java.lang.String contextPath)
          Retrieves the static resource path for the given Grails resource artifact (controller/taglib etc.)
static org.springframework.core.io.Resource getViewsDir(org.springframework.core.io.Resource resource)
           
static boolean isDomainClass(java.net.URL url)
          Checks whether the file referenced by the given url is a domain class
static boolean isGrailsPath(java.lang.String path)
          Checks whether the specified path is a Grails path
static boolean isGrailsResource(org.springframework.core.io.Resource r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEB_INF

public static final java.lang.String WEB_INF
The relative path to the WEB-INF directory

See Also:
Constant Field Values

GRAILS_APP_DIR

public static final java.lang.String GRAILS_APP_DIR
The name of the Grails application directory

See Also:
Constant Field Values

WEB_APP_DIR

public static final java.lang.String WEB_APP_DIR
The name of the Web app dir within Grails

See Also:
Constant Field Values

VIEWS_DIR_PATH

public static final java.lang.String VIEWS_DIR_PATH
The path to the views directory

See Also:
Constant Field Values

DOMAIN_PATH_PATTERN

public static java.util.regex.Pattern DOMAIN_PATH_PATTERN

RESOURCE_PATH_PATTERN

public static java.util.regex.Pattern RESOURCE_PATH_PATTERN

SPRING_SCRIPTS_PATH_PATTERN

public static java.util.regex.Pattern SPRING_SCRIPTS_PATH_PATTERN

COMPILER_ROOT_PATTERNS

public static java.util.regex.Pattern[] COMPILER_ROOT_PATTERNS

GRAILS_RESOURCE_PATTERN_FIRST_MATCH

public static final java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_FIRST_MATCH

GRAILS_RESOURCE_PATTERN_SECOND_MATCH

public static final java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_SECOND_MATCH

GRAILS_RESOURCE_PATTERN_THIRD_MATCH

public static final java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_THIRD_MATCH

GRAILS_RESOURCE_PATTERN_FOURTH_MATCH

public static final java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_FOURTH_MATCH

GRAILS_RESOURCE_PATTERN_FIFTH_MATCH

public static final java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_FIFTH_MATCH

GRAILS_RESOURCE_PATTERN_SIXTH_MATCH

public static final java.util.regex.Pattern GRAILS_RESOURCE_PATTERN_SIXTH_MATCH

patterns

public static final java.util.regex.Pattern[] patterns
Constructor Detail

GrailsResourceUtils

public GrailsResourceUtils()
Method Detail

isDomainClass

public static boolean isDomainClass(java.net.URL url)
Checks whether the file referenced by the given url is a domain class

Parameters:
url - The URL instance
Returns:
True if it is a domain class

getClassName

public static java.lang.String getClassName(org.springframework.core.io.Resource resource)
Gets the class name of the specified Grails resource

Parameters:
resource - The Spring Resource
Returns:
The class name or null if the resource is not a Grails class

getClassName

public static java.lang.String getClassName(java.lang.String path)
Returns the class name for a Grails resource

Parameters:
path - The path to check
Returns:
The class name or null if it doesn't exist

isGrailsPath

public static boolean isGrailsPath(java.lang.String path)
Checks whether the specified path is a Grails path

Parameters:
path - The path to check
Returns:
True if it is a Grails path

isGrailsResource

public static boolean isGrailsResource(org.springframework.core.io.Resource r)

getViewsDir

public static org.springframework.core.io.Resource getViewsDir(org.springframework.core.io.Resource resource)

getAppDir

public static org.springframework.core.io.Resource getAppDir(org.springframework.core.io.Resource resource)

getRelativeInsideWebInf

public static java.lang.String getRelativeInsideWebInf(org.springframework.core.io.Resource resource)
This method will take a Grails resource (one located inside the grails-app dir) and get its relative path inside the WEB-INF directory when deployed

Parameters:
resource - The Grails resource, which is a file inside the grails-app dir
Returns:
The relative URL of the file inside the WEB-INF dir at deployment time or null if it cannot be established

getStaticResourcePathForResource

public static java.lang.String getStaticResourcePathForResource(org.springframework.core.io.Resource resource,
                                                                java.lang.String contextPath)
Retrieves the static resource path for the given Grails resource artifact (controller/taglib etc.)

Parameters:
resource - The Resource
contextPath - The additonal context path to prefix
Returns:
The resource path

getPathFromRoot

public static java.lang.String getPathFromRoot(java.lang.String path)
Get the path relative to an artefact folder under grails-app i.e: Input: /usr/joe/project/grails-app/conf/BootStrap.groovy Output: BootStrap.groovy Input: /usr/joe/project/grails-app/domain/com/mystartup/Book.groovy Output: com/mystartup/Book.groovy

Parameters:
path - The path to evaluate
Returns:
The path relative to the root folder grails-app


Copyright (c) 2005-2006 The Grails project