Source Code Cross Referenced for CmsHtmlWidgetOption.java in  » Content-Management-System » opencms » org » opencms » widgets » 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.widgets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsHtmlWidgetOption.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:44 $
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.widgets;
033:
034:        import org.opencms.main.OpenCms;
035:        import org.opencms.util.CmsStringUtil;
036:
037:        import java.util.ArrayList;
038:        import java.util.Iterator;
039:        import java.util.List;
040:
041:        /**
042:         * An option of a Html type widget.<p>
043:         * 
044:         * Options can be defined for each element of the type <code>OpenCmsHtml</code> using the widget <code>HtmlWidget</code>.
045:         * They have to be placed in the annotation section of a XSD describing an xml content. The <code>configuration</code> attribute 
046:         * in the <code>layout</code> node for the element must contain the activated options as a comma separated String value:<p>
047:         * 
048:         * <code><layout element="Text" widget="HtmlWidget" configuration="height:400px,link,anchor,imagegallery,downloadgallery,formatselect,source" /></code><p>
049:         * 
050:         * Available options are:
051:         * <ul>
052:         * <li><code>anchor</code>: the anchor dialog button</li>
053:         * <li><code>css:/vfs/path/to/cssfile.css</code>: the absolute path in the OpenCms VFS to the CSS style sheet 
054:         *     to use to render the contents in the editor (availability depends on the integrated editor)</li>
055:         * <li><code>formatselect</code>: the format selector for selecting text format like paragraph or headings</li>
056:         * <li><code>fullpage</code>: the editor creates an entire html page code </li>
057:         * <li><code>${gallerytype}</code>: Shows a gallery dialog button, e.g. <code>imagegallery</code> displays 
058:         *     the image gallery button or <code>downloadgallery</code> displays the download gallery button</li>
059:         * <li><code>height:${editorheight}</code>: the editor height, where the height can be specified in px or %, e.g. <code>400px</code></li>
060:         * <li><code>image</code>: the image dialog button (availability depends on the integrated editor)</li>
061:         * <li><code>link</code>: the link dialog button</li>
062:         * <li><code>source</code>: shows the source code toggle button(s)</li>
063:         * <li><code>stylesxml:/vfs/path/to/stylefile.xml</code>: the absolute path in the OpenCms VFS to the user defined
064:         *     styles that should be displayed in the style selector (availability depends on the integrated editor)</li>
065:         * <li><code>table</code>: the table dialog button (availability depends on the integrated editor)</li>
066:         * </ul>
067:         * If an option key is not found in the configuration options, the corresponding button will be hidden in the editor widget.<p>
068:         * 
069:         * @author Andreas Zahner
070:         * 
071:         * @version $Revision: 1.6 $ 
072:         * 
073:         * @since 6.0.1
074:         */
075:        public class CmsHtmlWidgetOption {
076:
077:            /** The editor widget default height to use. */
078:            public static final String EDITOR_DEFAULTHEIGHT = "260px";
079:
080:            /** Option for the "anchor" dialog. */
081:            public static final String OPTION_ANCHOR = "anchor";
082:
083:            /** Option for the css style sheet VFS path to use in the widget area. */
084:            public static final String OPTION_CSS = "css:";
085:
086:            /** The delimiter to use in the configuration String. */
087:            public static final String OPTION_DELIMITER = ",";
088:
089:            /** Option for the "formatselect" selector. */
090:            public static final String OPTION_FORMATSELECT = "formatselect";
091:
092:            /** Option for the "fullpage" editor variant. */
093:            public static final String OPTION_FULLPAGE = "fullpage";
094:
095:            /** Option for the "height" configuration. */
096:            public static final String OPTION_HEIGHT = "height:";
097:
098:            /** Option for the "image" dialog. */
099:            public static final String OPTION_IMAGE = "image";
100:
101:            /** Option for the "link" dialog. */
102:            public static final String OPTION_LINK = "link";
103:
104:            /** Option for the "source" code mode. */
105:            public static final String OPTION_SOURCE = "source";
106:
107:            /** Option for the styles XML VFS path to use in the widget area. */
108:            public static final String OPTION_STYLES = "stylesxml:";
109:
110:            /** Option for the "table" dialog. */
111:            public static final String OPTION_TABLE = "table";
112:
113:            private String m_cssPath;
114:            private List m_displayGalleries;
115:            private String m_editorHeight;
116:            private boolean m_fullPage;
117:            private boolean m_showAnchorDialog;
118:            private boolean m_showFormatSelect;
119:            private boolean m_showImageDialog;
120:            private boolean m_showLinkDialog;
121:            private boolean m_showSourceEditor;
122:            private boolean m_showTableDialog;
123:            private String m_stylesXmlPath;
124:
125:            /**
126:             * Creates a new empty html widget object object.<p>
127:             */
128:            public CmsHtmlWidgetOption() {
129:
130:                // initialize the members
131:                m_displayGalleries = new ArrayList();
132:                m_editorHeight = EDITOR_DEFAULTHEIGHT;
133:            }
134:
135:            /**
136:             * Creates a new html widget object object, configured by the given configuration String.<p>
137:             * 
138:             * @param configuration configuration String to parse
139:             */
140:            public CmsHtmlWidgetOption(String configuration) {
141:
142:                // initialize the widget options
143:                m_displayGalleries = new ArrayList();
144:                m_editorHeight = EDITOR_DEFAULTHEIGHT;
145:                parseOptions(configuration);
146:            }
147:
148:            /**
149:             * Returns a html widget configuration String created from the given html widget option.<p>
150:             * 
151:             * @param option the html widget options to create the configuration String for
152:             * 
153:             * @return a select widget configuration String created from the given html widget option object
154:             */
155:            public static String createConfigurationString(
156:                    CmsHtmlWidgetOption option) {
157:
158:                StringBuffer result = new StringBuffer(512);
159:                boolean added = false;
160:                if (!option.getEditorHeight().equals(EDITOR_DEFAULTHEIGHT)) {
161:                    // append the height configuration
162:                    result.append(OPTION_HEIGHT);
163:                    result.append(option.getEditorHeight());
164:                    added = true;
165:                }
166:                if (option.showAnchorDialog()) {
167:                    // append the anchor configuration
168:                    if (added) {
169:                        result.append(OPTION_DELIMITER);
170:                    }
171:                    result.append(OPTION_ANCHOR);
172:                    added = true;
173:                }
174:                if (option.showLinkDialog()) {
175:                    // append the link configuration
176:                    if (added) {
177:                        result.append(OPTION_DELIMITER);
178:                    }
179:                    result.append(OPTION_LINK);
180:                    added = true;
181:                }
182:                if (option.showFormatSelect()) {
183:                    // append the format selector configuration
184:                    if (added) {
185:                        result.append(OPTION_DELIMITER);
186:                    }
187:                    result.append(OPTION_FORMATSELECT);
188:                    added = true;
189:                }
190:                if (option.showSourceEditor()) {
191:                    // append the source code configuration
192:                    if (added) {
193:                        result.append(OPTION_DELIMITER);
194:                    }
195:                    result.append(OPTION_SOURCE);
196:                    added = true;
197:                }
198:                if (option.showTableDialog()) {
199:                    // append the table configuration
200:                    if (added) {
201:                        result.append(OPTION_DELIMITER);
202:                    }
203:                    result.append(OPTION_TABLE);
204:                    added = true;
205:                }
206:                if (option.showImageDialog()) {
207:                    // append the image configuration
208:                    if (added) {
209:                        result.append(OPTION_DELIMITER);
210:                    }
211:                    result.append(OPTION_IMAGE);
212:                    added = true;
213:                }
214:                if (option.useCss()) {
215:                    // append the CSS VFS path
216:                    if (added) {
217:                        result.append(OPTION_DELIMITER);
218:                    }
219:                    result.append(OPTION_CSS);
220:                    result.append(option.getCssPath());
221:                    added = true;
222:                }
223:                if (option.showStylesXml()) {
224:                    // append the styles XML VFS path
225:                    if (added) {
226:                        result.append(OPTION_DELIMITER);
227:                    }
228:                    result.append(OPTION_STYLES);
229:                    result.append(option.getStylesXmlPath());
230:                    added = true;
231:                }
232:
233:                boolean isFirst = true;
234:                for (int i = 0; i < option.getDisplayGalleries().size(); i++) {
235:                    // append the galleries configuration
236:                    String gallery = (String) option.getDisplayGalleries().get(
237:                            i);
238:                    if (added || !isFirst) {
239:                        result.append(OPTION_DELIMITER);
240:                    }
241:                    result.append(gallery);
242:                    isFirst = false;
243:                }
244:
245:                return result.toString();
246:            }
247:
248:            /**
249:             * Returns the css style sheet VFS path to use in the widget area.<p>
250:             *
251:             * @return the css style sheet VFS path to use in the widget area
252:             */
253:            public String getCssPath() {
254:
255:                return m_cssPath;
256:            }
257:
258:            /**
259:             * Returns the displayed gallery names.<p>
260:             * 
261:             * @return the displayed gallery names
262:             */
263:            public List getDisplayGalleries() {
264:
265:                return m_displayGalleries;
266:            }
267:
268:            /**
269:             * Returns the widget editor height.<p>
270:             * 
271:             * @return the widget editor height
272:             */
273:            public String getEditorHeight() {
274:
275:                return m_editorHeight;
276:            }
277:
278:            /**
279:             * Returns the styles XML VFS path to use in the widget area.<p>
280:             *
281:             * @return the styles XML VFS path to use in the widget area
282:             */
283:            public String getStylesXmlPath() {
284:
285:                return m_stylesXmlPath;
286:            }
287:
288:            /**
289:             * Returns if the editor should be used in full page mode.<p>
290:             * 
291:             * @return true if the editor should be used in full page mode, otherwise false
292:             */
293:            public boolean isFullPage() {
294:
295:                return m_fullPage;
296:            }
297:
298:            /**
299:             * Sets the css style sheet VFS path to use in the widget area.<p>
300:             *
301:             * @param cssPath the css style sheet VFS path to use in the widget area
302:             */
303:            public void setCssPath(String cssPath) {
304:
305:                m_cssPath = cssPath;
306:            }
307:
308:            /**
309:             * Sets the displayed gallery names.<p>
310:             * 
311:             * @param displayGalleries the displayed gallery names
312:             */
313:            public void setDisplayGalleries(List displayGalleries) {
314:
315:                m_displayGalleries = displayGalleries;
316:            }
317:
318:            /**
319:             * Sets the widget editor height.<p>
320:             * 
321:             * @param editorHeight the widget editor height
322:             */
323:            public void setEditorHeight(String editorHeight) {
324:
325:                m_editorHeight = editorHeight;
326:            }
327:
328:            /**
329:             * Sets if the editor should be used in full page mode.<p>
330:             * 
331:             * @param fullPage true if the editor should be used in full page mode, otherwise false
332:             */
333:            public void setFullPage(boolean fullPage) {
334:
335:                m_fullPage = fullPage;
336:            }
337:
338:            /**
339:             * Sets if the anchor dialog button should be available.<p>
340:             * 
341:             * @param showAnchorDialog true if the anchor dialog button should be available, otherwise false
342:             */
343:            public void setShowAnchorDialog(boolean showAnchorDialog) {
344:
345:                m_showAnchorDialog = showAnchorDialog;
346:            }
347:
348:            /**
349:             * Sets if the format selector should be available.<p>
350:             * 
351:             * @param showFormatSelect true if the format selector should be available, otherwise false
352:             */
353:            public void setShowFormatSelect(boolean showFormatSelect) {
354:
355:                m_showFormatSelect = showFormatSelect;
356:            }
357:
358:            /**
359:             * Sets if the image dialog button should be available.<p>
360:             *
361:             * @param showImageDialog true if the image dialog button should be available, otherwise false
362:             */
363:            public void setShowImageDialog(boolean showImageDialog) {
364:
365:                m_showImageDialog = showImageDialog;
366:            }
367:
368:            /**
369:             * Sets if the link dialog button should be available.<p>
370:             * 
371:             * @param showLinkDialog true if the link dialog button should be available, otherwise false
372:             */
373:            public void setShowLinkDialog(boolean showLinkDialog) {
374:
375:                m_showLinkDialog = showLinkDialog;
376:            }
377:
378:            /**
379:             * Sets if the source code button should be available.<p>
380:             * 
381:             * @param showSourceEditor true if the source code button should be available, otherwise false
382:             */
383:            public void setShowSourceEditor(boolean showSourceEditor) {
384:
385:                m_showSourceEditor = showSourceEditor;
386:            }
387:
388:            /**
389:             * Sets if the table dialog button should be available.<p>
390:             *
391:             * @param showTableDialog true if the table dialog button should be available, otherwise false
392:             */
393:            public void setShowTableDialog(boolean showTableDialog) {
394:
395:                m_showTableDialog = showTableDialog;
396:            }
397:
398:            /**
399:             * Sets the styles XML VFS path to use in the widget area.<p>
400:             *
401:             * @param stylesXmlPath the styles XML VFS path to use in the widget area
402:             */
403:            public void setStylesXmlPath(String stylesXmlPath) {
404:
405:                m_stylesXmlPath = stylesXmlPath;
406:            }
407:
408:            /**
409:             * Returns true if the anchor dialog button should be available.<p>
410:             * 
411:             * @return if the anchor dialog button should be available
412:             */
413:            public boolean showAnchorDialog() {
414:
415:                return m_showAnchorDialog;
416:            }
417:
418:            /**
419:             * Returns true if the format selector should be available.<p>
420:             * 
421:             * @return if the format selector should be available
422:             */
423:            public boolean showFormatSelect() {
424:
425:                return m_showFormatSelect;
426:            }
427:
428:            /**
429:             * Returns true if the specified gallery type dialog button is shown.<p>
430:             * 
431:             * @param galleryType the gallery type to check
432:             * @return true if the specified gallery type dialog button is shown, otherwise false
433:             */
434:            public boolean showGalleryDialog(String galleryType) {
435:
436:                return getDisplayGalleries().contains(galleryType);
437:            }
438:
439:            /**
440:             * Returns true if the image dialog button should be available.<p>
441:             *
442:             * @return if the image dialog button should be available
443:             */
444:            public boolean showImageDialog() {
445:
446:                return m_showImageDialog;
447:            }
448:
449:            /**
450:             * Returns true if the link dialog button should be available.<p>
451:             * 
452:             * @return if the link dialog button should be available
453:             */
454:            public boolean showLinkDialog() {
455:
456:                return m_showLinkDialog;
457:            }
458:
459:            /**
460:             * Returns true if the source code button should be available.<p>
461:             * 
462:             * @return if the source code button should be available
463:             */
464:            public boolean showSourceEditor() {
465:
466:                return m_showSourceEditor;
467:            }
468:
469:            /**
470:             * Returns true if the styles selector should be available.<p>
471:             *
472:             * @return if the styles selector should be available
473:             */
474:            public boolean showStylesXml() {
475:
476:                return CmsStringUtil.isNotEmpty(getStylesXmlPath());
477:            }
478:
479:            /**
480:             * Returns true if the table dialog button should be available.<p>
481:             *
482:             * @return if the table dialog button should be available
483:             */
484:            public boolean showTableDialog() {
485:
486:                return m_showTableDialog;
487:            }
488:
489:            /**
490:             * Returns true if the widget editor should use a defined CSS style sheet.<p>
491:             * 
492:             * @return if the widget editor should use a defined CSS style sheet
493:             */
494:            public boolean useCss() {
495:
496:                return CmsStringUtil.isNotEmpty(getCssPath());
497:            }
498:
499:            /**
500:             * Parses the given configuration String.<p>
501:             * 
502:             * @param configuration the configuration String to parse
503:             */
504:            protected void parseOptions(String configuration) {
505:
506:                if (CmsStringUtil.isNotEmpty(configuration)) {
507:                    List options = CmsStringUtil.splitAsList(configuration,
508:                            OPTION_DELIMITER, true);
509:                    Iterator i = options.iterator();
510:                    while (i.hasNext()) {
511:                        String option = (String) i.next();
512:                        if (OPTION_LINK.equals(option)) {
513:                            // show link dialog
514:                            setShowLinkDialog(true);
515:                        } else if (OPTION_ANCHOR.equals(option)) {
516:                            // show anchor dialog
517:                            setShowAnchorDialog(true);
518:                        } else if (OPTION_SOURCE.equals(option)) {
519:                            // show source button
520:                            setShowSourceEditor(true);
521:                        } else if (OPTION_FORMATSELECT.equals(option)) {
522:                            // show format selector
523:                            setShowFormatSelect(true);
524:                        } else if (OPTION_FULLPAGE.equals(option)) {
525:                            // use editor in full page mode
526:                            setFullPage(true);
527:                        } else if (OPTION_IMAGE.equals(option)) {
528:                            // show image dialog
529:                            setShowImageDialog(true);
530:                        } else if (OPTION_TABLE.equals(option)) {
531:                            // show table dialog
532:                            setShowTableDialog(true);
533:                        } else if (option.startsWith(OPTION_HEIGHT)) {
534:                            // the editor height
535:                            option = option.substring(OPTION_HEIGHT.length());
536:                            if (CmsStringUtil
537:                                    .isNotEmptyOrWhitespaceOnly(option)) {
538:                                setEditorHeight(option);
539:                            }
540:                        } else if (option.startsWith(OPTION_CSS)) {
541:                            // the editor CSS
542:                            option = option.substring(OPTION_CSS.length());
543:                            setCssPath(option);
544:                        } else if (option.startsWith(OPTION_STYLES)) {
545:                            // the editor styles XML path
546:                            option = option.substring(OPTION_STYLES.length());
547:                            setStylesXmlPath(option);
548:                        } else {
549:                            // check if option describes a gallery
550:                            if (OpenCms.getWorkplaceManager().getGalleries()
551:                                    .get(option) != null) {
552:                                // add the option to the displayed galleries
553:                                m_displayGalleries.add(option);
554:                            }
555:                        }
556:                    }
557:                }
558:            }
559:
560:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.