From: <fg...@us...> - 2010-04-25 17:35:31
|
Revision: 2301 http://openutils.svn.sourceforge.net/openutils/?rev=2301&view=rev Author: fgiust Date: 2010-04-25 17:35:25 +0000 (Sun, 25 Apr 2010) Log Message: ----------- MEDIA-128 Use the standard I18nContentSupport for i18n Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java 2010-04-25 17:21:10 UTC (rev 2300) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java 2010-04-25 17:35:25 UTC (rev 2301) @@ -23,7 +23,9 @@ import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.i18n.I18nContentWrapper; import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.cms.util.NodeMapWrapper; import info.magnolia.context.MgnlContext; import info.magnolia.module.ModuleRegistry; @@ -94,6 +96,9 @@ { return null; } + + Content content = null; + if (obj instanceof String) { String mediaIdentifier = (String) obj; @@ -110,12 +115,12 @@ { if (hm.isExist(mediaIdentifier)) { - return hm.getContent(mediaIdentifier); + content = hm.getContent(mediaIdentifier); } } else { - return hm.getContentByUUID(StringUtils.trim(mediaIdentifier)); + content = hm.getContentByUUID(StringUtils.trim(mediaIdentifier)); } } catch (ItemNotFoundException e) @@ -129,9 +134,18 @@ } else if (obj instanceof Content) { - return (Content) obj; + content = (Content) obj; } - return null; + + if (!(content instanceof NodeMapWrapper)) + { + content = new NodeMapWrapper(new I18nContentWrapper(content), MgnlContext + .getAggregationState() + .getMainContent() + .getHandle()); + } + + return content; } /** @@ -140,9 +154,15 @@ * @param media media * @param locale language * @return description + * @deprecated use the standard Magnolia i18nContentSupport for this. Please note that versions < 4.2 of the media + * module used PROPERTY-language instead of PROPERTY_languaga which is now the magnolia standard so you may need to + * adapt existing repositories */ + @Deprecated public static String descLoc(Content media, Locale locale) { + log.warn("\"descLoc()\" has been deprecated, please check javadocs"); + if (media == null) { return null; @@ -160,24 +180,20 @@ } /** - * Get description for a media - * @param media media - * @return description - */ - public static String desc(Content media) - { - return descLoc(media, null); - } - - /** * Get localized title for a media. If the locale is "it", it searches for a nodedata called title-it, or (if not * found) title-en or (if not found) title. * @param media media * @param locale language * @return title + * @deprecated use the standard Magnolia i18nContentSupport for this. Please note that versions < 4.2 of the media + * module used PROPERTY-language instead of PROPERTY_languaga which is now the magnolia standard so you may need to + * adapt existing repositories */ + @Deprecated public static String titleLoc(Content media, Locale locale) { + log.warn("\"titleLoc()\" has been deprecated, please check javadocs"); + if (media == null) { return null; @@ -195,24 +211,20 @@ } /** - * Get title for a media - * @param media media - * @return title - */ - public static String title(Content media) - { - return titleLoc(media, null); - } - - /** * Get localized tags for a media. If the locale is "it", it searches for a nodedata called tags-it, or (if not * found) tags-en or (if not found) tags. * @param media media * @param locale language * @return tags + * @deprecated use the standard Magnolia i18nContentSupport for this. Please note that versions < 4.2 of the media + * module used PROPERTY-language instead of PROPERTY_languaga which is now the magnolia standard so you may need to + * adapt existing repositories */ + @Deprecated public static String[] tagsLoc(Content media, Locale locale) { + log.warn("\"tagsLoc()\" has been deprecated, please check javadocs"); + if (media == null) { return null; @@ -236,12 +248,44 @@ } /** + * Get description for a media for the current locale. + * @param media media + * @return description + * @deprecated use media.getNodeData("description") or ${media.description} + */ + @Deprecated + public static String desc(Content media) + { + log.warn("\"desc()\" has been deprecated, please check javadocs"); + + return descLoc(media, null); + } + + /** + * Get title for a media for the current locale. + * @param media media + * @return title + * @deprecated use media.getNodeData("title") or ${media.title} + */ + @Deprecated + public static String title(Content media) + { + log.warn("\"title()\" has been deprecated, please check javadocs"); + + return titleLoc(media, null); + } + + /** * Get tags for a media * @param media media * @return tags + * @deprecated use media.getNodeData("tags") or ${media.tags} */ + @Deprecated public static String[] tags(Content media) { + log.warn("\"tags()\" has been deprecated, please check javadocs"); + return tagsLoc(media, null); } Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java 2010-04-25 17:21:10 UTC (rev 2300) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java 2010-04-25 17:35:25 UTC (rev 2301) @@ -24,19 +24,25 @@ import info.magnolia.cms.beans.runtime.MultipartForm; import info.magnolia.cms.core.Content; import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.i18n.I18nContentSupport; +import info.magnolia.cms.i18n.I18nContentSupportFactory; import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.cms.util.NodeDataUtil; import info.magnolia.context.MgnlContext; import info.magnolia.module.admininterface.SaveHandlerImpl; import java.io.File; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import javax.jcr.PropertyType; import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.ValueFormatException; import javax.servlet.http.HttpServletRequest; import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; @@ -226,52 +232,11 @@ } /** - * Get the nodedata value for a given name and current locale searching first for [propertyname]-[lang]_[COUNTRY] - * then for [propertyname]-[lang] then for [propertyname]-en then for [propertyname].<br /> - * i.e for the property title and for a locale it,IT: - * <ol> - * <li>search for nodedata "title-it_IT"</li> - * <li>search for nodedata "title-it"</li> - * <li>search for nodedata "title-en"</li> - * <li>search for nodedata "title"</li> - * </ol> - * @param media media - * @param property base property name - * @return nodedata value for a given name and current locale - */ - protected String getPropertyLocalized(Content media, String property) - { - Locale locale = MgnlContext.getLocale(); - String language = locale.getLanguage().toLowerCase(); - String languageCountry = language + "_" + locale.getCountry().toLowerCase(); - try - { - if (media.hasNodeData(property + "-" + languageCountry)) - { - return NodeDataUtil.getString(media, property + "-" + languageCountry); - } - else if (media.hasNodeData(property + "-" + language)) - { - return NodeDataUtil.getString(media, property + "-" + language); - } - else if (media.hasNodeData(property + "-en")) - { - return NodeDataUtil.getString(media, property + "-" + language); - } - } - catch (RepositoryException ex) - { - log.error(ex.getMessage(), ex); - } - return NodeDataUtil.getString(media, property); - } - - /** * {@inheritDoc} */ public String getTitle(Content media) { - return getPropertyLocalized(media, "title"); + return I18nContentSupportFactory.getI18nSupport().getNodeData(media, "title").getString(); } /** @@ -279,7 +244,7 @@ */ public String getTags(Content media) { - return getPropertyLocalized(media, "tags"); + return I18nContentSupportFactory.getI18nSupport().getNodeData(media, "tags").getString(); } /** @@ -287,7 +252,7 @@ */ public String getDescription(Content media) { - return getPropertyLocalized(media, "description"); + return I18nContentSupportFactory.getI18nSupport().getNodeData(media, "description").getString(); } /** @@ -295,7 +260,7 @@ */ public String getAbstract(Content media) { - return getPropertyLocalized(media, "abstract"); + return I18nContentSupportFactory.getI18nSupport().getNodeData(media, "abstract").getString(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |