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.main.OpenCms;
031import org.opencms.ui.CmsVaadinUtils;
032import org.opencms.ui.apps.A_CmsAttributeAwareApp;
033import org.opencms.ui.apps.Messages;
034import org.opencms.util.CmsStringUtil;
035
036import java.io.File;
037import java.util.ArrayList;
038import java.util.LinkedHashMap;
039import java.util.List;
040
041import com.vaadin.ui.Component;
042
043/**
044 * Class for database manager app.<p>A_CmsAttributeAwareApp
045 */
046public class CmsDbManager extends A_CmsAttributeAwareApp {
047
048    /** Name of the manifest file used in upload files. */
049    private static final String FILE_MANIFEST = "manifest.xml";
050
051    /** Name of the sub-folder containing the OpenCms module packages. */
052    private static final String FOLDER_MODULES = "modules";
053
054    /**
055     * Returns the list of all uploadable zip files and uploadable folders available on the server.<p>
056     *
057     * @param includeFolders if true, the uploadable folders are included in the list
058     * @return the list of all uploadable zip files and uploadable folders available on the server
059     */
060    protected static List<String> getFileListFromServer(boolean includeFolders) {
061
062        List<String> result = new ArrayList<String>();
063
064        // get the RFS package export path
065        String exportpath = OpenCms.getSystemInfo().getPackagesRfsPath();
066        File folder = new File(exportpath);
067
068        // get a list of all files of the packages folder
069        String[] files = folder.list();
070        if (files != null) {
071            for (int i = 0; i < files.length; i++) {
072                File diskFile = new File(exportpath, files[i]);
073                // check this is a file and ends with zip -> this is a database upload file
074                if (diskFile.isFile() && diskFile.getName().endsWith(".zip")) {
075                    result.add(diskFile.getName());
076                } else if (diskFile.isDirectory()
077                    && includeFolders
078                    && (!diskFile.getName().equalsIgnoreCase(FOLDER_MODULES))
079                    && ((new File(diskFile + File.separator + FILE_MANIFEST)).exists())) {
080                    // this is an unpacked package, add it to uploadable files
081                    result.add(diskFile.getName());
082                }
083            }
084        }
085        return result;
086    }
087
088    /**
089     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getBreadCrumbForState(java.lang.String)
090     */
091    @Override
092    protected LinkedHashMap<String, String> getBreadCrumbForState(String state) {
093
094        LinkedHashMap<String, String> crumbs = new LinkedHashMap<String, String>();
095
096        //Deeper path
097        if (CmsStringUtil.isEmptyOrWhitespaceOnly(state)) {
098            crumbs.put("", CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_STATS_TITLE_0));
099            return crumbs;
100        }
101
102        return new LinkedHashMap<String, String>(); //size==1 & state was not empty -> state doesn't match to known path
103
104    }
105
106    /**
107     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getComponentForState(java.lang.String)
108     */
109    @Override
110    protected Component getComponentForState(String state) {
111
112        if (CmsStringUtil.isEmptyOrWhitespaceOnly(state)) {
113            return new CmsResourceTypeStatsView();
114        }
115
116        return null;
117    }
118
119    /**
120     * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getSubNavEntries(java.lang.String)
121     */
122    @Override
123    protected List<NavEntry> getSubNavEntries(String state) {
124
125        return null;
126    }
127
128}