Source Code Cross Referenced for CmsCommentImages.java in  » Content-Management-System » opencms » org » opencms » workplace » commons » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace.commons 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsCommentImages.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:23 $
004:         * Version: $Revision: 1.6 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.workplace.commons;
033:
034:        import com.alkacon.simapi.Simapi;
035:
036:        import org.opencms.file.CmsProperty;
037:        import org.opencms.file.CmsPropertyDefinition;
038:        import org.opencms.file.CmsResource;
039:        import org.opencms.file.CmsResourceFilter;
040:        import org.opencms.file.types.CmsResourceTypeImage;
041:        import org.opencms.i18n.CmsEncoder;
042:        import org.opencms.jsp.CmsJspActionElement;
043:        import org.opencms.loader.CmsImageScaler;
044:        import org.opencms.main.CmsException;
045:        import org.opencms.main.CmsLog;
046:        import org.opencms.main.OpenCms;
047:        import org.opencms.security.CmsPermissionSet;
048:        import org.opencms.util.CmsStringUtil;
049:        import org.opencms.workplace.CmsDialog;
050:        import org.opencms.workplace.CmsWorkplaceSettings;
051:
052:        import java.awt.Color;
053:        import java.util.ArrayList;
054:        import java.util.Iterator;
055:        import java.util.List;
056:
057:        import javax.servlet.http.HttpServletRequest;
058:        import javax.servlet.http.HttpServletResponse;
059:        import javax.servlet.jsp.JspException;
060:        import javax.servlet.jsp.PageContext;
061:
062:        import org.apache.commons.logging.Log;
063:
064:        /**
065:         * Provides methods for the comment images dialog on image gallery folders.<p> 
066:         * 
067:         * The following files use this class:
068:         * <ul>
069:         * <li>/commons/commentimages.jsp
070:         * </ul>
071:         * <p>
072:         *
073:         * @author  Andreas Zahner 
074:         * 
075:         * @version $Revision: 1.6 $ 
076:         * 
077:         * @since 6.1.3
078:         */
079:        public class CmsCommentImages extends CmsDialog {
080:
081:            /** Value for the action: comment images. */
082:            public static final int ACTION_COMMENTIMAGES = 100;
083:
084:            /** The dialog type. */
085:            public static final String DIALOG_TYPE = "commentimages";
086:
087:            /** The input field prefix for description property fields. */
088:            public static final String PREFIX_DESCRIPTION = "desc_";
089:
090:            /** The input field prefix for title property fields. */
091:            public static final String PREFIX_TITLE = "title_";
092:
093:            /** The height of the dialog thumbnails. */
094:            public static final int THUMB_HEIGHT = 150;
095:
096:            /** The width of the dialog thumbnails. */
097:            public static final int THUMB_WIDTH = 200;
098:
099:            /** The log object for this class. */
100:            private static final Log LOG = CmsLog
101:                    .getLog(CmsCommentImages.class);
102:
103:            /** The image scaler object used in the dialog input form. */
104:            private CmsImageScaler m_imageScaler;
105:
106:            /**
107:             * Public constructor with JSP action element.<p>
108:             * 
109:             * @param jsp an initialized JSP action element
110:             */
111:            public CmsCommentImages(CmsJspActionElement jsp) {
112:
113:                super (jsp);
114:            }
115:
116:            /**
117:             * Public constructor with JSP variables.<p>
118:             * 
119:             * @param context the JSP page context
120:             * @param req the JSP request
121:             * @param res the JSP response
122:             */
123:            public CmsCommentImages(PageContext context,
124:                    HttpServletRequest req, HttpServletResponse res) {
125:
126:                this (new CmsJspActionElement(context, req, res));
127:            }
128:
129:            /**
130:             * Performs the comment images action, will be called by the JSP page.<p>
131:             * 
132:             * @throws JspException if problems including sub-elements occur
133:             */
134:            public void actionCommentImages() throws JspException {
135:
136:                // save initialized instance of this class in request attribute for included sub-elements
137:                getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS,
138:                        this );
139:                try {
140:                    performDialogOperation();
141:                    // if no exception is caused comment operation was successful
142:                    actionCloseDialog();
143:                } catch (Throwable e) {
144:                    // error during rename images, show error dialog
145:                    includeErrorpage(this , e);
146:                }
147:            }
148:
149:            /**
150:             * Returns the HTML for the dialog input form to comment the images.<p>
151:             * 
152:             * @return the HTML for the dialog input form to comment the images
153:             */
154:            public String buildDialogForm() {
155:
156:                StringBuffer result = new StringBuffer(16384);
157:                Iterator i = getImages().iterator();
158:
159:                result
160:                        .append("<div style=\"height: 450px; padding: 4px; overflow: auto;\">");
161:
162:                while (i.hasNext()) {
163:                    CmsResource res = (CmsResource) i.next();
164:                    String imageName = res.getName();
165:                    String propertySuffix = "" + imageName.hashCode();
166:                    result.append(dialogBlockStart(imageName));
167:                    result.append("<table border=\"0\">\n");
168:                    result
169:                            .append("<tr>\n\t<td style=\"vertical-align: top;\">");
170:                    // create image tag
171:                    result.append("<img src=\"");
172:                    StringBuffer link = new StringBuffer(256);
173:                    link.append(getCms().getSitePath(res));
174:                    link.append(getImageScaler().toRequestParam());
175:                    result.append(getJsp().link(link.toString()));
176:                    result.append("\" border=\"0\" alt=\"\" width=\"");
177:                    result.append(getImageScaler().getWidth());
178:                    result.append("\" height=\"");
179:                    result.append(getImageScaler().getHeight());
180:                    result.append("\">");
181:
182:                    result.append("</td>\n");
183:                    result
184:                            .append("\t<td class=\"maxwidth\" style=\"vertical-align: top;\">\n");
185:
186:                    result.append("\t\t<table border=\"0\">\n");
187:
188:                    // build title property input row
189:                    String title = "";
190:                    try {
191:                        title = getCms().readPropertyObject(res,
192:                                CmsPropertyDefinition.PROPERTY_TITLE, false)
193:                                .getValue();
194:                    } catch (CmsException e) {
195:                        // log, should never happen
196:                        if (LOG.isErrorEnabled()) {
197:                            LOG.error(e.getLocalizedMessage(getLocale()));
198:                        }
199:                    }
200:                    result
201:                            .append("\t\t<tr>\n\t\t\t<td style=\"white-space: nowrap;\" unselectable=\"on\">");
202:                    result.append(key(Messages.GUI_LABEL_TITLE_0));
203:                    result.append(":</td>\n\t\t\t<td class=\"maxwidth\">");
204:                    result
205:                            .append("<input type=\"text\" class=\"maxwidth\" name=\"");
206:                    result.append(PREFIX_TITLE);
207:                    result.append(propertySuffix);
208:                    result.append("\" value=\"");
209:                    if (CmsStringUtil.isNotEmpty(title)) {
210:                        result.append(CmsEncoder.escapeXml(title));
211:                    }
212:                    result.append("\">");
213:                    result.append("</td>\n\t\t</tr>\n");
214:
215:                    // build description property input row
216:                    String description = "";
217:                    try {
218:                        description = getCms().readPropertyObject(res,
219:                                CmsPropertyDefinition.PROPERTY_DESCRIPTION,
220:                                false).getValue();
221:                    } catch (CmsException e) {
222:                        // log, should never happen
223:                        if (LOG.isErrorEnabled()) {
224:                            LOG.error(e.getLocalizedMessage(getLocale()));
225:                        }
226:                    }
227:                    result
228:                            .append("\t\t<tr>\n\t\t\t<td style=\"white-space: nowrap; vertical-align: top;\" unselectable=\"on\">");
229:                    result.append(key(Messages.GUI_LABEL_DESCRIPTION_0));
230:                    result
231:                            .append(":</td>\n\t\t\t<td style=\"vertical-align: top; height: 110px;\">");
232:                    result
233:                            .append("<textarea rows=\"8\" class=\"maxwidth\" style=\"overflow: auto;\" name=\"");
234:                    result.append(PREFIX_DESCRIPTION);
235:                    result.append(propertySuffix);
236:                    result.append("\">");
237:                    if (CmsStringUtil.isNotEmpty(description)) {
238:                        result.append(CmsEncoder.escapeXml(description));
239:                    }
240:                    result.append("</textarea>");
241:                    result.append("</td>\n\t\t</tr>\n");
242:
243:                    result.append("\t\t</table>\n");
244:
245:                    result.append("</td>\n</tr>\n");
246:                    result.append("</table>\n");
247:                    result.append(dialogBlockEnd());
248:
249:                    if (i.hasNext()) {
250:                        // append spacer if another entry follows
251:                        result.append(dialogSpacer());
252:                    }
253:                }
254:
255:                result.append("</div>");
256:
257:                return result.toString();
258:            }
259:
260:            /**
261:             * Returns the image resources of the gallery folder which are edited in the dialog form.<p>
262:             * 
263:             * @return the images of the gallery folder which are edited in the dialog form
264:             */
265:            protected List getImages() {
266:
267:                // get all image resources of the folder
268:                CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION
269:                        .addRequireType(CmsResourceTypeImage.getStaticTypeId());
270:                try {
271:                    return getCms().readResources(getParamResource(), filter,
272:                            false);
273:                } catch (CmsException e) {
274:                    // log, should never happen
275:                    if (LOG.isErrorEnabled()) {
276:                        LOG.error(e.getLocalizedMessage(getLocale()));
277:                    }
278:                    return new ArrayList(0);
279:                }
280:            }
281:
282:            /**
283:             * Returns the initialized image scaler object used to generate thumbnails for the dialog form.<p>
284:             * 
285:             * @return the initialized image scaler object used to generate thumbnails for the dialog form
286:             */
287:            protected CmsImageScaler getImageScaler() {
288:
289:                if (m_imageScaler == null) {
290:                    // not initialized, create image scaler with default settings
291:                    m_imageScaler = new CmsImageScaler();
292:                    m_imageScaler.setWidth(THUMB_WIDTH);
293:                    m_imageScaler.setHeight(THUMB_HEIGHT);
294:                    m_imageScaler.setRenderMode(Simapi.RENDER_SPEED);
295:                    m_imageScaler.setColor(new Color(0, 0, 0));
296:                    m_imageScaler.setType(1);
297:                }
298:                return m_imageScaler;
299:            }
300:
301:            /**
302:             * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
303:             */
304:            protected void initWorkplaceRequestValues(
305:                    CmsWorkplaceSettings settings, HttpServletRequest request) {
306:
307:                // fill the parameter values in the get/set methods
308:                fillParamValues(request);
309:
310:                // check the required permissions to rename the resource       
311:                if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE,
312:                        false)) {
313:                    // no write permissions for the resource, set cancel action to close dialog
314:                    setParamAction(DIALOG_CANCEL);
315:                }
316:
317:                // set the dialog type
318:                setParamDialogtype(DIALOG_TYPE);
319:                // set the action for the JSP switch 
320:                if (DIALOG_TYPE.equals(getParamAction())) {
321:                    setAction(ACTION_COMMENTIMAGES);
322:                } else if (DIALOG_LOCKS_CONFIRMED.equals(getParamAction())) {
323:                    setAction(ACTION_LOCKS_CONFIRMED);
324:                } else if (DIALOG_CANCEL.equals(getParamAction())) {
325:                    setAction(ACTION_CANCEL);
326:                } else {
327:                    setAction(ACTION_DEFAULT);
328:                    // build title for comment images dialog
329:                    Object[] args = new Object[] { getParamResource() };
330:                    setParamTitle(key(Messages.GUI_COMMENTIMAGES_TITLE_1, args));
331:                }
332:            }
333:
334:            /**
335:             * Performs the comment images operation.<p>
336:             * 
337:             * @return true, if the resources were successfully processed, otherwise false
338:             * @throws CmsException if commenting is not successful
339:             */
340:            protected boolean performDialogOperation() throws CmsException {
341:
342:                // lock the image gallery folder
343:                checkLock(getParamResource());
344:
345:                Iterator i = getImages().iterator();
346:                // loop over all image resources to change the properties
347:                while (i.hasNext()) {
348:                    CmsResource res = (CmsResource) i.next();
349:                    String imageName = res.getName();
350:                    String propertySuffix = "" + imageName.hashCode();
351:
352:                    // update the title property
353:                    CmsProperty titleProperty = getCms().readPropertyObject(
354:                            res, CmsPropertyDefinition.PROPERTY_TITLE, false);
355:                    String newValue = getJsp().getRequest().getParameter(
356:                            PREFIX_TITLE + propertySuffix);
357:                    writeProperty(res, CmsPropertyDefinition.PROPERTY_TITLE,
358:                            newValue, titleProperty);
359:
360:                    // update the description property
361:                    CmsProperty descProperty = getCms().readPropertyObject(res,
362:                            CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
363:                    newValue = getJsp().getRequest().getParameter(
364:                            PREFIX_DESCRIPTION + propertySuffix);
365:                    writeProperty(res,
366:                            CmsPropertyDefinition.PROPERTY_DESCRIPTION,
367:                            newValue, descProperty);
368:                }
369:
370:                return true;
371:            }
372:
373:            /**
374:             * Writes a property value for a resource, if the value was changed.<p>
375:             * 
376:             * @param res the resource to write the property to
377:             * @param propName the name of the property definition
378:             * @param propValue the new value of the property
379:             * @param currentProperty the old property object
380:             * @throws CmsException if something goes wrong
381:             */
382:            protected void writeProperty(CmsResource res, String propName,
383:                    String propValue, CmsProperty currentProperty)
384:                    throws CmsException {
385:
386:                // check if current property is not the null property
387:                if (currentProperty.isNullProperty()) {
388:                    // create new property object
389:                    currentProperty = new CmsProperty();
390:                    currentProperty.setName(propName);
391:                }
392:
393:                if (CmsStringUtil.isEmptyOrWhitespaceOnly(propValue)) {
394:                    // parameter is empty, determine the value to delete
395:                    boolean writeProperty = false;
396:                    if (currentProperty.getStructureValue() != null) {
397:                        currentProperty
398:                                .setStructureValue(CmsProperty.DELETE_VALUE);
399:                        currentProperty.setResourceValue(null);
400:                        writeProperty = true;
401:                    } else if (currentProperty.getResourceValue() != null) {
402:                        currentProperty
403:                                .setResourceValue(CmsProperty.DELETE_VALUE);
404:                        currentProperty.setStructureValue(null);
405:                        writeProperty = true;
406:                    }
407:                    if (writeProperty) {
408:                        // write the updated property object
409:                        getCms().writePropertyObject(getCms().getSitePath(res),
410:                                currentProperty);
411:                    }
412:                } else {
413:                    // parameter is not empty, check if the value has changed
414:                    if (!propValue.equals(currentProperty.getValue())) {
415:                        if ((currentProperty.getStructureValue() == null)
416:                                && (currentProperty.getResourceValue() == null)) {
417:                            // new property, determine setting from OpenCms workplace configuration
418:                            if (OpenCms.getWorkplaceManager()
419:                                    .isDefaultPropertiesOnStructure()) {
420:                                currentProperty.setStructureValue(propValue);
421:                                currentProperty.setResourceValue(null);
422:                            } else {
423:                                currentProperty.setResourceValue(propValue);
424:                                currentProperty.setStructureValue(null);
425:                            }
426:                        } else if (currentProperty.getStructureValue() != null) {
427:                            // structure value has to be updated
428:                            currentProperty.setStructureValue(propValue);
429:                            currentProperty.setResourceValue(null);
430:                        } else {
431:                            // resource value has to be updated
432:                            currentProperty.setResourceValue(propValue);
433:                            currentProperty.setStructureValue(null);
434:                        }
435:                        // write the updated property object
436:                        getCms().writePropertyObject(getCms().getSitePath(res),
437:                                currentProperty);
438:                    }
439:                }
440:            }
441:
442:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.