From: <fg...@us...> - 2010-05-02 17:30:27
|
Revision: 2331 http://openutils.svn.sourceforge.net/openutils/?rev=2331&view=rev Author: fgiust Date: 2010-05-02 17:30:21 +0000 (Sun, 02 May 2010) Log Message: ----------- MEDIA-113 cleaning up DialogSelectMedia before adding support for existing binary properties Modified Paths: -------------- trunk/openutils-mgnlmedia/pom.xml trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java trunk/openutils-mgnlmedia/src/main/resources/META-INF/tags/media/media.tag trunk/openutils-mgnlmedia/src/main/resources/dialog/selectMedia.ftl Modified: trunk/openutils-mgnlmedia/pom.xml =================================================================== --- trunk/openutils-mgnlmedia/pom.xml 2010-05-02 17:19:37 UTC (rev 2330) +++ trunk/openutils-mgnlmedia/pom.xml 2010-05-02 17:30:21 UTC (rev 2331) @@ -105,6 +105,11 @@ </dependency> <dependency> <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-mgnlcontrols</artifactId> + <version>4.0.7-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> <artifactId>openutils-mgnlext</artifactId> <version>2.1</version> </dependency> Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java 2010-05-02 17:19:37 UTC (rev 2330) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java 2010-05-02 17:30:21 UTC (rev 2331) @@ -19,44 +19,30 @@ package net.sourceforge.openutils.mgnlmedia.media.dialog; -import freemarker.template.TemplateException; -import freemarker.template.TemplateMethodModel; -import freemarker.template.TemplateModelException; import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.core.ItemType; import info.magnolia.cms.core.NodeData; -import info.magnolia.cms.core.SystemProperty; -import info.magnolia.cms.gui.control.ControlImpl; -import info.magnolia.cms.gui.control.FreemarkerControl; -import info.magnolia.cms.gui.dialog.DialogBox; import info.magnolia.cms.i18n.Messages; import info.magnolia.cms.i18n.MessagesUtil; -import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.cms.util.NodeDataUtil; import info.magnolia.context.MgnlContext; -import java.io.IOException; -import java.io.Writer; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.jcr.PathNotFoundException; -import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import net.sourceforge.openutils.mgnlcontrols.dialog.ConfigurableFreemarkerDialog; import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaTypeConfiguration; import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModule; +import net.sourceforge.openutils.mgnlmedia.media.save.MediaCustomSaveHandler; -import org.apache.commons.lang.exception.NestableRuntimeException; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,8 +52,7 @@ * @author molaschi * @version $Id$ */ -@SuppressWarnings("unchecked") -public class DialogSelectMedia extends DialogBox +public class DialogSelectMedia extends ConfigurableFreemarkerDialog { /** @@ -77,8 +62,6 @@ private Content media; - private Map configuration; - private Long width; private Long height; @@ -87,10 +70,10 @@ * {@inheritDoc} */ @Override - protected List readValues() + protected List<Object> readValues() { - List values = new ArrayList(); + List<Object> values = new ArrayList<Object>(); if (this.getStorageNode() != null) { @@ -117,50 +100,6 @@ } /** - * Get a recursive map view of a content node - * @param node content node - * @return recursive map view on content node properties and children - * @throws RepositoryException repository exception - * @throws AccessDeniedException access denied - */ - protected Map getSubNodes(Content node) throws RepositoryException, AccessDeniedException - { - - Map values = new LinkedHashMap(); - - // cycles on properties and stores them in map - Collection properties = node.getNodeDataCollection(); - - if (properties != null && properties.size() > 0) - { - Iterator propertiesIt = properties.iterator(); - while (propertiesIt.hasNext()) - { - NodeData property = (NodeData) propertiesIt.next(); - values.put(property.getName(), NodeDataUtil.getValueObject(property)); - } - } - - // cycle on children - Collection children = node.getChildren(ItemType.CONTENTNODE); - if (children != null && children.size() > 0) - { - Iterator childrenIt = children.iterator(); - while (childrenIt.hasNext()) - { - Content child = (Content) childrenIt.next(); - - // gets sub map - Map subValues = getSubNodes(child); - // stores it in map - values.put(child.getName(), subValues); - } - } - - return values; - } - - /** * {@inheritDoc} */ @@ -169,52 +108,28 @@ throws RepositoryException { super.init(request, response, websiteNode, configNode); - configuration = this.getSubNodes(configNode); + if (StringUtils.isEmpty(getConfigValue("saveHandler"))) + { + setConfig("saveHandler", MediaCustomSaveHandler.class.getName()); + } } /** * {@inheritDoc} */ @Override - public void drawHtml(Writer out) throws IOException + protected void addToParameters(Map parameters) { - Map parameters = new HashMap(); - parameters.put("name", this.getName()); - parameters.put("value", this.getValue()); - parameters.put("values", this.getValues()); - parameters.put("request", this.getRequest()); - parameters.put("debug", SystemProperty.getBooleanProperty("magnolia.develop")); - parameters.put("configuration", this.configuration); parameters.put("thumbnailUrl", this.getThumbnailUrl()); - parameters.put("filename", this.getFilename()); - parameters.put("reqGet", new RequestGetAttribute()); - parameters.put("reqSet", new RequestSetAttribute()); parameters.put("msgs", this.getMessages()); + parameters.put("filename", this.getFilename()); + if ("true".equals(this.getConfigValue("resizing"))) { parameters.put("width", this.getWidth()); parameters.put("height", this.getHeight()); } - this.drawHtmlPre(out); - - try - { - FreemarkerControl control = new FreemarkerControl("multiple".equals(this.getConfigValue("valueType")) - ? ControlImpl.VALUETYPE_MULTIPLE - : ControlImpl.VALUETYPE_SINGLE); - control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING)); - control.setName(this.getName()); - control.drawHtml(out, getPath(), parameters); - } - - catch (TemplateException ex) - { - log.error("Error processing dialog template:", ex); - throw new NestableRuntimeException(ex); - } - - this.drawHtmlPost(out); } /** @@ -226,6 +141,7 @@ return MessagesUtil.chain("net.sourceforge.openutils.mgnlmedia.media.lang.messages", super.getMessages()); } + @Override protected String getPath() { return "dialog/selectMedia.ftl"; @@ -332,78 +248,4 @@ return height; } - /** - * Freemarker method for setting request attributes - * @author molaschi - * @version $Id$ - */ - public class RequestSetAttribute implements TemplateMethodModel - { - - /** - * {@inheritDoc} - */ - public Object exec(List arguments) throws TemplateModelException - { - if (arguments != null && arguments.size() == 3 && arguments.get(0) instanceof HttpServletRequest) - { - HttpServletRequest req = (HttpServletRequest) arguments.get(0); - String name = (String) arguments.get(1); - Object value = arguments.get(2); - req.setAttribute(name, value); - } - - return TemplateMethodModel.NOTHING; - } - - } - - /** - * Freemarker method for getting request attributes - * @author molaschi - * @version $Id$ - */ - public class RequestGetAttribute implements TemplateMethodModel - { - - /** - * {@inheritDoc} - */ - public Object exec(List arguments) throws TemplateModelException - { - if (arguments != null && arguments.size() == 2 && arguments.get(0) instanceof HttpServletRequest) - { - HttpServletRequest req = (HttpServletRequest) arguments.get(0); - String name = (String) arguments.get(1); - return req.getAttribute(name); - } - - return null; - } - - } - - /** - * {@inheritDoc} - */ - @Override - public void drawHtmlPost(Writer out) throws IOException - { - out.write(this.getHtmlDescription()); - - out.write("<input type=\"hidden\" name=\""); - out.write(this.getName()); - out.write("_saveHandler\" value=\""); - out.write("net.sourceforge.openutils.mgnlmedia.media.save.MediaCustomSaveHandler"); - out.write("\" />"); - - out.write("<input type=\"hidden\" name=\""); - out.write(this.getName()); - out.write("_configNode\" value=\""); - out.write(this.getConfigValue("handle")); - out.write("\" />"); - - out.write("</td></tr>\n"); //$NON-NLS-1$ - } - } Modified: trunk/openutils-mgnlmedia/src/main/resources/META-INF/tags/media/media.tag =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/META-INF/tags/media/media.tag 2010-05-02 17:19:37 UTC (rev 2330) +++ trunk/openutils-mgnlmedia/src/main/resources/META-INF/tags/media/media.tag 2010-05-02 17:30:21 UTC (rev 2331) @@ -30,6 +30,12 @@ <jsp:directive.attribute name="videoImagePreview" required="false" rtexprvalue="true" type="java.lang.Boolean" description="if set to true, the tag will not insert the player for videos but only a preview image. For videos or mp3s it needs the following scripts loaded in page: <ul><li>.resources/media/js/mootools-1.2-core.js</li><li>.resources/media/js/mootools-1.2-more.js</li><li>.resources/media/js/mootools-1.2-swfobject.js</li></ul>"/> <jsp:directive.attribute name="controlbar" required="false" rtexprvalue="true" type="java.lang.String" description="defines controlbar position. Possible values are: 'none' (for hiding), 'over', 'bottom', 'top'. If not set, this value will be 'bottom' by default." /> <jsp:directive.attribute name="share" required="false" rtexprvalue="true" type="java.lang.Boolean" description="if set to true the pluging share-1 is show"/> + + + +_${item.class.name}_ + + <c:if test="${empty item}"> <c:if test="${empty node}"> <c:set var="node" value="${content}" /> Modified: trunk/openutils-mgnlmedia/src/main/resources/dialog/selectMedia.ftl =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/dialog/selectMedia.ftl 2010-05-02 17:19:37 UTC (rev 2330) +++ trunk/openutils-mgnlmedia/src/main/resources/dialog/selectMedia.ftl 2010-05-02 17:30:21 UTC (rev 2331) @@ -1,4 +1,4 @@ -[#if !reqGet(request, "js_media_included")?exists] +[#if !alreadyrendered] <script type="text/javascript"> function selectMedia(name, value, mediaType) { var url = "${request.contextPath}/.magnolia/pages/mediaBrowser.html?nodeid=" + name + "&selectMedia=true&mgnlCK="+ @@ -33,7 +33,6 @@ document.getElementById("dispRem"+ name + "Txt").innerHTML = filename; } </script> -${reqSet(request, "js_media_included", 1)} [/#if] <input type="hidden" id="${name}" name="${name}" value="${value}" /> [#if value?exists && value?length > 0] @@ -66,13 +65,13 @@ <tr> <td class="mgnlDialogBoxLabel">Width</td> <td class="mgnlDialogBoxInput"> - <input type="text" id="${name}_width" name="${name}_width" value="${width!''}" class="mgnlDialogControlEdit" style="width: 60px;"> + <input type="text" id="${name}_width" name="${name}_width" value="${width!''}" class="mgnlDialogControlEdit" style="width: 60px;" /> </td> </tr> <tr> <td class="mgnlDialogBoxLabel">Height</td> <td class="mgnlDialogBoxInput"> - <input type="text" id="${name}_height" name="${name}_height" value="${height!''}" class="mgnlDialogControlEdit" style="width: 60px;"> + <input type="text" id="${name}_height" name="${name}_height" value="${height!''}" class="mgnlDialogControlEdit" style="width: 60px;" /> </td> </tr> </tbody> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |