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


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/database/CmsHtmlImportDialog.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:51 $
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.tools.database;
033:
034:        import org.opencms.configuration.CmsImportExportConfiguration;
035:        import org.opencms.i18n.CmsEncoder;
036:        import org.opencms.importexport.CmsExtendedHtmlImportDefault;
037:        import org.opencms.jsp.CmsJspActionElement;
038:        import org.opencms.main.CmsException;
039:        import org.opencms.main.OpenCms;
040:        import org.opencms.util.CmsRequestUtil;
041:        import org.opencms.util.CmsStringUtil;
042:        import org.opencms.widgets.CmsCheckboxWidget;
043:        import org.opencms.widgets.CmsHttpUploadWidget;
044:        import org.opencms.widgets.CmsInputWidget;
045:        import org.opencms.widgets.CmsSelectWidget;
046:        import org.opencms.widgets.CmsSelectWidgetOption;
047:        import org.opencms.widgets.CmsVfsFileWidget;
048:        import org.opencms.widgets.I_CmsWidget;
049:        import org.opencms.workplace.CmsWidgetDialog;
050:        import org.opencms.workplace.CmsWidgetDialogParameter;
051:        import org.opencms.workplace.explorer.CmsNewResourceXmlPage;
052:        import org.opencms.workplace.tools.CmsToolDialog;
053:        import org.opencms.workplace.tools.CmsToolManager;
054:
055:        import java.io.File;
056:        import java.io.FileOutputStream;
057:        import java.util.ArrayList;
058:        import java.util.HashMap;
059:        import java.util.Iterator;
060:        import java.util.List;
061:        import java.util.Locale;
062:        import java.util.Map;
063:        import java.util.TreeMap;
064:
065:        import javax.servlet.http.HttpServletRequest;
066:        import javax.servlet.http.HttpServletResponse;
067:        import javax.servlet.jsp.PageContext;
068:
069:        import org.apache.commons.fileupload.FileItem;
070:
071:        /**
072:         * Dialog to define an extended HTML import in the administration view.<p>
073:         * 
074:         * WARNING: If the zip file is to great to upload, then only a log entry
075:         * is created from the following method and this dialog is only refreshed:<p>
076:         * {@link org.opencms.util.CmsRequestUtil#readMultipartFileItems(HttpServletRequest)}. <p>
077:         * 
078:         * There are three modes to show the dialog:<p>
079:         * 
080:         * <ul>
081:         *  <li>{@link #MODE_DEFAULT} 
082:         *      <ul>
083:         *          <li>HTTP-Upload is not shown.</li> 
084:         *          <li>default values are saved by action commit.</li>
085:         *      </ul>
086:         *  </li>
087:         *  <li>{@link #MODE_STANDARD} 
088:         *      <ul>
089:         *          <li>HTTP-Upload is shown.</li> 
090:         *          <li>the HTML files would be imported by action commit.</li>
091:         *      </ul>
092:         *  </li>
093:         *  <li>{@link #MODE_ADVANCED} 
094:         *      <ul>
095:         *          <li>This dialog is needed for the advanced button in the new Dialog for the user.</li> 
096:         *          <li>HTTP-Upload is shown.</li> 
097:         *          <li>DestinationDir is not shown.</li> 
098:         *          <li>InputDir is not shown.</li> 
099:         *          <li>the HTML files would be imported by action commit.</li>
100:         *      </ul>
101:         *  </li>
102:         * </ul>
103:         * 
104:         * @author Peter Bonrad
105:         * @author Anja Röttgers
106:         * 
107:         * @version $Revision: 1.6 $ 
108:         * 
109:         */
110:        public class CmsHtmlImportDialog extends CmsWidgetDialog {
111:
112:            /** the JSP path, which requested the default mode. */
113:            public static final String IMPORT_DEFAULT_PATH = "htmldefault.jsp";
114:
115:            /** the JSP path, which requested the standard mode. */
116:            public static final String IMPORT_STANDARD_PATH = "htmlimport.jsp";
117:
118:            /** localized messages Keys prefix. */
119:            public static final String KEY_PREFIX = "htmlimport";
120:
121:            /** shows this dialog in the advanced mode.*/
122:            public static final String MODE_ADVANCED = "advanced";
123:
124:            /** shows this dialog in the default mode.*/
125:            public static final String MODE_DEFAULT = "default";
126:
127:            /** shows this dialog in the standard mode.*/
128:            public static final String MODE_STANDARD = "standard";
129:
130:            /** Defines which pages are valid for this dialog. */
131:            public static final String[] PAGES = { "page1" };
132:
133:            /** The import JSP report workplace URI. */
134:            protected static final String IMPORT_ACTION_REPORT = PATH_WORKPLACE
135:                    + "admin/database/reports/htmlimport.jsp";
136:
137:            /** The HTML import object that is edited on this dialog. */
138:            protected CmsHtmlImport m_htmlimport;
139:
140:            /**the current mode of the dialog. */
141:            private String m_dialogMode;
142:
143:            /**
144:             * Public constructor with JSP action element.<p>
145:             * 
146:             * @param jsp an initialized JSP action element
147:             */
148:            public CmsHtmlImportDialog(CmsJspActionElement jsp) {
149:
150:                super (jsp);
151:            }
152:
153:            /**
154:             * Public constructor with JSP variables.<p>
155:             * 
156:             * @param context the JSP page context
157:             * @param req the JSP request
158:             * @param res the JSP response
159:             */
160:            public CmsHtmlImportDialog(PageContext context,
161:                    HttpServletRequest req, HttpServletResponse res) {
162:
163:                this (new CmsJspActionElement(context, req, res));
164:            }
165:
166:            /**
167:             * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
168:             */
169:            public void actionCommit() {
170:
171:                List errors = new ArrayList();
172:                setDialogObject(m_htmlimport);
173:
174:                try {
175:
176:                    if (isDisplayMode(MODE_DEFAULT)) {
177:                        // default mode the default values are saved in the configuration file
178:
179:                        m_htmlimport.validate(null, true);
180:
181:                        // fill the extended 
182:                        fillExtendedHtmlImportDefault();
183:
184:                        // save the default values in the file
185:                        OpenCms
186:                                .writeConfiguration(CmsImportExportConfiguration.class);
187:
188:                    } else {
189:                        // advanced and standard mode the importing is starting
190:                        FileItem fi = getHttpImportFileItem();
191:
192:                        m_htmlimport.validate(fi, false);
193:
194:                        // write the file in the temporary directory
195:                        writeHttpImportDir(fi);
196:
197:                        Map params = new HashMap();
198:
199:                        // set the name of this class to get dialog object in report
200:                        params.put(CmsHtmlImportReport.PARAM_CLASSNAME, this 
201:                                .getClass().getName());
202:
203:                        // set style to display report in correct layout
204:                        params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
205:
206:                        // set close link to get back to overview after finishing the import
207:                        params.put(PARAM_CLOSELINK, CmsToolManager
208:                                .linkForToolPath(getJsp(), "/database"));
209:
210:                        // redirect to the report output JSP
211:                        getToolManager().jspForwardPage(this ,
212:                                IMPORT_ACTION_REPORT, params);
213:                    }
214:                } catch (Throwable t) {
215:                    errors.add(t);
216:                }
217:
218:                // set the list of errors to display when saving failed
219:                setCommitErrors(errors);
220:            }
221:
222:            /**
223:             * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
224:             */
225:            protected String createDialogHtml(String dialog) {
226:
227:                StringBuffer result = new StringBuffer(1024);
228:
229:                result.append(createWidgetTableStart());
230:                // show error header once if there were validation errors
231:                result.append(createWidgetErrorHeader());
232:
233:                if (dialog.equals(PAGES[0])) {
234:
235:                    // create the widgets for the first dialog page
236:                    int row = (isDisplayMode(MODE_DEFAULT) ? 1
237:                            : (isDisplayMode(MODE_ADVANCED) ? 0 : 2));
238:                    result
239:                            .append(createWidgetBlockStart(key(Messages.GUI_HTMLIMPORT_BLOCK_LABEL_FOLDER_0)));
240:                    result.append(createDialogRowsHtml(0, row));
241:                    result.append(createWidgetBlockEnd());
242:                    row++;
243:
244:                    result
245:                            .append(createWidgetBlockStart(key(Messages.GUI_HTMLIMPORT_BLOCK_LABEL_GALLERY_0)));
246:                    result.append(createDialogRowsHtml(row, row + 2));
247:                    result.append(createWidgetBlockEnd());
248:
249:                    result
250:                            .append(createWidgetBlockStart(key(Messages.GUI_HTMLIMPORT_BLOCK_LABEL_SETTINGS_0)));
251:
252:                    result.append(createDialogRowsHtml(row + 3, row + 10));
253:                    result.append(createWidgetBlockEnd());
254:                }
255:
256:                result.append(createWidgetTableEnd());
257:                return result.toString();
258:            }
259:
260:            /**
261:             * This must be overwrite, because we need additional the 'enctype' parameter.<p>
262:             * 
263:             * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlContent()
264:             */
265:            protected String defaultActionHtmlContent() {
266:
267:                StringBuffer result = new StringBuffer(2048);
268:                result
269:                        .append(
270:                                "<form name=\"EDITOR\" id=\"EDITOR\" method=\"post\" action=\"")
271:                        .append(getDialogRealUri());
272:                result
273:                        .append(
274:                                "\" class=\"nomargin\" onsubmit=\"return submitAction('")
275:                        .append(DIALOG_OK)
276:                        .append(
277:                                "', null, 'EDITOR');\" enctype=\"multipart/form-data\">\n");
278:                result.append(dialogContentStart(getDialogTitle()));
279:                result.append(buildDialogForm());
280:                result.append(dialogContentEnd());
281:                result.append(dialogButtonsCustom());
282:                result.append(paramsAsHidden());
283:                if (getParamFramename() == null) {
284:                    result.append("\n<input type=\"hidden\" name=\"").append(
285:                            PARAM_FRAMENAME).append("\" value=\"\">\n");
286:                }
287:                result.append("</form>\n");
288:                result.append(getWidgetHtmlEnd());
289:                return result.toString();
290:            }
291:
292:            /**
293:             * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
294:             */
295:            protected void defineWidgets() {
296:
297:                initHtmlImportObject();
298:                setKeyPrefix(KEY_PREFIX);
299:
300:                if (!isDisplayMode(MODE_ADVANCED)) {
301:                    addWidget(getDialogParameter("inputDir",
302:                            new CmsInputWidget()));
303:                }
304:                if (!isDisplayMode(MODE_DEFAULT)) {
305:                    addWidget(getDialogParameter("httpDir",
306:                            new CmsHttpUploadWidget()));
307:                }
308:                if (!isDisplayMode(MODE_ADVANCED)) {
309:                    addWidget(getDialogParameter("destinationDir",
310:                            new CmsVfsFileWidget(false, getCms()
311:                                    .getRequestContext().getSiteRoot())));
312:                }
313:
314:                addWidget(getDialogParameter("imageGallery",
315:                        new CmsVfsFileWidget(false, getCms()
316:                                .getRequestContext().getSiteRoot())));
317:                addWidget(getDialogParameter("downloadGallery",
318:                        new CmsVfsFileWidget(false, getCms()
319:                                .getRequestContext().getSiteRoot())));
320:                addWidget(getDialogParameter("linkGallery",
321:                        new CmsVfsFileWidget(false, getCms()
322:                                .getRequestContext().getSiteRoot())));
323:
324:                addWidget(getDialogParameter("template", new CmsSelectWidget(
325:                        getTemplates())));
326:                addWidget(getDialogParameter("element", new CmsInputWidget()));
327:                addWidget(getDialogParameter("locale", new CmsSelectWidget(
328:                        getLocales())));
329:                addWidget(getDialogParameter("inputEncoding",
330:                        new CmsInputWidget()));
331:                addWidget(getDialogParameter("startPattern",
332:                        new CmsInputWidget()));
333:                addWidget(getDialogParameter("endPattern", new CmsInputWidget()));
334:
335:                addWidget(getDialogParameter("overwrite",
336:                        new CmsCheckboxWidget()));
337:                addWidget(getDialogParameter("keepBrokenLinks",
338:                        new CmsCheckboxWidget()));
339:            }
340:
341:            /**
342:             * This function fills the <code> {@link CmsHtmlImport} </code> Object based on 
343:             * the values in the import/export configuration file. <p>
344:             */
345:            protected void fillHtmlImport() {
346:
347:                CmsExtendedHtmlImportDefault extimport = OpenCms
348:                        .getImportExportManager()
349:                        .getExtendedHtmlImportDefault();
350:                m_htmlimport.setDestinationDir(extimport.getDestinationDir());
351:                m_htmlimport.setInputDir(extimport.getInputDir());
352:                m_htmlimport.setDownloadGallery(extimport.getDownloadGallery());
353:                m_htmlimport.setImageGallery(extimport.getImageGallery());
354:                m_htmlimport.setLinkGallery(extimport.getLinkGallery());
355:                m_htmlimport.setTemplate(extimport.getTemplate());
356:                m_htmlimport.setElement(extimport.getElement());
357:                m_htmlimport.setLocale(extimport.getLocale());
358:                m_htmlimport.setInputEncoding(extimport.getEncoding());
359:                m_htmlimport.setStartPattern(extimport.getStartPattern());
360:                m_htmlimport.setEndPattern(extimport.getEndPattern());
361:                m_htmlimport.setOverwrite(Boolean.valueOf(
362:                        extimport.getOverwrite()).booleanValue());
363:                m_htmlimport.setKeepBrokenLinks(Boolean.valueOf(
364:                        extimport.getKeepBrokenLinks()).booleanValue());
365:            }
366:
367:            /**
368:             * @see org.opencms.workplace.CmsWidgetDialog#fillWidgetValues(javax.servlet.http.HttpServletRequest)
369:             */
370:            protected void fillWidgetValues(HttpServletRequest request) {
371:
372:                Map parameters;
373:                if (getMultiPartFileItems() != null) {
374:                    parameters = CmsRequestUtil.readParameterMapFromMultiPart(
375:                            getCms().getRequestContext().getEncoding(),
376:                            getMultiPartFileItems());
377:                } else {
378:                    parameters = request.getParameterMap();
379:                }
380:                Map processedParameters = new HashMap();
381:                Iterator p = parameters.entrySet().iterator();
382:                // make sure all "hidden" widget parameters are decoded
383:                while (p.hasNext()) {
384:                    Map.Entry entry = (Map.Entry) p.next();
385:                    String key = (String) entry.getKey();
386:                    String[] values = (String[]) entry.getValue();
387:                    if (key.startsWith(HIDDEN_PARAM_PREFIX)) {
388:                        // this is an encoded hidden parameter
389:                        key = key.substring(HIDDEN_PARAM_PREFIX.length());
390:                        String[] newValues = new String[values.length];
391:                        for (int l = 0; l < values.length; l++) {
392:                            newValues[l] = CmsEncoder.decode(values[l],
393:                                    getCms().getRequestContext().getEncoding());
394:                        }
395:                        values = newValues;
396:                    }
397:                    processedParameters.put(key, values);
398:                }
399:
400:                // now process the parameters
401:                m_widgetParamValues = new HashMap();
402:                Iterator i = getWidgets().iterator();
403:
404:                while (i.hasNext()) {
405:                    // check for all widget base parameters            
406:                    CmsWidgetDialogParameter base = (CmsWidgetDialogParameter) i
407:                            .next();
408:
409:                    List params = new ArrayList();
410:                    int maxOccurs = base.getMaxOccurs();
411:
412:                    boolean onPage = false;
413:                    if (base.isCollectionBase()) {
414:                        // for a collection base, check if we are on the page where the collection base is shown
415:                        if (CmsStringUtil.isNotEmpty(getParamAction())
416:                                && !DIALOG_INITIAL.equals(getParamAction())) {
417:                            // if no action set (usually for first display of dialog) make sure all values are shown
418:                            // DIALOG_INITIAL is a special value for the first display and must be handled the same way
419:                            String page = getParamPage();
420:                            // keep in mind that since the paramPage will be set AFTER the widget values are filled,
421:                            // so the first time this page is called from another page the following will result to "false",
422:                            // but for every "submit" on the page this will be "true"
423:                            onPage = CmsStringUtil.isEmpty(page)
424:                                    || CmsStringUtil.isEmpty(base
425:                                            .getDialogPage())
426:                                    || base.getDialogPage().equals(page);
427:                        }
428:                    }
429:
430:                    for (int j = 0; j < maxOccurs; j++) {
431:                        // check for all possible values in the request parameters
432:                        String id = CmsWidgetDialogParameter.createId(base
433:                                .getName(), j);
434:
435:                        boolean required = (params.size() < base.getMinOccurs())
436:                                || (processedParameters.get(id) != null)
437:                                || (!onPage && base.hasValue(j));
438:
439:                        if (required) {
440:                            CmsWidgetDialogParameter param = new CmsWidgetDialogParameter(
441:                                    base, params.size(), j);
442:                            param.setKeyPrefix(KEY_PREFIX);
443:                            base.getWidget().setEditorValue(getCms(),
444:                                    processedParameters, this , param);
445:                            params.add(param);
446:                        }
447:                    }
448:                    m_widgetParamValues.put(base.getName(), params);
449:                }
450:            }
451:
452:            /**
453:             * This function creates a <code> {@link CmsWidgetDialogParameter} </code> Object based 
454:             * on the given properties.<p>
455:             * 
456:             * @param property the base object property to map the parameter to / from
457:             * @param widget the widget used for this dialog-parameter
458:             * 
459:             * @return a <code> {@link CmsWidgetDialogParameter} </code> Object
460:             */
461:            protected CmsWidgetDialogParameter getDialogParameter(
462:                    String property, I_CmsWidget widget) {
463:
464:                return new CmsWidgetDialogParameter(m_htmlimport, property,
465:                        PAGES[0], widget);
466:            }
467:
468:            /**
469:             * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
470:             */
471:            protected String[] getPageArray() {
472:
473:                return PAGES;
474:            }
475:
476:            /**
477:             * Initializes this widget dialog's object.<p>
478:             */
479:            protected void initHtmlImportObject() {
480:
481:                Object o;
482:                String uri = getJsp().getRequestContext().getUri();
483:                if (uri == null || uri.endsWith(IMPORT_STANDARD_PATH)) {
484:                    m_dialogMode = MODE_STANDARD;
485:                } else if (uri.endsWith(IMPORT_DEFAULT_PATH)) {
486:                    m_dialogMode = MODE_DEFAULT;
487:                } else {
488:                    m_dialogMode = MODE_ADVANCED;
489:                }
490:                if (CmsStringUtil.isEmpty(getParamAction())) {
491:                    o = new CmsHtmlImport(getJsp().getCmsObject());
492:                } else {
493:                    // this is not the initial call, get the job object from session
494:                    o = getDialogObject();
495:                }
496:
497:                if (!(o instanceof  CmsHtmlImport)) {
498:                    // create a new HTML import handler object
499:                    m_htmlimport = new CmsHtmlImport(getJsp().getCmsObject());
500:                } else {
501:                    // reuse HTML import handler object stored in session
502:                    m_htmlimport = (CmsHtmlImport) o;
503:                    // this is needed, because the user can switch between the sites, now get the current
504:                    m_htmlimport.setCmsObject(getJsp().getCmsObject());
505:                }
506:
507:                // gets the data from the configuration file
508:                fillHtmlImport();
509:            }
510:
511:            /**
512:             * @see org.opencms.workplace.CmsWorkplace#initMessages()
513:             */
514:            protected void initMessages() {
515:
516:                // add specific dialog resource bundle
517:                addMessages(Messages.get().getBundleName());
518:                // add default resource bundles
519:                super .initMessages();
520:            }
521:
522:            /**
523:             * This function fills the <code> {@link CmsExtendedHtmlImportDefault} </code> Object based on 
524:             * the current values in the dialog. <p>
525:             */
526:            private void fillExtendedHtmlImportDefault() {
527:
528:                CmsExtendedHtmlImportDefault extimport = OpenCms
529:                        .getImportExportManager()
530:                        .getExtendedHtmlImportDefault();
531:                extimport.setDestinationDir(m_htmlimport.getDestinationDir());
532:                extimport.setInputDir(m_htmlimport.getInputDir());
533:                extimport.setDownloadGallery(m_htmlimport.getDownloadGallery());
534:                extimport.setImageGallery(m_htmlimport.getImageGallery());
535:                extimport.setLinkGallery(m_htmlimport.getLinkGallery());
536:                extimport.setTemplate(m_htmlimport.getTemplate());
537:                extimport.setElement(m_htmlimport.getElement());
538:                extimport.setLocale(m_htmlimport.getLocale());
539:                extimport.setEncoding(m_htmlimport.getInputEncoding());
540:                extimport.setStartPattern(m_htmlimport.getStartPattern());
541:                extimport.setEndPattern(m_htmlimport.getEndPattern());
542:                extimport.setOverwrite(Boolean.toString(m_htmlimport
543:                        .isOverwrite()));
544:                extimport.setKeepBrokenLinks(Boolean.toString(m_htmlimport
545:                        .isKeepBrokenLinks()));
546:                OpenCms.getImportExportManager().setExtendedHtmlImportDefault(
547:                        extimport);
548:            }
549:
550:            /**
551:             * Returns a list with all available local's.<p>
552:             * 
553:             * @return a list with all available local's
554:             */
555:            private List getLocales() {
556:
557:                ArrayList ret = new ArrayList();
558:
559:                try {
560:                    Iterator i = OpenCms.getLocaleManager()
561:                            .getAvailableLocales().iterator();
562:
563:                    // loop through all local's and build the entries
564:                    while (i.hasNext()) {
565:                        Locale locale = (Locale) i.next();
566:                        String language = locale.getLanguage();
567:                        String displayLanguage = locale.getDisplayLanguage();
568:
569:                        ret.add(new CmsSelectWidgetOption(language, false,
570:                                displayLanguage));
571:                    }
572:                } catch (Exception e) {
573:                    // not necessary
574:                }
575:                return ret;
576:            }
577:
578:            /**
579:             * Returns a list with all available templates.<p>
580:             * 
581:             * @return a list with all available templates
582:             */
583:            private List getTemplates() {
584:
585:                ArrayList ret = new ArrayList();
586:                TreeMap templates = null;
587:
588:                try {
589:                    templates = CmsNewResourceXmlPage.getTemplates(getJsp()
590:                            .getCmsObject(), null);
591:
592:                    // loop through all templates and build the entries
593:                    Iterator i = templates.entrySet().iterator();
594:                    while (i.hasNext()) {
595:                        Map.Entry entry = (Map.Entry) i.next();
596:                        String title = (String) entry.getKey();
597:                        String path = (String) entry.getValue();
598:
599:                        ret.add(new CmsSelectWidgetOption(path, false, title));
600:                    }
601:                } catch (CmsException e) {
602:                    // not necessary
603:                }
604:
605:                return ret;
606:            }
607:
608:            /**
609:             * Checks if given mode is to show.<p>
610:             * 
611:             * @param mode [ {@link #MODE_DEFAULT} | {@link #MODE_STANDARD} | {@link #MODE_ADVANCED} ] 
612:             * 
613:             * @return <code>true</code> if the given display mode is to shown
614:             */
615:            private boolean isDisplayMode(String mode) {
616:
617:                return m_dialogMode.equals(mode);
618:            }
619:
620:            /**
621:             * This function reads the file item and if its exits then the 
622:             * file is saved in the temporary directory of the system.<p>
623:             * 
624:             * @param fi the file item from the multipart-request
625:             * 
626:             * @throws CmsException if something goes wrong.
627:             */
628:            private void writeHttpImportDir(FileItem fi) throws CmsException {
629:
630:                try {
631:
632:                    if (fi != null
633:                            && CmsStringUtil.isNotEmptyOrWhitespaceOnly(fi
634:                                    .getName())) {
635:                        //write the file in the tmp-directory of the system
636:                        byte[] content = fi.get();
637:                        File importFile = File.createTempFile("import_html",
638:                                ".zip");
639:                        //write the content in the tmp file
640:                        FileOutputStream fileOutput = new FileOutputStream(
641:                                importFile.getAbsolutePath());
642:                        fileOutput.write(content);
643:                        fileOutput.close();
644:                        fi.delete();
645:                        m_htmlimport.setHttpDir(importFile.getAbsolutePath());
646:                    }
647:                } catch (Exception e) {
648:                    throw new CmsException(Messages.get().container(
649:                            Messages.ERR_ACTION_ZIPFILE_UPLOAD_0));
650:                }
651:            }
652:
653:            /**
654:             * Checks if a multipart-request file item exists and returns it.<p>
655:             * 
656:             * @return <code>true</code> if a multipart-request file exists
657:             */
658:            private FileItem getHttpImportFileItem() {
659:
660:                FileItem result = null;
661:                m_htmlimport.setHttpDir("");
662:                // get the file item from the multipart-request
663:                Iterator it = getMultiPartFileItems().iterator();
664:                FileItem fi = null;
665:                while (it.hasNext()) {
666:                    fi = (FileItem) it.next();
667:                    if (fi.getName() != null) {
668:                        // found the file object, leave iteration
669:                        break;
670:                    } else {
671:                        // this is no file object, check next item
672:                        continue;
673:                    }
674:                }
675:
676:                if (fi != null
677:                        && CmsStringUtil.isNotEmptyOrWhitespaceOnly(fi
678:                                .getName())) {
679:                    result = fi;
680:                }
681:                return result;
682:            }
683:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.