001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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 082 m_mode = mode; 083 } 084 085 /** 086 * @see org.opencms.ui.apps.dbmanager.I_CmsReportApp#goToMainView() 087 */ 088 public void goToMainView() { 089 090 openSubView("", true); 091 } 092 093 /** 094 * @see org.opencms.ui.apps.dbmanager.I_CmsReportApp#openReport(java.lang.String, org.opencms.report.A_CmsReportThread, java.lang.String) 095 */ 096 public void openReport(String path, A_CmsReportThread thread, String title) { 097 098 m_reports.put(path, thread); 099 m_labels.put(thread, title); 100 openSubView(path, true); 101 } 102 103 /** 104 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getBreadCrumbForState(java.lang.String) 105 */ 106 @Override 107 protected LinkedHashMap<String, String> getBreadCrumbForState(String state) { 108 109 LinkedHashMap<String, String> crumbs = new LinkedHashMap<String, String>(); 110 111 if (CmsStringUtil.isEmptyOrWhitespaceOnly(state) 112 | state.startsWith(PATH_REPORT_HTTP) 113 | state.startsWith(PATH_REPORT_SERVER)) { 114 if (m_mode.equals(Mode.HTTP)) { 115 crumbs.put("", CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_IMPORTHTTP_ADMIN_TOOL_NAME_0)); 116 } else { 117 crumbs.put("", CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_IMPORTSERVER_ADMIN_TOOL_NAME_0)); 118 } 119 return crumbs; 120 } 121 return new LinkedHashMap<String, String>(); 122 } 123 124 /** 125 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getComponentForState(java.lang.String) 126 */ 127 @Override 128 protected Component getComponentForState(String state) { 129 130 if (CmsStringUtil.isEmptyOrWhitespaceOnly(state)) { 131 if (m_mode.equals(Mode.HTTP)) { 132 return new CmsDbImportHTTP(this); 133 } else { 134 return new CmsDbImportServer(this); 135 } 136 } 137 if (state.startsWith(PATH_REPORT_SERVER) | state.startsWith(PATH_REPORT_HTTP)) { 138 CmsBasicReportPage reportForm = new CmsBasicReportPage( 139 m_labels.get(m_reports.get(state)), 140 m_reports.get(state), 141 new Runnable() { 142 143 public void run() { 144 145 openSubView("", true); 146 } 147 }); 148 reportForm.setHeight("100%"); 149 return reportForm; 150 } 151 return null; 152 } 153 154 /** 155 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getSubNavEntries(java.lang.String) 156 */ 157 @Override 158 protected List<NavEntry> getSubNavEntries(String state) { 159 160 return null; 161 } 162}