From: <fg...@us...> - 2010-01-29 16:51:43
|
Revision: 1714 http://openutils.svn.sourceforge.net/openutils/?rev=1714&view=rev Author: fgiust Date: 2010-01-29 16:51:27 +0000 (Fri, 29 Jan 2010) Log Message: ----------- MGNLUTILS-1 New EL functions for composing absolute URLs Modified Paths: -------------- trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld Modified: trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java =================================================================== --- trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-21 10:49:43 UTC (rev 1713) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-29 16:51:27 UTC (rev 1714) @@ -447,4 +447,59 @@ return list.toArray(new String[0][]); } + /** + * Returns the base URL for the request (scheme + server + port + context path, like http://server:81/context/) + * @return the base URL for the request (scheme + server + port + context path, like http://server:81/context/ + */ + public static String baseUrl() + { + return baseUrlWithoutContextPath() + MgnlContext.getWebContext().getRequest().getContextPath(); + } + + /** + * Returns the base URL for the request without the context path (scheme + server + port, like http://server:81/) + * @return the base URL for the request (scheme + server + port , like http://server:81/ + */ + public static String baseUrlWithoutContextPath() + { + HttpServletRequest request = MgnlContext.getWebContext().getRequest(); + + StringBuffer baseUrl = new StringBuffer(); + baseUrl.append(request.getScheme()); + baseUrl.append("://"); + baseUrl.append(request.getServerName()); + + if (("http".equals(request.getScheme()) && request.getServerPort() != 80) + || ("https".equals(request.getScheme()) && request.getServerPort() != 443)) + { + baseUrl.append(":"); + baseUrl.append(request.getServerPort()); + } + + return baseUrl.toString(); + } + + /** + * Returns the full url to the given content (starting with http) + * @param content magnolia content + * @return the full url to the given content (starting with http) + */ + public static String pageFullUrl(Content content) + { + if (content != null) + { + return baseUrl() + content.getHandle() + ".html"; + } + return null; + } + + /** + * Returns the full url to the current page (starting with http) + * @return the full url to the current page (starting with http) + */ + public static String activePageFullUrl() + { + return baseUrl() + MgnlContext.getAggregationState().getMainContent() + ".html"; + } + } Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-21 10:49:43 UTC (rev 1713) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-29 16:51:27 UTC (rev 1714) @@ -179,4 +179,34 @@ <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String[][] splitAndTokenize(java.lang.String)</function-signature> </function> + <function> + <name>baseUrl</name> + <description> + Returns the base URL for the request (scheme + server + port + context path, like http://server:81/context/) + </description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String baseUrl()</function-signature> + </function> + <function> + <name>baseUrlWithoutContextPath</name> + <description> + Returns the base URL for the request without the context path (scheme + server + port, like http://server:81/) + </description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String baseUrlWithoutContextPath()</function-signature> + </function> + <function> + <name>pageFullUrl</name> + <description> + Returns the full url to the given content (starting with http) + </description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String pageFullUrl(info.magnolia.cms.core.Content)</function-signature> + </function> + <function> + <name>activePageFullUrl</name> + <description>Returns the full url to the current page (starting with http)</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String activePageFullUrl()</function-signature> + </function> </taglib> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |