1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.wizards.web; 24 25 import com.sun.star.awt.XWindowPeer; 26 import com.sun.star.lang.XMultiServiceFactory; 27 import com.sun.star.util.XStringSubstitution; 28 import com.sun.star.wizards.common.FileAccess; 29 import com.sun.star.wizards.common.Helper; 30 import com.sun.star.wizards.common.HelpIds; 31 import com.sun.star.wizards.common.JavaTools; 32 import com.sun.star.wizards.common.PropertyNames; 33 import com.sun.star.wizards.common.SystemDialog; 34 import com.sun.star.wizards.ui.event.ListModelBinder; 35 import com.sun.star.wizards.web.data.CGDocument; 36 import com.sun.star.wizards.web.data.CGFilter; 37 import com.sun.star.wizards.web.data.CGPublish; 38 import com.sun.star.wizards.web.data.CGSettings; 39 40 /** 41 * @author rpiterman 42 * This class implements general methods, used by different sub-classes (either WWD_Sturtup, or WWD_Events) 43 * or both. 44 */ 45 public abstract class WWD_General extends WebWizardDialog 46 { 47 48 private FileAccess fileAccess; 49 private SystemDialog docAddDialog, folderDialog, favIconDialog, zipDialog; 50 protected FTPDialog ftpDialog; 51 protected CGSettings settings; 52 /** 53 * true if proxies are on, which means, ftp is disabled. 54 */ 55 protected boolean proxies; 56 private XStringSubstitution xStringSubstitution; 57 getStatusDialog()58 protected StatusDialog getStatusDialog() 59 { 60 61 StatusDialog statusDialog = new StatusDialog(xMSF, StatusDialog.STANDARD_WIDTH, resources.resLoadingSession, false, new String[] 62 { 63 resources.prodName, PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING 64 }, HelpIds.getHelpIdString(HID0_STATUS_DIALOG)); 65 try 66 { 67 statusDialog.createWindowPeer(xControl.getPeer()); 68 } 69 catch (Exception e) 70 { 71 e.printStackTrace(); 72 } 73 74 return statusDialog; 75 } 76 77 /** 78 * @param xmsf 79 */ WWD_General(XMultiServiceFactory xmsf)80 public WWD_General(XMultiServiceFactory xmsf) 81 { 82 super(xmsf); 83 xStringSubstitution = SystemDialog.createStringSubstitution(xmsf); 84 } 85 86 /* 87 * File Dialog methods 88 */ getDocAddDialog()89 protected SystemDialog getDocAddDialog() 90 { 91 //if (docAddDialog == null) { 92 docAddDialog = SystemDialog.createOpenDialog(xMSF); 93 for (int i = 0; i < settings.cp_Filters.getSize(); i++) 94 { 95 CGFilter f = ((CGFilter) settings.cp_Filters.getElementAt(i)); 96 docAddDialog.addFilter( 97 JavaTools.replaceSubString(f.cp_Name, resources.prodName, "%PRODNAME"), f.cp_Filter, i == 0); 98 } 99 //docAddDialog.addFilter(resources.resSODocs, "*.oxt;*.sxw;*.sxc;*.sxd;*.sxi;*.sdw;*.sdc;*.sdd;*.sdi;*.sda;*.sdp" ,true); 100 //docAddDialog.addFilter(resources.resMSDocs, "*.doc;*.xls;*.ppt;*.pps",false); 101 //docAddDialog.addFilter(resources.resImages, "*.jpg;*.gif;*.png;*.bmp;*.tiff;*.jpeg;*.jpe",false); 102 //docAddDialog.addFilter(resources.resAllFiles,"*.*",false); 103 //} 104 return docAddDialog; 105 } 106 getZipDialog()107 protected SystemDialog getZipDialog() 108 { 109 if (zipDialog == null) 110 { 111 zipDialog = SystemDialog.createStoreDialog(xMSF); 112 zipDialog.addFilter(resources.resZipFiles, "*.zip", true); 113 } 114 return zipDialog; 115 } 116 getFTPDialog(CGPublish pub)117 protected FTPDialog getFTPDialog(CGPublish pub) 118 { 119 if (ftpDialog == null) 120 { 121 try 122 { 123 ftpDialog = new FTPDialog(xMSF, pub); 124 ftpDialog.createWindowPeer(xControl.getPeer()); 125 } 126 catch (Exception ex) 127 { 128 ex.printStackTrace(); 129 } 130 } 131 return ftpDialog; 132 } 133 showFolderDialog(String title, String description, String dir)134 protected String showFolderDialog(String title, String description, String dir) 135 { 136 if (folderDialog == null) 137 { 138 folderDialog = SystemDialog.createFolderDialog(xMSF); 139 } 140 return folderDialog.callFolderDialog(title, description, dir); 141 } 142 getFileAccess()143 protected FileAccess getFileAccess() 144 { 145 if (fileAccess == null) 146 { 147 try 148 { 149 fileAccess = new FileAccess(xMSF); 150 } 151 catch (Exception ex) 152 { 153 ex.printStackTrace(); 154 } 155 } 156 return fileAccess; 157 } 158 159 /** 160 * returns the document specified 161 * by the given short array. 162 * @param s 163 * @return 164 */ getDoc(short[] s)165 protected CGDocument getDoc(short[] s) 166 { 167 if (s.length == 0) 168 { 169 return null; 170 } 171 else if (settings.cp_DefaultSession.cp_Content.cp_Documents.getSize() <= s[0]) 172 { 173 return null; 174 } 175 else 176 { 177 return (CGDocument) settings.cp_DefaultSession.cp_Content.cp_Documents.getElementAt(s[0]); 178 } 179 } 180 181 /** 182 * how many documents are in the list? 183 * @return the number of documents in the docs list. 184 */ getDocsCount()185 protected int getDocsCount() 186 { 187 return settings.cp_DefaultSession.cp_Content.cp_Documents.getSize(); 188 } 189 190 /** 191 * fills the export listbox. 192 * @param listContent 193 */ fillExportList(Object[] listContent)194 protected void fillExportList(Object[] listContent) 195 { 196 ListModelBinder.fillList(lstDocTargetType, listContent, null); 197 } 198 199 /** 200 * returns a publisher object for the given name 201 * @param name one of the WebWizardConst constants : FTP 202 * @return 203 */ getPublisher(String name)204 protected CGPublish getPublisher(String name) 205 { 206 return (CGPublish) settings.cp_DefaultSession.cp_Publishing.getElement(name); 207 } 208 209 /** 210 * @return true if the checkbox "save session" is checked. 211 */ isSaveSession()212 protected boolean isSaveSession() 213 { 214 return (((Number) Helper.getUnoPropertyValue( 215 getModel(chkSaveSettings), PropertyNames.PROPERTY_STATE)).intValue() == 1); 216 } 217 218 /** 219 * @return the name to save the session (step 7) 220 */ getSessionSaveName()221 protected String getSessionSaveName() 222 { 223 return (String) Helper.getUnoPropertyValue( 224 getModel(cbSaveSettings), "Text"); 225 } 226 227 /** 228 * This method checks the status of the wizards and 229 * enables or disables the 'next' and the 'create' button. 230 * 231 */ checkSteps()232 protected void checkSteps() 233 { 234 /* first I check the document list. 235 * If it is empty, then step3 and on are disabled. 236 */ 237 if (checkDocList()) 238 { 239 checkPublish(); 240 } 241 } 242 243 /** 244 * enables/disables the steps 3 to 7) 245 * @param enabled true = enabled, false = disabled. 246 */ enableSteps(boolean enabled)247 private void enableSteps(boolean enabled) 248 { 249 250 if (!enabled && !isStepEnabled(3)) 251 { 252 return; 253 /* 254 * disbale steps 3-7 255 */ 256 } 257 for (int i = 3; i < 8; i++) 258 { 259 setStepEnabled(i, enabled, true); 260 /* in this place i just disable the finish button. 261 * later, in the checkPublish, which is only performed if 262 * this one is true, it will be enabled (if the check 263 * is positive) 264 */ 265 } 266 if (!enabled) 267 { 268 enableFinishButton(false); 269 } 270 } 271 272 /** 273 * Checks if the documents list is 274 * empty. If it is, disables the steps 3-7, and the 275 * create button. 276 * @return 277 */ checkDocList()278 protected boolean checkDocList() 279 { 280 if (settings.cp_DefaultSession.cp_Content.cp_Documents.getSize() == 0) 281 { 282 enableSteps(false); 283 return false; 284 } 285 else 286 { 287 enableSteps(true); 288 return true; 289 } 290 } 291 292 /** 293 * check if the save-settings input is ok. 294 * (eather the checkbox is unmarked, or, 295 * if it is marked, a session name exists. 296 * 297 */ checkSaveSession()298 public boolean checkSaveSession() 299 { 300 return (!isSaveSession() || 301 !getSessionSaveName().equals(PropertyNames.EMPTY_STRING)); 302 303 } 304 305 /** 306 * @return false if this publisher is not active, or, if it 307 * active, returns true if the url is not empty... 308 * if the url is empty, throws an exception 309 */ checkPublish(String s, Object text, String property)310 private boolean checkPublish(String s, Object text, String property) 311 { 312 CGPublish p = getPublisher(s); 313 if (p.cp_Publish) 314 { 315 String url = (String) Helper.getUnoPropertyValue(getModel(text), property); 316 if ((url == null) || (url.equals(PropertyNames.EMPTY_STRING))) 317 { 318 throw new IllegalArgumentException(); 319 } 320 else 321 { 322 return true; 323 } 324 } 325 else 326 { 327 return false; 328 } 329 } 330 331 /** 332 * 333 * @return false either if publishing input is wrong or there 334 * are no publishing targets chosen. returns true when at least 335 * one target is chosen, *and* all 336 * which are chosen are legal. 337 * If proxies are on, ftp publisher is ignored. 338 */ checkPublish_()339 private boolean checkPublish_() 340 { 341 try 342 { 343 return (checkPublish(LOCAL_PUBLISHER, txtLocalDir, "Text") | (!proxies && checkPublish(FTP_PUBLISHER, lblFTP, PropertyNames.PROPERTY_LABEL)) | checkPublish(ZIP_PUBLISHER, txtZip, "Text")) && checkSaveSession(); 344 } 345 catch (IllegalArgumentException ex) 346 { 347 return false; 348 } 349 } 350 351 /** 352 * This method checks if the publishing 353 * input is ok, and enables and disables 354 * the 'create' button. 355 * public because it is called from 356 * an event listener object. 357 */ checkPublish()358 public void checkPublish() 359 { 360 enableFinishButton(checkPublish_()); 361 } 362 363 /** 364 * shows a message box "Unexpected Error... " :-) 365 * @param ex 366 */ unexpectedError(Exception ex)367 protected void unexpectedError(Exception ex) 368 { 369 ex.printStackTrace(); 370 XWindowPeer peer = xControl.getPeer(); 371 AbstractErrorHandler.showMessage(xMSF, peer, resources.resErrUnexpected, ErrorHandler.ERROR_PROCESS_FATAL); 372 } 373 374 /** 375 * substitutes path variables with the corresponding values. 376 * @param path a path, which might contain OOo path variables. 377 * @return the path, after substituing path variables. 378 */ substitute(String path)379 protected String substitute(String path) 380 { 381 try 382 { 383 return xStringSubstitution.substituteVariables(path, false); 384 } 385 catch (Exception ex) 386 { 387 return path; 388 } 389 } 390 } 391