From: <cs...@us...> - 2010-01-14 17:45:43
|
Revision: 1641 http://openutils.svn.sourceforge.net/openutils/?rev=1641&view=rev Author: cstrap Date: 2010-01-14 17:45:36 +0000 (Thu, 14 Jan 2010) Log Message: ----------- MgnlUtilsElFunction: - getLink: return a cleaned url (accept uuid, internal link, http link and a generic strings) 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-14 17:44:47 UTC (rev 1640) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-14 17:45:36 UTC (rev 1641) @@ -6,6 +6,7 @@ import info.magnolia.cms.core.Path; import info.magnolia.cms.core.SystemProperty; import info.magnolia.context.MgnlContext; +import info.magnolia.context.WebContext; import info.magnolia.link.LinkException; import info.magnolia.link.LinkUtil; @@ -169,6 +170,57 @@ return cleanedurl; } + /** + * Parse the string (path or uuid) and return a link. + * @param uuidOrPath url (http:// or internal link or an UUID) + * @return cleaned url (external or internal) + */ + public static String getLink(String uuidOrPath) + { + + String cleanedurl = StringUtils.replace(StringUtils.trim(uuidOrPath), "&", "&"); + String contextPath = ((WebContext) MgnlContext.getInstance()).getContextPath(); + + if (StringUtils.isBlank(cleanedurl)) + { + return contextPath; + } + + if (cleanedurl.startsWith("http") || cleanedurl.startsWith("#")) + { + return cleanedurl; + } + + // Check if there is already an extensions, else add default one + if (cleanedurl.startsWith("/")) + { + cleanedurl = contextPath + cleanedurl; + if (!cleanedurl.endsWith(".html")) + { + return cleanedurl + ".html"; + } + + return cleanedurl; + } + + // uuidOrPath is an UUID, mabye... + try + { + cleanedurl = MgnlContext.getContextPath() + + LinkUtil.convertUUIDtoURI(cleanedurl, ContentRepository.WEBSITE); + } + catch (LinkException e) + { + log.debug("Failed to parse links with from " + + MgnlContext.getAggregationState().getCurrentURI() + + e.getMessage()); + } + + // If got an error return the cleaned string + return cleanedurl; + + } + public static String tolinkOrText(String tabseparatedstring) { 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-14 17:44:47 UTC (rev 1640) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-14 17:45:36 UTC (rev 1641) @@ -92,6 +92,11 @@ <function-signature>java.lang.String encodeISO9075(java.lang.String)</function-signature> </function> <function> + <name>getLink</name> + <function-class>--to be set --</function-class> + <function-signature>java.lang.String getLink(java.lang.String)</function-signature> + </function> + <function> <name>formatDateTime</name> <description> Format a date and time based on a given pattern, or a builtin style (short, medium, long or full). Also supports This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |