From: <cs...@us...> - 2010-01-15 17:16:29
|
Revision: 1654 http://openutils.svn.sourceforge.net/openutils/?rev=1654&view=rev Author: cstrap Date: 2010-01-15 17:16:18 +0000 (Fri, 15 Jan 2010) Log Message: ----------- Fix splitAndTokenize Improve tolink() method tld descriptions 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-15 15:41:45 UTC (rev 1653) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-15 17:16:18 UTC (rev 1654) @@ -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; @@ -44,9 +45,11 @@ } /** - * Test if exists a parent page with content in the collectionName given as parameter, if exist set the parent page a sactpage + * Test if exists a parent page with content in the collectionName given as parameter, if exist set the parent page + * a sactpage * @param collectionName (column) of magnolia contentNode - * @return true if exists a parent page with content in the collectionName given as parameter, if exist set the parent page a sactpage + * @return true if exists a parent page with content in the collectionName given as parameter, if exist set the + * parent page a sactpage */ public static boolean firstPageWithCollection(String collectionName) { @@ -72,10 +75,12 @@ return false; } + /** * Return the content of a given path and repository - * @param String path, String repository - * @return the content of a given path and repository + * @param path content path + * @param repository repository type + * @return the content of a given path and repository */ public static Content contentByPath(String path, String repository) { @@ -88,6 +93,7 @@ return null; } } + /** * Return a map key=value of all magnolia request attributes * @return a map key=value of all magnolia request attributes @@ -109,15 +115,17 @@ return attrs; } + /** * Return the message of a given message key - * @param String key + * @param key string * @return return the message string of a given message key */ public static String message(String key) { return MgnlContext.getMessages().get(key); } + /** * Test the system property 'magnolia.develop' * @return true if the system property = 'magnolia.develop' @@ -126,48 +134,65 @@ { return SystemProperty.getBooleanProperty("magnolia.develop"); } - + /** - * @param String uuidOrPath - * @return a link from given a path or a uuid + * Same as tolink() + * @param uuidOrPathOrUrl url (http://, internal link, UUID, generic url) + * @return cleaned url (external or internal) */ - public static String link(String uuidOrPath) + public static String link(String uuidOrPathOrUrl) { - return uuidLink(uuidOrPath); + return tolink(uuidOrPathOrUrl); } - /** - * @param String uuid - * @return a link the ContextPath o '.html' when needed + * Same as tolink() + * @param uuidOrPathOrUrl url (http://, internal link, UUID, generic url) + * @return cleaned url (external or internal) */ - public static String uuidLink(String uuid) + public static String uuidLink(String uuidOrPathOrUrl) { - if (StringUtils.isEmpty(uuid)) + return tolink(uuidOrPathOrUrl); + + } + + /** + * Parse uuidOrPathOrUrl string and return a url. + * @param uuidOrPathOrUrl url (http://, internal link, UUID, generic url) + * @return cleaned url (external or internal) + */ + public static String tolink(String uuidOrPathOrUrl) + { + String cleanedurl = StringUtils.replace(StringUtils.trim(uuidOrPathOrUrl), "&", "&"); + String contextPath = ((WebContext) MgnlContext.getInstance()).getContextPath(); + + if (StringUtils.isBlank(cleanedurl)) { - return null; + return contextPath; } - // not an uuid links - if (StringUtils.startsWith(uuid, "/")) + if (cleanedurl.startsWith("http") || cleanedurl.startsWith("#")) { - String url = MgnlContext.getContextPath() + uuid; - if (!url.endsWith(".html")) + return cleanedurl; + } + + // Check if there is already an extensions, else add default one + if (cleanedurl.startsWith("/")) + { + cleanedurl = contextPath + cleanedurl; + if (!cleanedurl.endsWith(".html")) { - return url + ".html"; + return cleanedurl + ".html"; } - return url; + return cleanedurl; } - if (StringUtils.startsWith(uuid, "http")) - { - return uuid; - } - String value = null; + // Check if uuidOrPathOrUrl is an UUID try { - value = MgnlContext.getContextPath() + LinkUtil.convertUUIDtoURI(uuid, ContentRepository.WEBSITE); + cleanedurl = MgnlContext.getContextPath() + + LinkUtil.convertUUIDtoURI(cleanedurl, ContentRepository.WEBSITE); } catch (LinkException e) { @@ -175,29 +200,17 @@ + MgnlContext.getAggregationState().getCurrentURI() + e.getMessage()); } - return value; - } - public static String tolink(String url) - { - String cleanedurl = StringUtils.replace(StringUtils.trim(url), "&", "&"); - if (cleanedurl != null && cleanedurl.startsWith("http")) - { - return cleanedurl; - } - - if (StringUtils.isNotBlank(cleanedurl)) - { - cleanedurl = MgnlContext.getContextPath() + cleanedurl; - } + // If got an error return the cleaned string return cleanedurl; } + /** - * Create an html complete link from a string composed by link \t link text. If the link is empty the function return only the text - * @param String tabseparatedstring + * Create an html complete link from a string composed by link \t link text. If the link is empty the function + * return only the text + * @param tabseparatedstring string * @return a link or a text */ - public static String tolinkOrText(String tabseparatedstring) { @@ -248,13 +261,13 @@ return splitted[0]; } } - + /** * Count the nodes in a collection with a given content and the name of the collection - * @param Content content, String subnode + * @param content Content + * @param subnode String * @return the number of nodes in a collection */ - public static int countNodesInCollection(Content content, String subnode) { int count = 0; @@ -282,7 +295,7 @@ /** * Count subpages with a given content - * @param Content content + * @param content Content * @return the number of subpages */ public static int countSubpages(Content content) @@ -299,7 +312,7 @@ /** * Return the collection of subpages of a given page - * @param Content content + * @param content Content * @return a Collection<Content> of subpages of a given page */ public static Collection<Content> subpages(Content content) @@ -312,28 +325,30 @@ return null; } + /** * Return true if the current user has a given role - * @param String role + * @param role String * @return boolean value */ public static boolean userInRole(String role) { return MgnlContext.getUser().hasRole(role); } + /** * Evaluete if primary node type of the associated Node of an object is a mgnl:contentNode - * @param content + * @param content Content * @return boolean value */ public static boolean isPage(Content content) { return content != null && !content.isNodeType(ItemType.CONTENTNODE.getSystemName()); } - + /** * Return the Content of the object passed or of the first parent page that has content type = mgnl:content - * @param Content content + * @param content Content * @return the Content of the object passed or of the first parent page that has content type = mgnl:content */ public static Content getPage(Content content) @@ -428,7 +443,7 @@ { if (StringUtils.isNotBlank(line)) { - list.add(StringUtils.splitPreserveAllTokens(string, '\t')); + list.add(StringUtils.splitPreserveAllTokens(line, '\t')); } } return list.toArray(new String[0][]); 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-15 15:41:45 UTC (rev 1653) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-15 17:16:18 UTC (rev 1654) @@ -80,18 +80,19 @@ </function> <function> <name>uuidlink</name> - <description></description> + <description>Same as tolink</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String uuidLink(java.lang.String)</function-signature> </function> <function> <name>link</name> - <description></description> + <description>Same as tolink</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String link(java.lang.String)</function-signature> </function> <function> <name>tolink</name> + <description>Return a cleaned url (external or internal with contextPath). Accept in input generic string, url, uuid.</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String tolink(java.lang.String)</function-signature> </function> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |