001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.apps.dbmanager; 029 030import org.opencms.report.A_CmsReportThread; 031import org.opencms.ui.CmsVaadinUtils; 032import org.opencms.ui.apps.A_CmsAttributeAwareApp; 033import org.opencms.ui.apps.Messages; 034import org.opencms.ui.components.CmsBasicReportPage; 035import org.opencms.util.CmsStringUtil; 036 037import java.util.IdentityHashMap; 038import java.util.LinkedHashMap; 039import java.util.List; 040import java.util.Map; 041 042import com.google.common.collect.Maps; 043import com.vaadin.ui.Component; 044 045/** 046 * Class for the database import app.<p> 047 */ 048public class CmsDbImportApp extends A_CmsAttributeAwareApp implements I_CmsReportApp { 049 050 /** 051 * Enumeration to distinguist between http- and server import. 052 */ 053 protected enum Mode { 054 /**Import per HTTP.*/ 055 HTTP, 056 /**Import from Server.*/ 057 SERVER; 058 } 059 060 /**Path to the report from import(HTTP). */ 061 public static final String PATH_REPORT_HTTP = "reportHTTP"; 062 063 /**Path to the report from import(server).*/ 064 public static final String PATH_REPORT_SERVER = "reportserver"; 065 066 /**Map to store labels with theire threads for showing the reports.*/ 067 private IdentityHashMap<A_CmsReportThread, String> m_labels = new IdentityHashMap<A_CmsReportThread, String>(); 068 069 /**Map to link threads to the current states. */ 070 private Map<String, A_CmsReportThread> m_reports = Maps.newHashMap(); 071 072 /**Import mode.*/ 073 private Mode m_mode; 074 075 /** 076 * Public constructor.<p> 077 * 078 * @param mode for import 079 */ 080 public CmsDbImportApp(Mode mode) { 081 m_mode = mode; 082 } 083 084 /** 085 * @see org.opencms.ui.apps.dbmanager.I_CmsReportApp#goToMainView() 086 */ 087 public void goToMainView() { 088 089 openSubView("", true); 090 } 091 092 /** 093 * @see org.opencms.ui.apps.dbmanager.I_CmsReportApp#openReport(java.lang.String, org.opencms.report.A_CmsReportThread, java.lang.String) 094 */ 095 public void openReport(String path, A_CmsReportThread thread, String title) { 096 097 m_reports.put(path, thread); 098 m_labels.put(thread, title); 099 openSubView(path, true); 100 } 101 102 /** 103 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getBreadCrumbForState(java.lang.String) 104 */ 105 @Override 106 protected LinkedHashMap<String, String> getBreadCrumbForState(String state) { 107 108 LinkedHashMap<String, String> crumbs = new LinkedHashMap<String, String>(); 109 110 if (CmsStringUtil.isEmptyOrWhitespaceOnly(state) 111 | state.startsWith(PATH_REPORT_HTTP) 112 | state.startsWith(PATH_REPORT_SERVER)) { 113 if (m_mode.equals(Mode.HTTP)) { 114 crumbs.put("", CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_IMPORTHTTP_ADMIN_TOOL_NAME_0)); 115 } else { 116 crumbs.put("", CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_IMPORTSERVER_ADMIN_TOOL_NAME_0)); 117 } 118 return crumbs; 119 } 120 return new LinkedHashMap<String, String>(); 121 } 122 123 /** 124 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getComponentForState(java.lang.String) 125 */ 126 @Override 127 protected Component getComponentForState(String state) { 128 129 if (CmsStringUtil.isEmptyOrWhitespaceOnly(state)) { 130 if (m_mode.equals(Mode.HTTP)) { 131 return new CmsDbImportHTTP(this); 132 } else { 133 return new CmsDbImportServer(this); 134 } 135 } 136 if (state.startsWith(PATH_REPORT_SERVER) | state.startsWith(PATH_REPORT_HTTP)) { 137 CmsBasicReportPage reportForm = new CmsBasicReportPage( 138 m_labels.get(m_reports.get(state)), 139 m_reports.get(state), 140 new Runnable() { 141 142 public void run() { 143 144 openSubView("", true); 145 } 146 }); 147 reportForm.setHeight("100%"); 148 return reportForm; 149 } 150 return null; 151 } 152 153 /** 154 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getSubNavEntries(java.lang.String) 155 */ 156 @Override 157 protected List<NavEntry> getSubNavEntries(String state) { 158 159 return null; 160 } 161}