1 31 32 package org.opencms.workplace.tools.database; 33 34 import org.opencms.jsp.CmsJspActionElement; 35 import org.opencms.main.OpenCms; 36 import org.opencms.widgets.CmsDisplayWidget; 37 import org.opencms.widgets.CmsSelectWidget; 38 import org.opencms.widgets.CmsSelectWidgetOption; 39 import org.opencms.workplace.CmsWidgetDialog; 40 import org.opencms.workplace.CmsWidgetDialogParameter; 41 import org.opencms.workplace.CmsWorkplaceSettings; 42 import org.opencms.workplace.tools.CmsToolDialog; 43 import org.opencms.workplace.tools.CmsToolManager; 44 45 import java.io.File ; 46 import java.io.IOException ; 47 import java.util.ArrayList ; 48 import java.util.HashMap ; 49 import java.util.Iterator ; 50 import java.util.List ; 51 import java.util.Map ; 52 53 import javax.servlet.ServletException ; 54 import javax.servlet.http.HttpServletRequest ; 55 import javax.servlet.http.HttpServletResponse ; 56 import javax.servlet.jsp.PageContext ; 57 58 67 public class CmsDatabaseImportFromServer extends CmsWidgetDialog { 68 69 70 public static final String DIALOG_TYPE = "DatabaseImportServer"; 71 72 73 public static final String [] PAGES = {"page1"}; 74 75 76 public static final String PARAM_IMPORTFILE = "importFile"; 77 78 79 protected static final String IMPORT_ACTION_REPORT = PATH_WORKPLACE + "admin/database/reports/import.jsp"; 80 81 82 private static final String FILE_MANIFEST = "manifest.xml"; 83 84 85 private static final String FOLDER_MODULES = "modules"; 86 87 88 private String m_importFile; 89 90 95 public CmsDatabaseImportFromServer(CmsJspActionElement jsp) { 96 97 super(jsp); 98 } 99 100 107 public CmsDatabaseImportFromServer(PageContext context, HttpServletRequest req, HttpServletResponse res) { 108 109 this(new CmsJspActionElement(context, req, res)); 110 } 111 112 118 protected static List getFileListFromServer(boolean includeFolders) { 119 120 List result = new ArrayList (); 121 122 String exportpath = OpenCms.getSystemInfo().getPackagesRfsPath(); 124 File folder = new File (exportpath); 125 126 String [] files = folder.list(); 128 for (int i = 0; i < files.length; i++) { 129 File diskFile = new File (exportpath, files[i]); 130 if (diskFile.isFile() && diskFile.getName().endsWith(".zip")) { 132 result.add(diskFile.getName()); 133 } else if (diskFile.isDirectory() 134 && includeFolders 135 && (!diskFile.getName().equalsIgnoreCase(FOLDER_MODULES)) 136 && ((new File (diskFile + File.separator + FILE_MANIFEST)).exists())) { 137 result.add(diskFile.getName()); 139 } 140 } 141 142 return result; 143 } 144 145 148 public void actionCommit() throws IOException , ServletException { 149 150 List errors = new ArrayList (); 151 152 Map params = new HashMap (); 153 params.put(PARAM_FILE, getImportFile()); 154 params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW); 156 params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/database")); 158 getToolManager().jspForwardPage(this, IMPORT_ACTION_REPORT, params); 160 setCommitErrors(errors); 162 } 163 164 169 public String getImportFile() { 170 171 return m_importFile; 172 } 173 174 179 public void setImportFile(String importFile) { 180 181 m_importFile = importFile; 182 } 183 184 190 protected String createDialogHtml(String dialog) { 191 192 StringBuffer result = new StringBuffer (1024); 193 194 result.append(createWidgetTableStart()); 196 197 result.append(createWidgetErrorHeader()); 199 200 if (dialog.equals(PAGES[0])) { 201 result.append(dialogBlockStart(key("label.block.importFileFromServer"))); 202 result.append(createWidgetTableStart()); 203 result.append(createDialogRowsHtml(0, 0)); 204 result.append(createWidgetTableEnd()); 205 result.append(dialogBlockEnd()); 206 } 207 208 result.append(createWidgetTableEnd()); 210 211 return result.toString(); 212 } 213 214 217 protected void defineWidgets() { 218 219 List files = getFilesFromServer(); 221 222 if (files.isEmpty()) { 223 addWidget(new CmsWidgetDialogParameter(this, PARAM_IMPORTFILE, PAGES[0], new CmsDisplayWidget(key(Messages.GUI_IMPORTSERVER_NO_DB_EXPORTS_0)))); 225 } else { 226 addWidget(new CmsWidgetDialogParameter(this, PARAM_IMPORTFILE, PAGES[0], new CmsSelectWidget(files))); 228 } 229 } 230 231 238 protected List getFilesFromServer() { 239 240 List retVal = new ArrayList (); 241 Iterator i = getFileListFromServer(true).iterator(); 242 while (i.hasNext()) { 243 String fileName = (String )i.next(); 244 retVal.add(new CmsSelectWidgetOption(fileName)); 245 } 246 return retVal; 247 } 248 249 252 protected String [] getPageArray() { 253 254 return PAGES; 255 } 256 257 260 protected void initMessages() { 261 262 addMessages(Messages.get().getBundleName()); 264 super.initMessages(); 266 } 267 268 271 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 272 273 setParamDialogtype(DIALOG_TYPE); 275 276 super.initWorkplaceRequestValues(settings, request); 277 } 278 } | Popular Tags |