From: <luc...@us...> - 2010-01-14 16:19:05
|
Revision: 1639 http://openutils.svn.sourceforge.net/openutils/?rev=1639&view=rev Author: lucaboati Date: 2010-01-14 16:18:55 +0000 (Thu, 14 Jan 2010) Log Message: ----------- add encodeISO9075 function 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 16:03:30 UTC (rev 1638) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-14 16:18:55 UTC (rev 1639) @@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; +import org.apache.jackrabbit.util.ISO9075; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -346,4 +347,14 @@ return isStringInSeparatedList(list, value, "\r\n") || isStringInSeparatedList(list, value, "\n"); } + /** + * encode handle for a JackRabbit search + * @param handle the page handle + * @return handle encoded ISO9075 + */ + public static String encodeISO9075(String handle) + { + return ISO9075.encodePath(handle); + } + } 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 16:03:30 UTC (rev 1638) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-14 16:18:55 UTC (rev 1639) @@ -86,6 +86,11 @@ <function-class>--to be set --</function-class> <function-signature>java.lang.String tolinkOrText(java.lang.String)</function-signature> </function> + <function> + <name>encodeISO9075</name> + <function-class>--to be set --</function-class> + <function-signature>java.lang.String encodeISO9075(java.lang.String)</function-signature> + </function> <function> <name>formatDateTime</name> <description> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <fg...@us...> - 2010-01-14 21:15:33
|
Revision: 1642 http://openutils.svn.sourceforge.net/openutils/?rev=1642&view=rev Author: fgiust Date: 2010-01-14 21:15:23 +0000 (Thu, 14 Jan 2010) Log Message: ----------- remove duplicate function (getLink() -> link()) 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:45:36 UTC (rev 1641) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-14 21:15:23 UTC (rev 1642) @@ -6,7 +6,6 @@ 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; @@ -170,57 +169,6 @@ 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:45:36 UTC (rev 1641) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-14 21:15:23 UTC (rev 1642) @@ -92,11 +92,6 @@ <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. |
From: <me...@us...> - 2010-01-15 15:12:25
|
Revision: 1651 http://openutils.svn.sourceforge.net/openutils/?rev=1651&view=rev Author: memila Date: 2010-01-15 15:12:14 +0000 (Fri, 15 Jan 2010) Log Message: ----------- descriptions added 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 14:51:23 UTC (rev 1650) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-15 15:12:14 UTC (rev 1651) @@ -44,9 +44,9 @@ } /** - * return true if exists content + * 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 boolean value + * @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,7 +72,11 @@ 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 + */ public static Content contentByPath(String path, String repository) { try @@ -84,7 +88,10 @@ return null; } } - + /** + * Return a map key=value of all magnolia request attributes + * @return a map key=value of all magnolia request attributes + */ @SuppressWarnings("unchecked") public static Map<String, Object> getRequestAttributeMap() { @@ -102,22 +109,38 @@ return attrs; } - + /** + * Return the message of a given message key + * @param String key + * @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' + */ public static boolean develop() { return SystemProperty.getBooleanProperty("magnolia.develop"); } - + + /** + * @param String uuidOrPath + * @return a link from given a path or a uuid + */ public static String link(String uuidOrPath) { return uuidLink(uuidOrPath); } + + /** + * @param String uuid + * @return a link the ContextPath o '.html' when needed + */ public static String uuidLink(String uuid) { if (StringUtils.isEmpty(uuid)) @@ -220,7 +243,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 + * @return the number of nodes in a collection + */ + public static int countNodesInCollection(Content content, String subnode) { int count = 0; @@ -246,6 +275,11 @@ return count; } + /** + * Count subpages with a given content + * @param Content content + * @return the number of subpages + */ public static int countSubpages(Content content) { int count = 0; @@ -258,6 +292,11 @@ return count; } + /** + * Return the collection of subpages of a given page + * @param Content content + * @return a Collection<Content> of subpages of a given page + */ public static Collection<Content> subpages(Content content) { @@ -273,12 +312,21 @@ { return MgnlContext.getUser().hasRole(role); } - + /** + * Evaluete if primary node type of the associated Node of an object is a mgnl:contentNode + * @param 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 + * @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) { 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 14:51:23 UTC (rev 1650) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-15 15:12:14 UTC (rev 1651) @@ -74,16 +74,19 @@ </function> <function> <name>develop</name> + <description>Test the system property 'magnolia.develop'</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.Boolean develop()</function-signature> </function> <function> <name>uuidlink</name> + <description></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> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String link(java.lang.String)</function-signature> </function> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <me...@us...> - 2010-01-15 15:41:16
|
Revision: 1652 http://openutils.svn.sourceforge.net/openutils/?rev=1652&view=rev Author: memila Date: 2010-01-15 15:41:09 +0000 (Fri, 15 Jan 2010) Log Message: ----------- description added 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:12:14 UTC (rev 1651) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-15 15:41:09 UTC (rev 1652) @@ -192,7 +192,12 @@ } 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 + * @return a link or a text + */ + public static String tolinkOrText(String tabseparatedstring) { @@ -307,7 +312,11 @@ return null; } - + /** + * Return true if the current user has a given role + * @param String role + * @return boolean value + */ public static boolean userInRole(String role) { return MgnlContext.getUser().hasRole(role); 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:12:14 UTC (rev 1651) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-15 15:41:09 UTC (rev 1652) @@ -97,21 +97,25 @@ </function> <function> <name>tolinkOrText</name> + <description>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</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String tolinkOrText(java.lang.String)</function-signature> </function> <function> <name>encodeISO9075</name> - <function-class>--to be set --</function-class> + <description>encode handle for a JackRabbit search</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String encodeISO9075(java.lang.String)</function-signature> </function> <function> <name>userInRole</name> + <description>Return true if the current user has a given role</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.Boolean userInRole(java.lang.String)</function-signature> </function> <function> <name>getValidatedLabel</name> + <description>Retrieve validate label for input string</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String getValidatedLabel(java.lang.String)</function-signature> </function> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <fg...@us...> - 2010-01-21 10:21:03
|
Revision: 1708 http://openutils.svn.sourceforge.net/openutils/?rev=1708&view=rev Author: fgiust Date: 2010-01-21 10:20:56 +0000 (Thu, 21 Jan 2010) Log Message: ----------- spell check + remove duplicate link() methods 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:16:41 UTC (rev 1707) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-01-21 10:20:56 UTC (rev 1708) @@ -65,10 +65,10 @@ /** * Test if exists a parent page with content in the collectionName given as parameter, if exist set the parent page - * a sactpage + * as actpage * @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 + * parent page as actpage */ public static boolean firstPageWithCollection(String collectionName) { @@ -155,33 +155,12 @@ } /** - * Same as tolink() + * 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 link(String uuidOrPathOrUrl) { - return tolink(uuidOrPathOrUrl); - } - - /** - * Same as tolink() - * @param uuidOrPathOrUrl url (http://, internal link, UUID, generic url) - * @return cleaned url (external or internal) - */ - public static String uuidLink(String uuidOrPathOrUrl) - { - 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(); @@ -242,7 +221,7 @@ if (splitted.length > 1) { - String url = tolink(splitted[1]); + String url = link(splitted[1]); boolean external = false; if (splitted.length > 2 && "true".equals(StringUtils.trim(splitted[2]))) @@ -356,7 +335,7 @@ } /** - * Evaluete if primary node type of the associated Node of an object is a mgnl:contentNode + * Evaluates if primary node type of the associated Node of an object is a mgnl:contentNode * @param content Content * @return boolean value */ @@ -406,7 +385,7 @@ /** * splits a list according to a separator and returns true if one of the values equals the input value - * @param list the string to be splitted + * @param list the string to be split * @param value the value to check * @param separator the separator * @return true if the value equals one of the values obtained from splitting the string, false otherwise @@ -452,7 +431,7 @@ /** * Splits the given strings on newline (<code>\n</code>) and after on tabs (<code>\t</code>) Usually used to * retrieve data from a magnolia grid component - * @param string string to be splitted + * @param string string to be split * @return array */ public static String[][] splitAndTokenize(String string) 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:16:41 UTC (rev 1707) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-01-21 10:20:56 UTC (rev 1708) @@ -121,24 +121,12 @@ <function-signature>java.lang.Boolean develop()</function-signature> </function> <function> - <name>uuidlink</name> - <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>Same as tolink</description> + <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 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> - <function> <name>tolinkOrText</name> <description>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</description> <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <lbr...@us...> - 2010-02-04 15:06:47
|
Revision: 1798 http://openutils.svn.sourceforge.net/openutils/?rev=1798&view=rev Author: lbrindisi Date: 2010-02-04 15:06:40 +0000 (Thu, 04 Feb 2010) Log Message: ----------- MGNLUTILS-2 added an El Function which allows to specify a repository for searching an uuid within it 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-02-04 15:04:56 UTC (rev 1797) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-02-04 15:06:40 UTC (rev 1798) @@ -502,4 +502,29 @@ return baseUrl() + MgnlContext.getAggregationState().getMainContent() + ".html"; } + /** + * Returns a link from an uuid. Accepts in input uuid. Returns "#" if provided uuid is not found. + * @param uuid uuid to find + * @param repo repository within search - can be null - default is 'website' + * @return a link from an uuid. + */ + public static String repoUuidLink(String uuid, String repo) + { + String url = "#"; + try + { + url = MgnlContext.getContextPath() + + LinkUtil.convertUUIDtoURI(uuid, StringUtils.isNotBlank(repo) ? repo : ContentRepository.WEBSITE); + } + catch (LinkException e) + { + log.debug("Failed to parse links with from " + + MgnlContext.getAggregationState().getCurrentURI() + + e.getMessage()); + } + + return url; + } + } + Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-02-04 15:04:56 UTC (rev 1797) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-02-04 15:06:40 UTC (rev 1798) @@ -5,7 +5,7 @@ <display-name>Magnolia utility Tags and EL functions</display-name> <tlib-version>1.0</tlib-version> <short-name>mu</short-name> - <uri>mgnlutils</uri> + <uri>mgnlutilscust</uri> <function> <name>firstPageWithCollection</name> <description>Test if exists a parent page with content in the collectionName given as parameter, if exist set the parent page as actpage</description> @@ -209,4 +209,10 @@ <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 + <function> + <name>repoUuidLink</name> + <description>Returns a link from an uuid. Accepts in input uuid.</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String repoUuidLink(java.lang.String, java.lang.String)</function-signature> + </function> +</taglib> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-03-08 13:22:21
|
Revision: 2104 http://openutils.svn.sourceforge.net/openutils/?rev=2104&view=rev Author: diego_schivo Date: 2010-03-08 13:22:12 +0000 (Mon, 08 Mar 2010) Log Message: ----------- MGNLUTILS-5 EL functions: convertToCollection, hasChildWithTitle, contentChildrenOfType 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-03-08 11:22:04 UTC (rev 2103) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-03-08 13:22:12 UTC (rev 2104) @@ -24,6 +24,7 @@ import info.magnolia.cms.core.ItemType; import info.magnolia.cms.core.Path; import info.magnolia.cms.core.SystemProperty; +import info.magnolia.cms.util.NodeMapWrapper; import info.magnolia.context.MgnlContext; import info.magnolia.context.WebContext; import info.magnolia.link.LinkException; @@ -527,4 +528,49 @@ return url; } + /** + * Convert a content list into a collection, also wrapping the content inside a I18NNodeMapWrapper + * @param list the list to be converted + * @return a collection with the user's content + */ + public static List<NodeMapWrapper> convertToCollection(List<Content> list) + { + List<NodeMapWrapper> itemsList = new ArrayList<NodeMapWrapper>(); + Collection<Content> result = list; + for (Content content : result) + { + itemsList.add(new NodeMapWrapper(content, content.getHandle())); + } + return itemsList; + } + + /** + * Check if the content parameter has a child with title equal the title parameter + * @param content + * @param title + * @return + */ + public static Boolean hasChildWithTitle(Content content, String title) + { + for (Content currentChild : content.getChildren()) + { + if (currentChild.getTitle() != null && currentChild.getTitle().equalsIgnoreCase(title)) + { + return true; + } + } + + return false; + } + + /** + * Get child nodes of specified content type and its subtypes + * @param content + * @param contentType + * @return + */ + public static Collection<Content> contentChildrenOfType(Content content, String contentType) + { + return content.getChildren(contentType); + } } Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-03-08 11:22:04 UTC (rev 2103) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-03-08 13:22:12 UTC (rev 2104) @@ -215,4 +215,22 @@ <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.lang.String repoUuidLink(java.lang.String, java.lang.String)</function-signature> </function> + <function> + <name>convertToCollection</name> + <description>Convert a content list into a collection, also wrapping the content inside a I18NNodeMapWrapper</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.util.List convertToCollection(java.util.List)</function-signature> + </function> + <function> + <name>hasChildWithTitle</name> + <description>Check if the content parameter has a child with title equal the title parameter</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.Boolean hasChildWithTitle(info.magnolia.cms.core.Content, java.lang.String)</function-signature> + </function> + <function> + <name>contentChildrenOfType</name> + <description>Get child nodes of specified content type and its subtypes</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.util.Collection contentChildrenOfType(info.magnolia.cms.core.Content, java.lang.String)</function-signature> + </function> </taglib> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-03-08 13:49:20
|
Revision: 2105 http://openutils.svn.sourceforge.net/openutils/?rev=2105&view=rev Author: diego_schivo Date: 2010-03-08 13:49:14 +0000 (Mon, 08 Mar 2010) Log Message: ----------- MGNLUTILS-6 EL functions mapTokens, multiMapTokens 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-03-08 13:22:12 UTC (rev 2104) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-03-08 13:49:14 UTC (rev 2105) @@ -36,6 +36,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; @@ -450,6 +451,67 @@ } /** + * Extracts a map from a bi-dimensional array of strings, getting keys and values from the specified columns + * @param tokens + * @param keyIndex index of the column storing keys + * @param valueIndex index of the column storing values + * @return + */ + public static Map<String, String> mapTokens(String[][] tokens, int keyIndex, int valueIndex) + { + Map<String, String> map = new HashMap<String, String>(tokens.length); + for (String[] row : tokens) + { + if (keyIndex < row.length && valueIndex < row.length) + { + map.put(row[keyIndex], row[valueIndex]); + } + } + return map; + } + + /** + * Same as mapTokens, but the resulting map is multi-value, i.e. the same key can have more than one value. + * Rows having no key specified are considered entries of the last used key. + * @param tokens + * @param keyIndex + * @param valueIndex + * @return + */ + public static Map<String, String[]> multiMapTokens(String[][] tokens, int keyIndex, int valueIndex) + { + Map<String, List<String>> tmpMap = new HashMap<String, List<String>>(); + String currentKey = null; + for (String[] row : tokens) + { + if (keyIndex < row.length && valueIndex < row.length) + { + String key = StringUtils.trimToNull(row[keyIndex]); + if (key == null) + { + key = currentKey; + } + if (key != null) + { + List<String> values = tmpMap.get(key); + if (values == null) + { + values = new ArrayList<String>(); + tmpMap.put(key, values); + } + values.add(row[valueIndex]); + } + } + } + Map<String, String[]> map = new HashMap<String, String[]>(tmpMap.size()); + for (Entry<String, List<String>> entry : tmpMap.entrySet()) + { + map.put(entry.getKey(), entry.getValue().toArray(new String[0])); + } + return map; + } + + /** * 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/ */ Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-03-08 13:22:12 UTC (rev 2104) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-03-08 13:49:14 UTC (rev 2105) @@ -180,6 +180,21 @@ <function-signature>java.lang.String[][] splitAndTokenize(java.lang.String)</function-signature> </function> <function> + <name>mapTokens</name> + <description>Extracts a map from a bi-dimensional array of strings, getting keys and values from the specified columns</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.util.Map mapTokens(java.lang.String[][], int, int)</function-signature> + </function> + <function> + <name>multiMapTokens</name> + <description> + Same as mapTokens, but the resulting map is multi-value, i.e. the same key can have more than one value. + Rows having no key specified are considered entries of the last used key. + </description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.util.Map multiMapTokens(java.lang.String[][], int, int)</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/) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-04-04 17:27:49
|
Revision: 2270 http://openutils.svn.sourceforge.net/openutils/?rev=2270&view=rev Author: fgiust Date: 2010-04-04 17:27:43 +0000 (Sun, 04 Apr 2010) Log Message: ----------- MGNLUTILS-13 new EL function for handling pagination Modified Paths: -------------- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld Added Paths: ----------- trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlPagingElFunctions.java Added: trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlPagingElFunctions.java =================================================================== --- trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlPagingElFunctions.java (rev 0) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlPagingElFunctions.java 2010-04-04 17:27:43 UTC (rev 2270) @@ -0,0 +1,268 @@ +/** + * + * Magnolia generic utilities (http://www.openmindlab.com/lab/products/mgnlutils.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package it.openutils.mgnlutils.el; + +import info.magnolia.context.MgnlContext; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.math.NumberUtils; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + + +/** + * @author fgiust + * @version $Id$ + */ +public class MgnlPagingElFunctions +{ + + /** + * Creates a list of Page objects that can be used to draw a pagination bar. + * @param total total number of pages + * @param visible maximum number of pages to show + * @param param name of the request parameter that will hold the current page number + * @return List of Page objects + */ + public static List<Page> pageList(int total, int visible, String param) + { + + Map<String, String> parameters = MgnlContext.getParameters(); + + StringBuffer sb = new StringBuffer(); + sb.append("?"); + boolean first = true; + for (Map.Entry<String, String> entry : parameters.entrySet()) + { + if (!StringUtils.equals(entry.getKey(), param)) + { + if (!first) + { + sb.append("&"); + } + sb.append(entry.getKey()); + sb.append("="); + sb.append(entry.getValue()); + first = false; + } + } + + if (!first) + { + sb.append("&"); + } + sb.append(param); + sb.append("="); + + String baseUrl = sb.toString(); + + List<Page> result = new ArrayList<Page>(); + + int current = Math.max(1, NumberUtils.toInt(MgnlContext.getParameter(param), 1)); + + // center pages + int start = Math.max(1, Math.min(current - visible / 2, total - visible + 1)); + int end = Math.min(start + visible, total); + + Page page = new Page(1, current == 1, baseUrl); + page.setLabel("««"); + page.setActive(current != 1); + result.add(page); + page.setCssclass("page-first"); + + int previous = Math.max(current - 1, 1); + page = new Page(previous, current == previous, baseUrl); + page.setLabel("«"); + page.setActive(current != previous); + result.add(page); + page.setCssclass("page-previous"); + + for (int j = start; j <= end; j++) + { + page = new Page(j, current == j, baseUrl); + page.setLabel(Integer.toString(j)); + page.setCssclass("page-numbered"); + result.add(page); + } + + int next = Math.min(current + 1, total); + page = new Page(next, current == next, baseUrl); + page.setLabel("»"); + page.setActive(current != next); + page.setCssclass("page-next"); + result.add(page); + + page = new Page(total, current == total, baseUrl); + page.setLabel("»»"); + page.setActive(current != total); + page.setCssclass("page-last"); + result.add(page); + + return result; + } + + public static class Page + { + + private int number; + + boolean current; + + private String url; + + private String label; + + private boolean active; + + private String cssclass; + + /** + * @param number + * @param active + * @param baseurl + */ + public Page(int number, boolean current, String baseurl) + { + this.number = number; + this.current = current; + this.url = baseurl; + active = true; + } + + /** + * Returns the number. + * @return the number + */ + public int getNumber() + { + return number; + } + + /** + * Sets the number. + * @param number the number to set + */ + public void setNumber(int number) + { + this.number = number; + } + + /** + * Returns the current. + * @return the current + */ + public boolean isCurrent() + { + return current; + } + + /** + * Sets the current. + * @param current the current to set + */ + public void setCurrent(boolean current) + { + this.current = current; + } + + /** + * Returns the url. + * @return the url + */ + public String getUrl() + { + return url + this.number; + } + + /** + * Returns the label. + * @return the label + */ + public String getLabel() + { + return label; + } + + /** + * Sets the label. + * @param label the label to set + */ + public void setLabel(String label) + { + this.label = label; + } + + /** + * Returns the active. + * @return the active + */ + public boolean isActive() + { + return active; + } + + /** + * Sets the active. + * @param active the active to set + */ + public void setActive(boolean active) + { + this.active = active; + } + + /** + * Returns the cssclass. + * @return the cssclass + */ + public String getCssclass() + { + return cssclass; + } + + /** + * Sets the cssclass. + * @param cssclass the cssclass to set + */ + public void setCssclass(String cssclass) + { + this.cssclass = cssclass; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() + { + return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE) + .append("number", this.number) + .append("url", this.url) + .append("active", this.active) + .append("current", this.current) + .append("label", this.label) + .append("cssclass", this.cssclass) + .toString(); + } + } +} Property changes on: trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlPagingElFunctions.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-04-04 17:12:44 UTC (rev 2269) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-04-04 17:27:43 UTC (rev 2270) @@ -248,4 +248,21 @@ <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.util.Collection contentChildrenOfType(info.magnolia.cms.core.Content, java.lang.String)</function-signature> </function> -</taglib> + <function> + <name>pageList</name> + <description>Creates a list of Page objects that can be used to draw a pagination bar. + Takes as parameters the total number of pages, the maximum number of pages to show and the name of the request parameter that will hold the current page number</description> + <function-class>it.openutils.mgnlutils.el.MgnlPagingElFunctions</function-class> + <function-signature>java.util.List pageList(int, int, java.lang.String)</function-signature> + <example><![CDATA[ + <c:set var="pageList" value="${mu:pageList(numPages, maxPages, 'page')}" /> + <ul class="paging"> + <c:forEach var="page" items="${pageList}"> + <li class="page-current-${page.current} page-active-${page.active} ${page.cssclass}"> + <a href="${page.url}">${page.label}</a> + </li> + </c:forEach> + </ul> + ]]></example> + </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. |
From: <fg...@us...> - 2010-04-05 14:18:52
|
Revision: 2276 http://openutils.svn.sourceforge.net/openutils/?rev=2276&view=rev Author: fgiust Date: 2010-04-05 14:18:42 +0000 (Mon, 05 Apr 2010) Log Message: ----------- MGNLUTILS-14 new EL toAbsoluteUrl() 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-04-05 13:51:54 UTC (rev 2275) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-04-05 14:18:42 UTC (rev 2276) @@ -471,8 +471,8 @@ } /** - * Same as mapTokens, but the resulting map is multi-value, i.e. the same key can have more than one value. - * Rows having no key specified are considered entries of the last used key. + * Same as mapTokens, but the resulting map is multi-value, i.e. the same key can have more than one value. Rows + * having no key specified are considered entries of the last used key. * @param tokens * @param keyIndex * @param valueIndex @@ -521,6 +521,28 @@ } /** + * Convert a relative url to absolute, using the current base url. If the link is already absolute it will not be + * altered. + * @param relativeOrAbsolute input url, considered absolute if it contains the protocol separator ("://") + * @return absolute url + */ + public static String toAbsoluteUrl(String relativeOrAbsolute) + { + if (StringUtils.isBlank(relativeOrAbsolute)) + { + return relativeOrAbsolute; + } + + // check for :// after protocol + if (StringUtils.contains(StringUtils.substring(relativeOrAbsolute, 0, 10), "://")) + { + return relativeOrAbsolute; + } + + return baseUrl() + relativeOrAbsolute; + } + + /** * 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/ */ Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-04-05 13:51:54 UTC (rev 2275) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-04-05 14:18:42 UTC (rev 2276) @@ -219,6 +219,14 @@ <function-signature>java.lang.String pageFullUrl(info.magnolia.cms.core.Content)</function-signature> </function> <function> + <name>toAbsoluteUrl</name> + <description> + Convert a relative url to absolute, using the current base url. If the link is already absolute it will not be altered. + </description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String toAbsoluteUrl(java.lang.String)</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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-05-12 15:01:42
|
Revision: 2413 http://openutils.svn.sourceforge.net/openutils/?rev=2413&view=rev Author: fgiust Date: 2010-05-12 15:01:36 +0000 (Wed, 12 May 2010) Log Message: ----------- MGNLUTILS-20 New EL functions for building a query string including/excluding a set of parameters 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-05-12 15:01:24 UTC (rev 2412) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2010-05-12 15:01:36 UTC (rev 2413) @@ -30,6 +30,8 @@ import info.magnolia.link.LinkException; import info.magnolia.link.LinkUtil; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; @@ -41,6 +43,7 @@ import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.util.ISO9075; import org.slf4j.Logger; @@ -657,4 +660,93 @@ { return content.getChildren(contentType); } + + /** + * Builds a query string with the actual request parameters, optionally excluding a list of parameters. + * @param excludedParamsWhitespaceSeparated list of parameters to exclude, in a single whitespace separated string + * @return queryString, without the leading "?" and with parameters already urlencoded (but with ampersands not html + * escaped) + */ + public static String buildQuerystringExcluding(String excludedParamsWhitespaceSeparated) + { + return buildQuerystringInternal(StringUtils.split( + StringUtils.defaultString(excludedParamsWhitespaceSeparated), + ' '), new String[0]); + } + + /** + * Builds a query string with the actual request parameters, optionally excluding a list of parameters + * @param includedParamsWhitespaceSeparated list of parameters to include, in a single whitespace separated string + * @return queryString, without the leading "?" and with parameters already urlencoded (but with ampersands not html + * escaped) + */ + public static String buildQuerystringIncluding(String includedParamsWhitespaceSeparated) + { + return buildQuerystringInternal(new String[0], StringUtils.split(StringUtils + .defaultString(includedParamsWhitespaceSeparated), ' ')); + } + + /** + * @param excluded + * @return + */ + private static String buildQuerystringInternal(String[] excluded, String[] included) + { + Map<String, String> parameters = MgnlContext.getParameters(); + StringBuffer sb = new StringBuffer(); + + boolean first = true; + + for (Map.Entry<String, String> entry : parameters.entrySet()) + { + String key = entry.getKey(); + if (!ArrayUtils.contains(excluded, key) + && (included == null || included.length == 0 || ArrayUtils.contains(included, key))) + { + if (!first) + { + sb.append("&"); + } + + String[] parameterValues = MgnlContext.getParameterValues(key); + + if (parameterValues != null) + { + for (int j = 0; j < parameterValues.length; j++) + { + String value = parameterValues[j]; + sb.append(urlencode(key)); + sb.append("="); + sb.append(urlencode(value)); + if (j + 1 < parameterValues.length) + { + sb.append("&"); + } + } + } + + first = false; + } + } + + return sb.toString(); + } + + /** + * Encodes a url in UTF-8 format + * @param string url to be encoded + * @return a url UTF-8 encoded + */ + private static String urlencode(String string) + { + try + { + return URLEncoder.encode(string, "UTF-8"); + } + catch (UnsupportedEncodingException e) + { + // should never happen + return string; + } + } } Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-05-12 15:01:24 UTC (rev 2412) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2010-05-12 15:01:36 UTC (rev 2413) @@ -273,4 +273,18 @@ </ul> ]]></example> </function> + <function> + <name>buildQuerystringExcluding</name> + <description>Builds a query string with the actual request parameters, optionally excluding a list of parameters. The list list of parameters to exclude in given as a single whitespace separated string. + The returned querystring doesn't contain the leading "?" and has all the parameters already urlencoded (but with ampersands not html escaped)</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.util.String buildQuerystringExcluding(java.lang.String)</function-signature> + </function> + <function> + <name>buildQuerystringIncluding</name> + <description>Builds a query string with the actual request parameters, only including the given list of parameters. The list list of parameters to include in given as a single whitespace separated string. + The returned querystring doesn't contain the leading "?" and has all the parameters already urlencoded (but with ampersands not html escaped)</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.util.String buildQuerystringIncluding(java.lang.String)</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. |
From: <die...@us...> - 2011-02-09 07:55:33
|
Revision: 3325 http://openutils.svn.sourceforge.net/openutils/?rev=3325&view=rev Author: diego_schivo Date: 2011-02-09 07:55:26 +0000 (Wed, 09 Feb 2011) Log Message: ----------- MGNLUTILS-25 EL function returning a content given a UUID/path/content 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 2011-02-08 18:09:30 UTC (rev 3324) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2011-02-09 07:55:26 UTC (rev 3325) @@ -22,10 +22,12 @@ import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.beans.config.ServerConfiguration; import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.ItemType; import info.magnolia.cms.core.Path; import info.magnolia.cms.core.SystemProperty; import info.magnolia.cms.i18n.I18nContentSupportFactory; +import info.magnolia.cms.i18n.I18nContentWrapper; import info.magnolia.cms.util.NodeMapWrapper; import info.magnolia.context.MgnlContext; import info.magnolia.context.WebContext; @@ -42,6 +44,7 @@ import java.util.Map; import java.util.Map.Entry; +import javax.jcr.ItemNotFoundException; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; @@ -767,4 +770,86 @@ return string; } } + + /** + * @param obj + * @param repo + * @return + */ + public static Content content(Object obj, String repo) + { + if (obj == null) + { + return null; + } + + Content content = null; + + if (obj instanceof String) + { + String mediaIdentifier = (String) obj; + + if (StringUtils.isBlank(mediaIdentifier)) + { + return null; + } + + HierarchyManager hm = MgnlContext.getHierarchyManager(repo); + try + { + if (mediaIdentifier.startsWith("/")) + { + if (hm.isExist(mediaIdentifier)) + { + content = hm.getContent(mediaIdentifier); + } + } + else + { + content = hm.getContentByUUID(StringUtils.trim(mediaIdentifier)); + } + } + catch (ItemNotFoundException e) + { + log.debug("Node \"" + mediaIdentifier + "\" not found"); + } + catch (RepositoryException e) + { + log.error(e.getClass().getName() + " getting node \"" + mediaIdentifier + "\"", e); + } + } + else if (obj instanceof Content) + { + content = (Content) obj; + } + + return content; + } + + /** + * @param obj + * @param repo + * @return + */ + public static NodeMapWrapper node(Object obj, String repo) + { + Content content = content(obj, repo); + + NodeMapWrapper node = null; + if (content instanceof NodeMapWrapper) + { + node = (NodeMapWrapper) content; + } + else if (content != null) + { + Content currentpage = MgnlContext.getAggregationState().getMainContent(); + if (currentpage == null) + { + currentpage = content; + } + node = new NodeMapWrapper(new I18nContentWrapper(content), currentpage.getHandle()); + } + + return node; + } } Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2011-02-08 18:09:30 UTC (rev 3324) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2011-02-09 07:55:26 UTC (rev 3325) @@ -289,4 +289,16 @@ <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.util.String buildQuerystringIncluding(java.lang.String)</function-signature> </function> + <function> + <description></description> + <name>content</name> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>info.magnolia.cms.core.Content content(java.lang.Object, java.lang.String)</function-signature> + </function> + <function> + <description></description> + <name>node</name> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>info.magnolia.cms.util.NodeMapWrapper node(java.lang.Object, java.lang.String)</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. |
From: <fg...@us...> - 2011-06-23 10:46:15
|
Revision: 3553 http://openutils.svn.sourceforge.net/openutils/?rev=3553&view=rev Author: fgiust Date: 2011-06-23 10:46:09 +0000 (Thu, 23 Jun 2011) Log Message: ----------- MGNLUTILS-30 new EL functions for reading user properties 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 2011-06-23 10:29:24 UTC (rev 3552) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2011-06-23 10:46:09 UTC (rev 3553) @@ -29,24 +29,31 @@ import info.magnolia.cms.i18n.I18nContentSupportFactory; import info.magnolia.cms.i18n.I18nContentWrapper; import info.magnolia.cms.i18n.MessagesManager; +import info.magnolia.cms.security.User; +import info.magnolia.cms.security.auth.Entity; import info.magnolia.cms.util.NodeMapWrapper; import info.magnolia.context.MgnlContext; import info.magnolia.context.WebContext; +import info.magnolia.jaas.principal.EntityImpl; import info.magnolia.link.LinkException; import info.magnolia.link.LinkUtil; import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import javax.jcr.ItemNotFoundException; import javax.jcr.RepositoryException; +import javax.security.auth.Subject; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.ArrayUtils; @@ -870,4 +877,62 @@ return node; } + + /** + * Get a user property calling MgnlContext.getUser().getProperty(property) + * @param property property name + * @return + */ + public static Object userPropertyCurrent(String property) + { + return MgnlContext.getUser().getProperty(property); + } + + /** + * Get a user property calling getProperty(property) on the given User object. + * @param user info.magnolia.cms.security.User instance + * @param property property name + * @return + */ + public static Object userProperty(User user, String property) + { + if (user == null) + { + return null; + } + return user.getProperty(property); + } + + /** + * Returns a Map with all the properties of the current user, taken from the current jaas Principal (note: this uses + * info.magnolia.jaas.principal.EntityImpl internals) + * @return + */ + @SuppressWarnings("unchecked") + public static Map<String, Object> userProperties() + { + Subject subject = MgnlContext.getUser().getSubject(); + + Set<Entity> principalDetails = subject.getPrincipals(Entity.class); + Iterator<Entity> entityIterator = principalDetails.iterator(); + Entity userDetails = entityIterator.next(); + + if (userDetails instanceof EntityImpl) + { + try + { + Field properties = userDetails.getClass().getDeclaredField("properties"); + properties.setAccessible(true); + Object value = properties.get(userDetails); + return (Map<String, Object>) value; + } + catch (Exception e) + { + log.error(e.getMessage(), e); + } + } + + return null; + } + } Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2011-06-23 10:29:24 UTC (rev 3552) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2011-06-23 10:46:09 UTC (rev 3553) @@ -307,4 +307,25 @@ <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>info.magnolia.cms.util.NodeMapWrapper node(java.lang.Object, java.lang.String)</function-signature> </function> + <function> + <description>Get a user property calling MgnlContext.getUser().getProperty(propertyname)</description> + <name>userPropertyCurrent</name> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String userPropertyCurrent(java.lang.String)</function-signature> + </function> + <function> + <description>Get a user property calling getProperty(property) on the given User object. Params: instance of info.magnolia.cms.security.User, property key</description> + <name>userProperty</name> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String userProperty(info.magnolia.cms.security.User, java.lang.String)</function-signature> + </function> + <function> + <description>Returns a Map with all the properties of the current user, taken from the current jaas Principal (note: this uses info.magnolia.jaas.principal.EntityImpl internals)</description> + <display-name>userProperties</display-name> + <name>userProperties</name> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.util.Map userProperties()</function-signature> + </function> + + <!-- please don't add new funtions without a meaningfull <description> --> </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. |
From: <fg...@us...> - 2011-08-08 10:49:24
|
Revision: 3588 http://openutils.svn.sourceforge.net/openutils/?rev=3588&view=rev Author: fgiust Date: 2011-08-08 10:49:18 +0000 (Mon, 08 Aug 2011) Log Message: ----------- a couple of useful EL functions 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 2011-08-08 10:42:46 UTC (rev 3587) +++ trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2011-08-08 10:49:18 UTC (rev 3588) @@ -935,4 +935,51 @@ return null; } + /** + * Returns the value of a page property, by iterating on active page ancestor till a value is found + * @param property property name + * @return property value + */ + public static String pagePropertyInherited(String property) + { + Content content = MgnlContext.getAggregationState().getMainContent(); + + try + { + while (content.getLevel() >= 1) + { + String value = content.getNodeData(property).getString(); + + if (!StringUtils.isEmpty(value)) + { + return value; + } + + content = content.getParent(); + } + } + catch (RepositoryException e) + { + log.warn(e.getClass().getName() + + " caught while reading property " + + property + + " from " + + MgnlContext.getAggregationState().getMainContent().getHandle()); + } + + return null; + } + + /** + * Sets the given content as the active page, calling MgnlContext.getAggregationState().setCurrentContent) + * @param content current content to set + */ + public static void setActivePage(Content content) + { + if (content != null) + { + MgnlContext.getAggregationState().setCurrentContent(content); + } + } + } Modified: trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld =================================================================== --- trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2011-08-08 10:42:46 UTC (rev 3587) +++ trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2011-08-08 10:49:18 UTC (rev 3588) @@ -326,6 +326,17 @@ <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> <function-signature>java.util.Map userProperties()</function-signature> </function> - + <function> + <name>pagePropertyInherited</name> + <description>Returns the value of a page property, by iterating on active page ancestor till a value is found</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>java.lang.String pagePropertyInherited( java.lang.String)</function-signature> + </function> + <function> + <name>setActivePage</name> + <description>Sets the given content as the active page, calling MgnlContext.getAggregationState().setCurrentContent)</description> + <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class> + <function-signature>void setActivePage(info.magnolia.cms.core.Content)</function-signature> + </function> <!-- please don't add new funtions without a meaningfull <description> --> </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. |