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.sitemanager; 029 030import org.opencms.ade.configuration.CmsADEManager; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsProject; 033import org.opencms.file.CmsProperty; 034import org.opencms.file.CmsPropertyDefinition; 035import org.opencms.file.CmsResource; 036import org.opencms.file.CmsResourceFilter; 037import org.opencms.file.types.CmsResourceTypeFolderSubSitemap; 038import org.opencms.file.types.CmsResourceTypeJsp; 039import org.opencms.file.types.I_CmsResourceType; 040import org.opencms.i18n.CmsLocaleManager; 041import org.opencms.main.CmsException; 042import org.opencms.main.CmsIllegalArgumentException; 043import org.opencms.main.CmsLog; 044import org.opencms.main.OpenCms; 045import org.opencms.relations.CmsRelation; 046import org.opencms.relations.CmsRelationFilter; 047import org.opencms.security.CmsOrganizationalUnit; 048import org.opencms.site.CmsSSLMode; 049import org.opencms.site.CmsSite; 050import org.opencms.site.CmsSiteMatcher; 051import org.opencms.ui.A_CmsUI; 052import org.opencms.ui.CmsVaadinUtils; 053import org.opencms.ui.apps.Messages; 054import org.opencms.ui.components.CmsBasicDialog; 055import org.opencms.ui.components.CmsRemovableFormRow; 056import org.opencms.ui.components.CmsResourceInfo; 057import org.opencms.ui.components.editablegroup.CmsEditableGroup; 058import org.opencms.ui.components.editablegroup.I_CmsEditableGroupRow; 059import org.opencms.ui.components.fileselect.CmsPathSelectField; 060import org.opencms.ui.report.CmsReportWidget; 061import org.opencms.util.CmsFileUtil; 062import org.opencms.util.CmsMacroResolver; 063import org.opencms.util.CmsStringUtil; 064import org.opencms.util.CmsUUID; 065 066import java.io.ByteArrayInputStream; 067import java.io.ByteArrayOutputStream; 068import java.io.IOException; 069import java.io.InputStream; 070import java.io.InputStreamReader; 071import java.io.OutputStream; 072import java.nio.charset.StandardCharsets; 073import java.util.ArrayList; 074import java.util.Collections; 075import java.util.HashMap; 076import java.util.HashSet; 077import java.util.List; 078import java.util.Map; 079import java.util.Map.Entry; 080import java.util.Properties; 081import java.util.Set; 082import java.util.SortedMap; 083import java.util.TreeMap; 084 085import org.apache.commons.logging.Log; 086 087import com.google.common.base.Supplier; 088import com.vaadin.event.FieldEvents.BlurEvent; 089import com.vaadin.event.FieldEvents.BlurListener; 090import com.vaadin.server.StreamResource; 091import com.vaadin.server.UserError; 092import com.vaadin.ui.Button; 093import com.vaadin.ui.Button.ClickEvent; 094import com.vaadin.ui.Button.ClickListener; 095import com.vaadin.ui.Component; 096import com.vaadin.ui.FormLayout; 097import com.vaadin.ui.Image; 098import com.vaadin.ui.Panel; 099import com.vaadin.ui.TabSheet; 100import com.vaadin.ui.UI; 101import com.vaadin.v7.data.Item; 102import com.vaadin.v7.data.Property.ValueChangeEvent; 103import com.vaadin.v7.data.Property.ValueChangeListener; 104import com.vaadin.v7.data.Validator; 105import com.vaadin.v7.data.util.BeanItemContainer; 106import com.vaadin.v7.data.util.IndexedContainer; 107import com.vaadin.v7.shared.ui.combobox.FilteringMode; 108import com.vaadin.v7.ui.AbstractField; 109import com.vaadin.v7.ui.CheckBox; 110import com.vaadin.v7.ui.ComboBox; 111import com.vaadin.v7.ui.TextField; 112import com.vaadin.v7.ui.Upload; 113import com.vaadin.v7.ui.Upload.Receiver; 114import com.vaadin.v7.ui.Upload.SucceededEvent; 115import com.vaadin.v7.ui.Upload.SucceededListener; 116import com.vaadin.v7.ui.VerticalLayout; 117 118/** 119 * Class for the Form to edit or add a site.<p> 120 */ 121public class CmsEditSiteForm extends CmsBasicDialog { 122 123 /** 124 * Bean for the ComboBox to edit the position.<p> 125 */ 126 public class PositionComboBoxElementBean { 127 128 /**Position of site in List. */ 129 private float m_position; 130 131 /**Title of site to show. */ 132 private String m_title; 133 134 /** 135 * Constructor. <p> 136 * 137 * @param title of site 138 * @param position of site 139 */ 140 public PositionComboBoxElementBean(String title, float position) { 141 142 m_position = position; 143 m_title = title; 144 } 145 146 /** 147 * Getter for position.<p> 148 * 149 * @return float position 150 */ 151 public float getPosition() { 152 153 return m_position; 154 } 155 156 /** 157 * Getter for title.<p> 158 * 159 * @return String title 160 */ 161 public String getTitle() { 162 163 return m_title; 164 } 165 } 166 167 /** 168 *Validator for server field.<p> 169 */ 170 class AliasValidator implements Validator { 171 172 /**vaadin serial id.*/ 173 private static final long serialVersionUID = 9014118214418269697L; 174 175 /** 176 * @see com.vaadin.v7.data.Validator#validate(java.lang.Object) 177 */ 178 public void validate(Object value) throws InvalidValueException { 179 180 String enteredServer = (String)value; 181 if (enteredServer == null) { 182 return; 183 } 184 if (enteredServer.isEmpty()) { 185 return; 186 } 187 if (m_alreadyUsedURL.contains(new CmsSiteMatcher(enteredServer))) { 188 if (!OpenCms.getSiteManager().getSites().get(new CmsSiteMatcher(enteredServer)).equals(m_site)) { 189 throw new InvalidValueException( 190 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SERVER_ALREADYUSED_1, enteredServer)); 191 } 192 } 193 if ((new CmsSiteMatcher(enteredServer)).equals(new CmsSiteMatcher(getFieldServer()))) { 194 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SERVER_EQUAL_ALIAS_0)); 195 } 196 if (isDoubleAlias(enteredServer)) { 197 throw new InvalidValueException( 198 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SERVER_ALREADYUSED_1, enteredServer)); 199 } 200 } 201 } 202 203 /** 204 * Receiver class for upload of favicon.<p> 205 */ 206 class FavIconReceiver implements Receiver, SucceededListener { 207 208 /**vaadin serial id. */ 209 private static final long serialVersionUID = 688021741970679734L; 210 211 /** 212 * @see com.vaadin.ui.Upload.Receiver#receiveUpload(java.lang.String, java.lang.String) 213 */ 214 public OutputStream receiveUpload(String filename, String mimeType) { 215 216 m_os.reset(); 217 if (!mimeType.startsWith("image")) { 218 return new ByteArrayOutputStream(0); 219 } 220 return m_os; 221 } 222 223 /** 224 * @see com.vaadin.ui.Upload.SucceededListener#uploadSucceeded(com.vaadin.ui.Upload.SucceededEvent) 225 */ 226 public void uploadSucceeded(SucceededEvent event) { 227 228 if (m_os.size() <= 1) { 229 m_imageCounter = 0; 230 m_fieldUploadFavIcon.setComponentError( 231 new UserError(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FAVICON_MIME_0))); 232 setFaviconIfExist(); 233 return; 234 } 235 if (m_os.size() > 4096) { 236 m_fieldUploadFavIcon.setComponentError( 237 new UserError(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FAVICON_SIZE_0))); 238 m_imageCounter = 0; 239 setFaviconIfExist(); 240 return; 241 } 242 m_imageCounter++; 243 setCurrentFavIcon(m_os.toByteArray()); 244 } 245 } 246 247 /** 248 *Validator for Folder Name field.<p> 249 */ 250 class FolderPathValidator implements Validator { 251 252 /**vaadin serial id.*/ 253 private static final long serialVersionUID = 2269520781911597613L; 254 255 /** 256 * @see com.vaadin.data.Validator#validate(java.lang.Object) 257 */ 258 public void validate(Object value) throws InvalidValueException { 259 260 String enteredName = (String)value; 261 if (FORBIDDEN_FOLDER_NAMES.contains(enteredName)) { 262 throw new InvalidValueException( 263 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FOLDERNAME_FORBIDDEN_1, enteredName)); 264 } 265 266 // if (m_alreadyUsedFolderPath.contains(getParentFolder() + enteredName)) { 267 if (OpenCms.getSiteManager().getSiteForRootPath(getParentFolder() + enteredName) != null) { 268 throw new InvalidValueException( 269 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FOLDERNAME_ALREADYUSED_1, enteredName)); 270 } 271 try { 272 CmsResource.checkResourceName(enteredName); 273 } catch (CmsIllegalArgumentException e) { 274 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FOLDERNAME_EMPTY_0)); 275 } 276 } 277 } 278 279 /** 280 * Validator for the parent field.<p> 281 */ 282 class ParentFolderValidator implements Validator { 283 284 /**vaadin serial id.*/ 285 private static final long serialVersionUID = 5217828150841769662L; 286 287 /** 288 * @see com.vaadin.data.Validator#validate(java.lang.Object) 289 */ 290 public void validate(Object value) throws InvalidValueException { 291 292 try { 293 m_clonedCms.getRequestContext().setSiteRoot(""); 294 m_clonedCms.readResource(getParentFolder()); 295 } catch (CmsException e) { 296 throw new InvalidValueException( 297 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_PARENTFOLDER_NOT_EXIST_0)); 298 } 299 if (OpenCms.getSiteManager().getSiteForRootPath( 300 CmsFileUtil.removeTrailingSeparator(getParentFolder())) != null) { 301 throw new InvalidValueException( 302 CmsVaadinUtils.getMessageText( 303 Messages.GUI_SITE_FOLDERNAME_ALREADYUSED_1, 304 CmsFileUtil.removeTrailingSeparator(getParentFolder()))); 305 } 306 if (!(getParentFolder()).startsWith(CmsSiteManager.PATH_SITES)) { 307 throw new InvalidValueException( 308 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FOLDERNAME_WRONGPARENT_0)); 309 } 310 311 if (!getSiteTemplatePath().isEmpty()) { 312 if (ensureFoldername(getParentFolder()).equals(ensureFoldername(getSiteTemplatePath()))) { 313 throw new InvalidValueException( 314 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FOLDERNAME_EQUAL_SITETEMPLATE_0)); 315 } 316 } 317 318 } 319 320 } 321 322 /** 323 * Validator for parent OU.<p> 324 */ 325 class SelectOUValidator implements Validator { 326 327 /**vaadin serial id.*/ 328 private static final long serialVersionUID = -911831798529729185L; 329 330 /** 331 * @see com.vaadin.data.Validator#validate(java.lang.Object) 332 */ 333 public void validate(Object value) throws InvalidValueException { 334 335 String OU = (String)value; 336 if (OU.equals("/")) { 337 return; //ok 338 } 339 340 if (OU.split("/").length < 2) { 341 return; //ou is under root 342 } 343 344 OU = OU.split("/")[0] + "/"; 345 346 if (getParentFolder().isEmpty() | getFieldFolder().isEmpty()) { 347 return; //not ok, but gets catched in an other validator 348 } 349 350 String rootPath = "/" + ensureFoldername(getParentFolder()) + ensureFoldername(getFieldFolder()); 351 352 boolean ok = false; 353 354 try { 355 List<CmsResource> res = OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(m_clonedCms, OU); 356 for (CmsResource resource : res) { 357 if (rootPath.startsWith(resource.getRootPath())) { 358 ok = true; 359 } 360 } 361 362 } catch (CmsException e) { 363 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_OU_INVALID_0)); 364 } 365 if (!ok) { 366 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_OU_INVALID_0)); 367 } 368 } 369 370 } 371 372 /** 373 * Validator for parent OU.<p> 374 */ 375 class SelectParentOUValidator implements Validator { 376 377 /**vaadin serial id.*/ 378 private static final long serialVersionUID = -911831798529729185L; 379 380 /** 381 * @see com.vaadin.v7.data.Validator#validate(java.lang.Object) 382 */ 383 public void validate(Object value) throws InvalidValueException { 384 385 String parentOU = (String)value; 386 if (parentOU.equals("/")) { 387 return; //ok 388 } 389 390 if (getParentFolder().isEmpty() | getFieldFolder().isEmpty()) { 391 return; //not ok, but gets catched in an other validator 392 } 393 394 String rootPath = "/" + ensureFoldername(getParentFolder()) + ensureFoldername(getFieldFolder()); 395 396 boolean ok = false; 397 398 try { 399 List<CmsResource> res = OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit( 400 m_clonedCms, 401 parentOU); 402 for (CmsResource resource : res) { 403 if (rootPath.startsWith(resource.getRootPath())) { 404 ok = true; 405 } 406 } 407 408 } catch (CmsException e) { 409 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_PARENTOU_INVALID_0)); 410 } 411 if (!ok) { 412 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_PARENTOU_INVALID_0)); 413 } 414 } 415 416 } 417 418 /** 419 *Validator for server field.<p> 420 */ 421 class ServerValidator implements Validator { 422 423 /**vaadin serial id.*/ 424 private static final long serialVersionUID = 9014118214418269697L; 425 426 /** 427 * @see com.vaadin.data.Validator#validate(java.lang.Object) 428 */ 429 public void validate(Object value) throws InvalidValueException { 430 431 String enteredServer = (String)value; 432 if (enteredServer.isEmpty()) { 433 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SERVER_EMPTY_0)); 434 } 435 if (m_alreadyUsedURL.contains(new CmsSiteMatcher(enteredServer))) { 436 throw new InvalidValueException( 437 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SERVER_ALREADYUSED_1, enteredServer)); 438 } 439 } 440 } 441 442 /** 443 * Validator for site root (in case of editing a site, fails for broken sites.<p> 444 */ 445 class SiteRootValidator implements Validator { 446 447 /**vaadin serial id.*/ 448 private static final long serialVersionUID = 7499390905843603642L; 449 450 /** 451 * @see com.vaadin.v7.data.Validator#validate(java.lang.Object) 452 */ 453 @Deprecated 454 public void validate(Object value) throws InvalidValueException { 455 456 CmsSite parentSite = m_manager.getElement(CmsFileUtil.removeTrailingSeparator((String)value)); 457 if (parentSite != null) { 458 if (!parentSite.equals(m_site)) { 459 throw new InvalidValueException( 460 CmsVaadinUtils.getMessageText( 461 Messages.GUI_SITE_FOLDERNAME_ALREADYUSED_1, 462 CmsFileUtil.removeTrailingSeparator((String)value))); 463 } 464 } 465 466 CmsProject currentProject = m_clonedCms.getRequestContext().getCurrentProject(); 467 try { 468 469 m_clonedCms.getRequestContext().setCurrentProject( 470 m_clonedCms.readProject(CmsProject.ONLINE_PROJECT_ID)); 471 m_clonedCms.readResource((String)value); 472 473 } catch (CmsException e) { 474 m_clonedCms.getRequestContext().setCurrentProject(currentProject); 475 if (!m_clonedCms.existsResource((String)value)) { 476 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SITEROOT_WRONG_0)); 477 } 478 } 479 480 m_clonedCms.getRequestContext().setCurrentProject(currentProject); 481 } 482 483 } 484 485 /** 486 * Validator for Site Template selection field.<p> 487 */ 488 class SiteTemplateValidator implements Validator { 489 490 /**vaadin serial id.*/ 491 private static final long serialVersionUID = -8730991818750657154L; 492 493 /** 494 * @see com.vaadin.data.Validator#validate(java.lang.Object) 495 */ 496 public void validate(Object value) throws InvalidValueException { 497 498 String pathToCheck = (String)value; 499 if (pathToCheck == null) { 500 return; 501 } 502 if (pathToCheck.isEmpty()) { //Empty -> no template chosen, ok 503 return; 504 } 505 if (!getParentFolder().isEmpty() & !getFieldFolder().isEmpty()) { 506 String rootPath = "/" + ensureFoldername(getParentFolder()) + ensureFoldername(getFieldFolder()); 507 508 if (m_clonedCms.existsResource(rootPath)) { 509 throw new InvalidValueException( 510 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SITETEMPLATE_OVERWRITE_0)); 511 } 512 } 513 try { 514 m_clonedCms.readResource(pathToCheck + CmsADEManager.CONTENT_FOLDER_NAME); 515 } catch (CmsException e) { 516 throw new InvalidValueException( 517 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SITETEMPLATE_INVALID_0)); 518 } 519 } 520 521 } 522 523 /** 524 * Validator for the title field.<p> 525 */ 526 class TitleValidator implements Validator { 527 528 /**vaadin serial id.*/ 529 private static final long serialVersionUID = 7878441125879949490L; 530 531 /** 532 * @see com.vaadin.data.Validator#validate(java.lang.Object) 533 */ 534 public void validate(Object value) throws InvalidValueException { 535 536 if (CmsStringUtil.isEmptyOrWhitespaceOnly((String)value)) { 537 throw new InvalidValueException(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_TITLE_EMPTY_0)); 538 } 539 540 } 541 542 } 543 544 /** The module name constant. */ 545 public static final String MODULE_NAME = "org.opencms.ui.apps.sitemanager"; 546 547 /** Module parameter constant for the web server script. */ 548 public static final String PARAM_OU_DESCRIPTION = "oudescription"; 549 550 /**List of all forbidden folder names as new site-roots.*/ 551 static final List<String> FORBIDDEN_FOLDER_NAMES = new ArrayList<String>() { 552 553 private static final long serialVersionUID = 8074588073232610426L; 554 555 { 556 add("system"); 557 add(OpenCms.getSiteManager().getSharedFolder().replaceAll("/", "")); 558 } 559 }; 560 561 /** The logger for this class. */ 562 static Log LOG = CmsLog.getLog(CmsEditSiteForm.class.getName()); 563 564 /**vaadin serial id.*/ 565 private static final long serialVersionUID = -1011525709082939562L; 566 567 /**Flag to block change events. */ 568 protected boolean m_blockChange; 569 570 /**List of all folder names already used for sites. */ 571 List<String> m_alreadyUsedFolderPath = new ArrayList<String>(); 572 573 /**List of all urls already used for sites.*/ 574 Set<CmsSiteMatcher> m_alreadyUsedURL = new HashSet<CmsSiteMatcher>(); 575 576 /**cloned cms obejct.*/ 577 CmsObject m_clonedCms; 578 579 /**vaadin component.*/ 580 ComboBox m_fieldSelectOU; 581 582 /**vaadin coponent.*/ 583 ComboBox m_fieldSelectParentOU; 584 585 /**vaadin component. */ 586 Upload m_fieldUploadFavIcon; 587 588 /**Needed to check if favicon was changed. */ 589 int m_imageCounter; 590 591 /** The site manager instance.*/ 592 CmsSiteManager m_manager; 593 594 /**OutputStream to store the uploaded favicon temporarily. */ 595 ByteArrayOutputStream m_os = new ByteArrayOutputStream(5500); 596 597 /**current site which is supposed to be edited, null if site should be added.*/ 598 CmsSite m_site; 599 600 /**vaadin component.*/ 601 TabSheet m_tab; 602 603 /**button to add parameter.*/ 604 private Button m_addParameter; 605 606 /**vaadin component.*/ 607 private VerticalLayout m_aliases; 608 609 /**Edit group for workplace servers.*/ 610 private CmsEditableGroup m_aliasGroup; 611 612 /**automatic setted folder name.*/ 613 private String m_autoSetFolderName; 614 615 /**Map to connect vaadin text fields with bundle keys.*/ 616 private Map<TextField, String> m_bundleComponentKeyMap; 617 618 /**vaadin component.*/ 619 private FormLayout m_bundleValues; 620 621 /**vaadin component.*/ 622 private Button m_cancel; 623 624 /**vaadin component.*/ 625 private CheckBox m_fieldCreateOU; 626 627 /**vaadin component.*/ 628 private CmsPathSelectField m_fieldErrorPage; 629 630 /**vaadin component.*/ 631 private CheckBox m_fieldExclusiveError; 632 633 /**vaadin component.*/ 634 private CheckBox m_fieldExclusiveURL; 635 636 /**vaadin component. */ 637 private Image m_fieldFavIcon; 638 639 /**vaadin component. */ 640 private CheckBox m_fieldKeepTemplate; 641 642 /**vaadin component.*/ 643 private CmsPathSelectField m_fieldLoadSiteTemplate; 644 645 /**vaadin component.*/ 646 private ComboBox m_fieldPosition; 647 648 /**vaadin component.*/ 649 private TextField m_fieldSecureServer; 650 651 /**vaadin component.*/ 652 private CheckBox m_fieldWebServer; 653 654 /**vaadin component. */ 655 private Panel m_infoSiteRoot; 656 657 /**boolean indicates if folder name was changed by user.*/ 658 private boolean m_isFolderNameTouched; 659 660 /**vaadin component.*/ 661 private Button m_ok; 662 663 /**Click listener for ok button. */ 664 private Button.ClickListener m_okClickListener; 665 666 /**vaadin component.*/ 667 private FormLayout m_parameter; 668 669 /**Panel holding the report widget.*/ 670 private Panel m_report; 671 672 /**Vaadin component. */ 673 private ComboBox m_simpleFieldEncryption; 674 675 /**vaadin component.*/ 676 private TextField m_simpleFieldFolderName; 677 678 /**vaadin component.*/ 679 private CmsPathSelectField m_simpleFieldParentFolderName; 680 681 /**vaadin component.*/ 682 private TextField m_simpleFieldServer; 683 684 /**vaadin component.*/ 685 private CmsPathSelectField m_simpleFieldSiteRoot; 686 687 /**vaadin component.*/ 688 private ComboBox m_simpleFieldTemplate; 689 690 /**vaadin component.*/ 691 private TextField m_simpleFieldTitle; 692 693 /**List of templates. */ 694 private List<CmsResource> m_templates; 695 696 /**Layout for the report widget. */ 697 private FormLayout m_threadReport; 698 699 /** 700 * Public constructor.<p> 701 * 702 * @param cms CmsObject 703 * @param site Site to be shown / edited 704 * @param manager calling the dialog 705 * @param editable flag indicates if fields should be editable 706 */ 707 public CmsEditSiteForm(CmsObject cms, CmsSite site, CmsSiteManager manager, boolean editable) { 708 709 m_clonedCms = cms; 710 m_site = site; 711 m_manager = manager; 712 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 713 setUpComboBoxPosition(); 714 setUpComboBoxTemplate(); 715 setUpComboBoxSSL(); 716 setUpOUComboBox(m_fieldSelectOU); 717 setUpOUComboBox(m_fieldSelectParentOU); 718 m_tab.setHeight("400px"); 719 m_report.setVisible(false); 720 m_ok.setVisible(editable); 721 m_infoSiteRoot.setVisible(false); 722 if (editable) { 723 m_aliasGroup = new CmsEditableGroup(m_aliases, new Supplier<Component>() { 724 725 public Component get() { 726 727 Component c = createAliasComponent("", true); 728 c.setEnabled(false); 729 return c; 730 731 } 732 733 }, CmsVaadinUtils.getMessageText(Messages.GUI_SITE_ADD_ALIAS_0)); 734 m_aliasGroup.init(); 735 } 736 setFieldsForSite(editable); 737 m_cancel.addClickListener(e -> CmsVaadinUtils.getWindow(CmsEditSiteForm.this).close()); 738 } 739 740 /** 741 * Constructor.<p> 742 * Use this to create a new site.<p> 743 * 744 * @param manager the site manager instance 745 * @param cms the CmsObject 746 */ 747 public CmsEditSiteForm(CmsObject cms, CmsSiteManager manager) { 748 749 m_isFolderNameTouched = false; 750 m_blockChange = true; 751 m_autoSetFolderName = ""; 752 m_clonedCms = cms; 753 754 List<CmsSite> allSites = manager.getAllElements(); 755 allSites.addAll(manager.getCorruptedSites()); 756 757 for (CmsSite site : allSites) { 758 if (site.getSiteMatcher() != null) { 759 m_alreadyUsedFolderPath.add(site.getSiteRoot()); 760 } 761 } 762 763 m_alreadyUsedURL.addAll(OpenCms.getSiteManager().getSites().keySet()); 764 765 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 766 m_tab.setHeight("400px"); 767 m_infoSiteRoot.setVisible(false); 768 m_simpleFieldSiteRoot.setVisible(false); 769 770 if (!OpenCms.getSiteManager().isConfigurableWebServer()) { 771 m_fieldWebServer.setVisible(false); 772 m_fieldWebServer.setValue(new Boolean(true)); 773 774 } 775 776 m_fieldKeepTemplate.setVisible(false); 777 m_fieldKeepTemplate.setValue(Boolean.FALSE); 778 779 m_simpleFieldParentFolderName.setValue(CmsSiteManager.PATH_SITES); 780 m_simpleFieldParentFolderName.setUseRootPaths(true); 781 m_simpleFieldParentFolderName.setCmsObject(m_clonedCms); 782 m_simpleFieldParentFolderName.requireFolder(); 783 m_simpleFieldParentFolderName.setResourceFilter(CmsResourceFilter.DEFAULT_FOLDERS); 784 m_simpleFieldParentFolderName.addValueChangeListener(new ValueChangeListener() { 785 786 private static final long serialVersionUID = 4043563040462776139L; 787 788 public void valueChange(ValueChangeEvent event) { 789 790 try { 791 String folderPath = m_simpleFieldParentFolderName.getValue(); 792 if (CmsResourceTypeFolderSubSitemap.TYPE_SUBSITEMAP.equals( 793 OpenCms.getResourceManager().getResourceType( 794 m_clonedCms.readResource(folderPath)).getTypeName())) { 795 String newFolderName = folderPath.split("/")[folderPath.split("/").length - 1]; 796 m_simpleFieldFolderName.setValue(newFolderName); 797 m_simpleFieldParentFolderName.setValue( 798 m_simpleFieldParentFolderName.getValue().substring( 799 0, 800 folderPath.length() - 1 - newFolderName.length())); 801 m_isFolderNameTouched = true; 802 if (m_simpleFieldTitle.isEmpty()) { 803 CmsProperty title = m_clonedCms.readPropertyObject( 804 m_clonedCms.readResource(folderPath), 805 "Title", 806 false); 807 if (!CmsProperty.getNullProperty().equals(title)) { 808 m_simpleFieldTitle.setValue(title.getValue()); 809 } 810 } 811 } 812 } catch (CmsException e) { 813 // Resource was not found. Not ok, but will be validated later 814 } 815 setUpOUComboBox(m_fieldSelectParentOU); 816 setUpOUComboBox(m_fieldSelectOU); 817 } 818 819 }); 820 821 m_manager = manager; 822 823 m_addParameter.addClickListener(new ClickListener() { 824 825 private static final long serialVersionUID = 6814134727761004218L; 826 827 public void buttonClick(ClickEvent event) { 828 829 addParameter(null); 830 } 831 }); 832 833 m_okClickListener = new ClickListener() { 834 835 private static final long serialVersionUID = 6814134727761004218L; 836 837 public void buttonClick(ClickEvent event) { 838 839 setupValidators(); 840 setupValidatorAliase(); 841 if (isValidInputSimple() & isValidInputSiteTemplate() & isValidAliase()) { 842 submit(); 843 return; 844 } 845 if (isValidInputSimple()) { 846 if (isValidAliase()) { 847 m_tab.setSelectedTab(4); 848 return; 849 } 850 m_tab.setSelectedTab(3); 851 return; 852 } 853 m_tab.setSelectedTab(0); 854 } 855 }; 856 857 m_ok.addClickListener(m_okClickListener); 858 859 m_cancel.addClickListener(new ClickListener() { 860 861 private static final long serialVersionUID = -276802394623141951L; 862 863 public void buttonClick(ClickEvent event) { 864 865 closeDailog(false); 866 } 867 }); 868 869 m_fieldCreateOU.addValueChangeListener(new ValueChangeListener() { 870 871 private static final long serialVersionUID = -2837270577662919541L; 872 873 public void valueChange(ValueChangeEvent event) { 874 875 toggleSelectOU(); 876 877 } 878 }); 879 880 setUpComboBoxPosition(); 881 setUpComboBoxTemplate(); 882 setUpComboBoxSSL(); 883 setUpOUComboBox(m_fieldSelectOU); 884 setUpOUComboBox(m_fieldSelectParentOU); 885 886 m_fieldSecureServer.addValueChangeListener(new ValueChangeListener() { 887 888 private static final long serialVersionUID = -2837270577662919541L; 889 890 public void valueChange(ValueChangeEvent event) { 891 892 toggleSecureServer(); 893 } 894 }); 895 m_fieldExclusiveURL.setEnabled(false); 896 m_fieldExclusiveError.setEnabled(false); 897 Receiver uploadReceiver = new FavIconReceiver(); 898 899 m_fieldWebServer.setValue(new Boolean(true)); 900 901 m_fieldUploadFavIcon.setReceiver(uploadReceiver); 902 m_fieldUploadFavIcon.setButtonCaption(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_SELECT_FILE_0)); 903 m_fieldUploadFavIcon.setImmediate(true); 904 m_fieldUploadFavIcon.addSucceededListener((SucceededListener)uploadReceiver); 905 m_fieldUploadFavIcon.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FAVICON_NEW_0)); 906 m_fieldFavIcon.setVisible(false); 907 908 m_simpleFieldTitle.addBlurListener(new BlurListener() { 909 910 private static final long serialVersionUID = -4147179568264310325L; 911 912 public void blur(BlurEvent event) { 913 914 if (!getFieldTitle().isEmpty() & !isFolderNameTouched()) { 915 String niceName = OpenCms.getResourceManager().getNameGenerator().getUniqueFileName( 916 m_clonedCms, 917 "/sites", 918 getFieldTitle().toLowerCase()); 919 setFolderNameState(niceName); 920 setFieldFolder(niceName); 921 } 922 923 } 924 }); 925 926 m_simpleFieldFolderName.addBlurListener(new BlurListener() { 927 928 private static final long serialVersionUID = 2080245499551324408L; 929 930 public void blur(BlurEvent event) { 931 932 checkTemplate(); 933 setFolderNameState(null); 934 935 } 936 }); 937 938 m_fieldLoadSiteTemplate.addValidator(new SiteTemplateValidator()); 939 940 m_fieldLoadSiteTemplate.addValueChangeListener(new ValueChangeListener() { 941 942 private static final long serialVersionUID = -5859547073423161234L; 943 944 public void valueChange(ValueChangeEvent event) { 945 946 resetFields(); 947 loadMessageBundle(); 948 m_manager.centerWindow(); 949 950 } 951 }); 952 953 m_fieldLoadSiteTemplate.setUseRootPaths(true); 954 m_fieldLoadSiteTemplate.setCmsObject(m_clonedCms); 955 m_fieldLoadSiteTemplate.requireFolder(); 956 m_fieldLoadSiteTemplate.setResourceFilter(CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireFolder()); 957 958 m_fieldSelectParentOU.setEnabled(false); 959 960 m_report.setVisible(false); 961 m_blockChange = false; 962 963 m_aliasGroup = new CmsEditableGroup(m_aliases, new Supplier<Component>() { 964 965 public Component get() { 966 967 return createAliasComponent("", true); 968 969 } 970 971 }, CmsVaadinUtils.getMessageText(Messages.GUI_SITE_ADD_ALIAS_0)); 972 m_aliasGroup.init(); 973 974 } 975 976 /** 977 * Constructor.<p> 978 * Used to edit existing site.<p> 979 * 980 * @param manager the manager instance 981 * @param siteRoot of site to edit 982 * @param cms the CmsObject 983 */ 984 public CmsEditSiteForm(CmsObject cms, CmsSiteManager manager, String siteRoot) { 985 986 this(cms, manager); 987 m_site = manager.getElement(siteRoot); 988 setFieldsForSite(true); 989 990 } 991 992 /** 993 * Creates an IndexedContaienr for use in SSL mode selection widgets.<p> 994 * 995 * @param captionProp the name of the property to use for captions 996 * @param includeOldStyle true if the old-style secure server mode should be included 997 * @param currentValue the current value of the mode (may be null) 998 * 999 * @return the container with the SSL mode items 1000 */ 1001 protected static IndexedContainer getSSLModeContainer( 1002 String captionProp, 1003 boolean includeOldStyle, 1004 CmsSSLMode currentValue) { 1005 1006 IndexedContainer res = new IndexedContainer(); 1007 res.addContainerProperty(captionProp, String.class, ""); 1008 boolean isLetsEncrypt = currentValue == CmsSSLMode.LETS_ENCRYPT; 1009 boolean letsEncryptConfigured = (OpenCms.getLetsEncryptConfig() != null) 1010 && OpenCms.getLetsEncryptConfig().isValidAndEnabled(); 1011 boolean skipLetsEncrypt = !letsEncryptConfigured && !isLetsEncrypt; 1012 1013 for (CmsSSLMode mode : CmsSSLMode.availableModes(includeOldStyle, !skipLetsEncrypt)) { 1014 Item item = res.addItem(mode); 1015 item.getItemProperty(captionProp).setValue(mode.getLocalizedMessage()); 1016 } 1017 return res; 1018 } 1019 1020 /** 1021 * Returns a Folder Name for a given site-root.<p> 1022 * 1023 * @param siteRoot site root of a site 1024 * @return Folder Name 1025 */ 1026 static String getFolderNameFromSiteRoot(String siteRoot) { 1027 1028 return siteRoot.split("/")[siteRoot.split("/").length - 1]; 1029 } 1030 1031 /** 1032 * Checks if site root exists in on and offline repository.<p> 1033 */ 1034 protected void checkOnOfflineSiteRoot() { 1035 1036 try { 1037 CmsObject cmsOnline = OpenCms.initCmsObject(m_clonedCms); 1038 cmsOnline.getRequestContext().setCurrentProject(m_clonedCms.readProject(CmsProject.ONLINE_PROJECT_ID)); 1039 1040 String rootPath = m_simpleFieldSiteRoot.getValue(); 1041 if (cmsOnline.existsResource(rootPath) & !m_clonedCms.existsResource(rootPath)) { 1042 m_ok.setEnabled(false); 1043 m_infoSiteRoot.setVisible(true); 1044 return; 1045 } 1046 1047 if (!m_site.getSiteRootUUID().isNullUUID()) { 1048 if (m_clonedCms.existsResource(m_site.getSiteRootUUID()) & !m_clonedCms.existsResource(rootPath)) { 1049 m_ok.setEnabled(false); 1050 m_infoSiteRoot.setVisible(true); 1051 return; 1052 } 1053 } 1054 1055 } catch (CmsException e) { 1056 LOG.error("Can not initialize CmsObject", e); 1057 } 1058 m_ok.setEnabled(true); 1059 m_infoSiteRoot.setVisible(false); 1060 } 1061 1062 /** 1063 * Checks the Template Property of the site root and fills the form field.<p> 1064 */ 1065 protected void checkTemplate() { 1066 1067 if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_simpleFieldFolderName.getValue())) { 1068 return; 1069 } 1070 if (!m_clonedCms.existsResource(getSiteRoot())) { 1071 return; 1072 } 1073 try { 1074 String templateValue = m_clonedCms.readPropertyObject( 1075 getSiteRoot(), 1076 CmsPropertyDefinition.PROPERTY_TEMPLATE, 1077 false).getValue(); 1078 m_simpleFieldTemplate.addItem(templateValue); 1079 m_simpleFieldTemplate.setValue(templateValue); 1080 } catch (CmsException e) { 1081 // 1082 } 1083 } 1084 1085 /** 1086 * Creates field for aliases.<p> 1087 * 1088 * @param alias url 1089 * @param red redirect 1090 * @return component 1091 */ 1092 protected FormLayout createAliasComponent(String alias, boolean red) { 1093 1094 FormLayout layout = new FormLayout(); 1095 TextField field = new TextField(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_ALIAS_0)); 1096 field.setWidth("100%"); 1097 field.setValue(alias); 1098 field.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_ALIAS_HELP_0)); 1099 CheckBox redirect = new CheckBox(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_ALIAS_REDIRECT_0), red); 1100 redirect.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_ALIAS_REDIRECT_HELP_0)); 1101 layout.addComponent(field); 1102 layout.addComponent(redirect); 1103 return layout; 1104 } 1105 1106 /** 1107 * Reads server field.<p> 1108 * 1109 * @return server as string 1110 */ 1111 protected String getFieldServer() { 1112 1113 return m_simpleFieldServer.getValue(); 1114 } 1115 1116 /** 1117 * Handles SSL changes.<p> 1118 */ 1119 protected void handleSSLChange() { 1120 1121 String toBeReplaced = "http:"; 1122 String newString = "https:"; 1123 CmsSSLMode mode = (CmsSSLMode)m_simpleFieldEncryption.getValue(); 1124 if (mode == null) { 1125 // mode is null if this is triggered by setContainerDataSource 1126 return; 1127 } 1128 if (mode.equals(CmsSSLMode.NO) | mode.equals(CmsSSLMode.SECURE_SERVER)) { 1129 toBeReplaced = "https:"; 1130 newString = "http:"; 1131 } 1132 m_simpleFieldServer.setValue(m_simpleFieldServer.getValue().replaceAll(toBeReplaced, newString)); 1133 m_fieldSecureServer.setVisible(mode.equals(CmsSSLMode.SECURE_SERVER)); 1134 m_fieldExclusiveError.setVisible(mode.equals(CmsSSLMode.SECURE_SERVER)); 1135 m_fieldExclusiveURL.setVisible(mode.equals(CmsSSLMode.SECURE_SERVER)); 1136 1137 } 1138 1139 /** 1140 * Sets the template field depending on current set site root field(s).<p> 1141 */ 1142 protected void setTemplateField() { 1143 1144 try { 1145 CmsProperty template = m_clonedCms.readPropertyObject( 1146 getSiteRoot(), 1147 CmsPropertyDefinition.PROPERTY_TEMPLATE, 1148 false); 1149 if (template.isNullProperty()) { 1150 m_simpleFieldTemplate.setValue(null); 1151 } else { 1152 m_simpleFieldTemplate.setValue(template.getStructureValue()); 1153 } 1154 } catch (CmsException e) { 1155 m_simpleFieldTemplate.setValue(null); 1156 } 1157 } 1158 1159 /** 1160 * Add a given parameter to the form layout.<p> 1161 * 1162 * @param parameter parameter to add to form 1163 */ 1164 void addParameter(String parameter) { 1165 1166 TextField textField = new TextField(); 1167 if (parameter != null) { 1168 textField.setValue(parameter); 1169 } 1170 CmsRemovableFormRow<TextField> row = new CmsRemovableFormRow<TextField>( 1171 textField, 1172 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_REMOVE_PARAMETER_0)); 1173 row.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_PARAMETER_0)); 1174 row.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_PARAMETER_HELP_0)); 1175 m_parameter.addComponent(row); 1176 } 1177 1178 /** 1179 * Closes the dialog.<p> 1180 * 1181 * @param updateTable <code>true</code> to update the site table 1182 */ 1183 void closeDailog(boolean updateTable) { 1184 1185 m_manager.closeDialogWindow(updateTable); 1186 } 1187 1188 /** 1189 * Checks if there are at least one character in the folder name, 1190 * also ensures that it ends with a '/' and doesn't start with '/'.<p> 1191 * 1192 * @param resourcename folder name to check (complete path) 1193 * @return the validated folder name 1194 * @throws CmsIllegalArgumentException if the folder name is empty or <code>null</code> 1195 */ 1196 String ensureFoldername(String resourcename) { 1197 1198 if (CmsStringUtil.isEmpty(resourcename)) { 1199 return ""; 1200 } 1201 if (!CmsResource.isFolder(resourcename)) { 1202 resourcename = resourcename.concat("/"); 1203 } 1204 if (resourcename.charAt(0) == '/') { 1205 resourcename = resourcename.substring(1); 1206 } 1207 return resourcename; 1208 } 1209 1210 /** 1211 * Returns the value of the site-folder.<p> 1212 * 1213 * @return String of folder path. 1214 */ 1215 String getFieldFolder() { 1216 1217 return m_simpleFieldFolderName.getValue(); 1218 } 1219 1220 /** 1221 * Reads title field.<p> 1222 * 1223 * @return title as string. 1224 */ 1225 String getFieldTitle() { 1226 1227 return m_simpleFieldTitle.getValue(); 1228 } 1229 1230 /** 1231 * Returns parent folder.<p> 1232 * 1233 * @return parent folder as string 1234 */ 1235 String getParentFolder() { 1236 1237 return m_simpleFieldParentFolderName.getValue(); 1238 } 1239 1240 /** 1241 * Returns the value of the site template field.<p> 1242 * 1243 * @return string root path 1244 */ 1245 String getSiteTemplatePath() { 1246 1247 return m_fieldLoadSiteTemplate.getValue(); 1248 } 1249 1250 /** 1251 * Checks if an alias was entered twice.<p> 1252 * 1253 * @param aliasName to check 1254 * @return true if it was defined double 1255 */ 1256 boolean isDoubleAlias(String aliasName) { 1257 1258 CmsSiteMatcher testAlias = new CmsSiteMatcher(aliasName); 1259 int count = 0; 1260 for (Component c : m_aliases) { 1261 if (c instanceof CmsRemovableFormRow<?>) { 1262 String alName = (String)((CmsRemovableFormRow<? extends AbstractField<?>>)c).getInput().getValue(); 1263 if (testAlias.equals(new CmsSiteMatcher(alName))) { 1264 count++; 1265 } 1266 } 1267 } 1268 return count > 1; 1269 } 1270 1271 /** 1272 * Checks if folder name was touched.<p> 1273 * 1274 * Considered as touched if side is edited or value of foldername was changed by user.<p> 1275 * 1276 * @return boolean true means Folder value was set by user or existing site and should not be changed by title-listener 1277 */ 1278 boolean isFolderNameTouched() { 1279 1280 if (m_site != null) { 1281 return true; 1282 } 1283 if (m_autoSetFolderName.equals(getFieldFolder())) { 1284 return false; 1285 } 1286 return m_isFolderNameTouched; 1287 } 1288 1289 /** 1290 * Are the aliase valid?<p> 1291 * 1292 * @return true if ok 1293 */ 1294 boolean isValidAliase() { 1295 1296 boolean ret = true; 1297 1298 for (I_CmsEditableGroupRow row : m_aliasGroup.getRows()) { 1299 FormLayout layout = (FormLayout)(row.getComponent()); 1300 TextField field = (TextField)layout.getComponent(0); 1301 ret = ret & field.isValid(); 1302 } 1303 return ret; 1304 } 1305 1306 /** 1307 * Checks if all required fields are set correctly at first Tab.<p> 1308 * 1309 * @return true if all inputs are valid. 1310 */ 1311 boolean isValidInputSimple() { 1312 1313 return (m_simpleFieldFolderName.isValid() 1314 & m_simpleFieldServer.isValid() 1315 & m_simpleFieldTitle.isValid() 1316 & m_simpleFieldParentFolderName.isValid() 1317 & m_fieldSelectOU.isValid() 1318 & m_simpleFieldSiteRoot.isValid()); 1319 } 1320 1321 /** 1322 * Checks if all required fields are set correctly at site template tab.<p> 1323 * 1324 * @return true if all inputs are valid. 1325 */ 1326 boolean isValidInputSiteTemplate() { 1327 1328 return (m_fieldLoadSiteTemplate.isValid() & m_fieldSelectParentOU.isValid()); 1329 } 1330 1331 /** 1332 * Loads message bundle from bundle defined inside the site-template which is used to create new site.<p> 1333 */ 1334 void loadMessageBundle() { 1335 1336 //Check if chosen site template is valid and not empty 1337 if (!m_fieldLoadSiteTemplate.isValid() 1338 | m_fieldLoadSiteTemplate.isEmpty() 1339 | !CmsSiteManager.isFolderWithMacros(m_clonedCms, m_fieldLoadSiteTemplate.getValue())) { 1340 return; 1341 } 1342 try { 1343 m_bundleComponentKeyMap = new HashMap<TextField, String>(); 1344 1345 //Get resource of the descriptor. 1346 CmsResource descriptor = m_clonedCms.readResource( 1347 m_fieldLoadSiteTemplate.getValue() 1348 + CmsSiteManager.MACRO_FOLDER 1349 + "/" 1350 + CmsSiteManager.BUNDLE_NAME 1351 + "_desc"); 1352 //Read related bundle 1353 1354 Properties resourceBundle = getLocalizedBundle(); 1355 Map<String, String[]> bundleKeyDescriptorMap = CmsMacroResolver.getBundleMapFromResources( 1356 resourceBundle, 1357 descriptor, 1358 m_clonedCms); 1359 1360 for (String key : bundleKeyDescriptorMap.keySet()) { 1361 1362 //Create TextField 1363 TextField field = new TextField(); 1364 field.setCaption(bundleKeyDescriptorMap.get(key)[0]); 1365 field.setValue(bundleKeyDescriptorMap.get(key)[1]); 1366 field.setWidth("100%"); 1367 1368 //Add vaadin component to UI and keep related key in HashMap 1369 m_bundleValues.addComponent(field); 1370 m_bundleComponentKeyMap.put(field, key); 1371 } 1372 } catch (CmsException | IOException e) { 1373 LOG.error("Error reading bundle", e); 1374 } 1375 } 1376 1377 /** 1378 * Clears the message bundle and removes related text fields from UI.<p> 1379 */ 1380 void resetFields() { 1381 1382 if (m_bundleComponentKeyMap != null) { 1383 Set<TextField> setBundles = m_bundleComponentKeyMap.keySet(); 1384 1385 for (TextField field : setBundles) { 1386 m_bundleValues.removeComponent(field); 1387 } 1388 m_bundleComponentKeyMap.clear(); 1389 } 1390 m_fieldKeepTemplate.setVisible(!CmsStringUtil.isEmptyOrWhitespaceOnly(m_fieldLoadSiteTemplate.getValue())); 1391 m_fieldKeepTemplate.setValue( 1392 Boolean.valueOf(!CmsStringUtil.isEmptyOrWhitespaceOnly(m_fieldLoadSiteTemplate.getValue()))); 1393 } 1394 1395 /** 1396 * Sets a new uploaded favicon and changes the caption of the upload button.<p> 1397 * 1398 * @param imageData holdings byte array of favicon 1399 */ 1400 void setCurrentFavIcon(final byte[] imageData) { 1401 1402 m_fieldFavIcon.setVisible(true); 1403 m_fieldUploadFavIcon.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_FAVICON_CHANGE_0)); 1404 m_fieldFavIcon.setSource(new StreamResource(new StreamResource.StreamSource() { 1405 1406 private static final long serialVersionUID = -8868657402793427460L; 1407 1408 public InputStream getStream() { 1409 1410 return new ByteArrayInputStream(imageData); 1411 } 1412 }, "")); 1413 } 1414 1415 /** 1416 * Tries to read and show the favicon of the site.<p> 1417 */ 1418 void setFaviconIfExist() { 1419 1420 try { 1421 CmsResource favicon = m_clonedCms.readResource(m_site.getSiteRoot() + "/" + CmsSiteManager.FAVICON); 1422 setCurrentFavIcon(m_clonedCms.readFile(favicon).getContents()); //FavIcon was found -> give it to the UI 1423 } catch (CmsException e) { 1424 //no favicon, do nothing 1425 } 1426 } 1427 1428 /** 1429 * Sets the folder field.<p> 1430 * 1431 * @param newValue value of the field 1432 */ 1433 void setFieldFolder(String newValue) { 1434 1435 m_simpleFieldFolderName.setValue(newValue); 1436 } 1437 1438 /** 1439 * Sets the folder Name state to recognize if folder field was touched.<p> 1440 * 1441 * @param setFolderName name of folder set by listener from title. 1442 */ 1443 void setFolderNameState(String setFolderName) { 1444 1445 if (setFolderName == null) { 1446 if (m_simpleFieldFolderName.getValue().isEmpty()) { 1447 m_isFolderNameTouched = false; 1448 return; 1449 } 1450 m_isFolderNameTouched = true; 1451 } else { 1452 m_autoSetFolderName = setFolderName; 1453 } 1454 } 1455 1456 /** 1457 * Enables the ok button after finishing report thread.<p> 1458 */ 1459 void setOkButtonEnabled() { 1460 1461 m_ok.setEnabled(true); 1462 m_ok.setCaption(CmsVaadinUtils.getMessageText(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_CLOSE_0)); 1463 m_ok.removeClickListener(m_okClickListener); 1464 m_ok.addClickListener(new ClickListener() { 1465 1466 private static final long serialVersionUID = 5637556711524961424L; 1467 1468 public void buttonClick(ClickEvent event) { 1469 1470 closeDailog(true); 1471 } 1472 }); 1473 } 1474 1475 /** 1476 * Fill ComboBox for OU selection.<p> 1477 * @param combo combo box 1478 */ 1479 void setUpOUComboBox(ComboBox combo) { 1480 1481 combo.removeAllItems(); 1482 try { 1483 if (m_site != null) { 1484 String siteOu = getSiteOU(); 1485 combo.addItem(siteOu); 1486 combo.select(siteOu); 1487 combo.setEnabled(false); 1488 } else { 1489 combo.addItem("/"); 1490 1491 m_clonedCms.getRequestContext().setSiteRoot(""); 1492 List<CmsOrganizationalUnit> ous = OpenCms.getOrgUnitManager().getOrganizationalUnits( 1493 m_clonedCms, 1494 "/", 1495 true); 1496 1497 for (CmsOrganizationalUnit ou : ous) { 1498 1499 if (ouIsOK(ou)) { 1500 combo.addItem(ou.getName()); 1501 } 1502 1503 } 1504 combo.select("/"); 1505 } 1506 1507 } catch (CmsException e) { 1508 LOG.error("Error on reading OUs", e); 1509 } 1510 combo.setNullSelectionAllowed(false); 1511 combo.setTextInputAllowed(true); 1512 combo.setFilteringMode(FilteringMode.CONTAINS); 1513 combo.setNewItemsAllowed(false); 1514 1515 } 1516 1517 /** 1518 * Setup for the aliase validator.<p> 1519 */ 1520 void setupValidatorAliase() { 1521 1522 for (I_CmsEditableGroupRow row : m_aliasGroup.getRows()) { 1523 FormLayout layout = (FormLayout)(row.getComponent()); 1524 TextField field = (TextField)layout.getComponent(0); 1525 field.removeAllValidators(); 1526 field.addValidator(new AliasValidator()); 1527 } 1528 } 1529 1530 /** 1531 * Setup validators which get called on click.<p> 1532 * Site-template gets validated separately.<p> 1533 */ 1534 void setupValidators() { 1535 1536 if (m_simpleFieldServer.getValidators().size() == 0) { 1537 if (m_site == null) { 1538 m_simpleFieldFolderName.addValidator(new FolderPathValidator()); 1539 m_simpleFieldParentFolderName.addValidator(new ParentFolderValidator()); 1540 } 1541 m_simpleFieldServer.addValidator(new ServerValidator()); 1542 m_simpleFieldTitle.addValidator(new TitleValidator()); 1543 if (m_site == null) { 1544 m_fieldSelectOU.addValidator(new SelectOUValidator()); 1545 } 1546 if (m_fieldCreateOU.getValue().booleanValue()) { 1547 m_fieldSelectParentOU.addValidator(new SelectParentOUValidator()); 1548 } 1549 } 1550 } 1551 1552 /** 1553 * Saves the entered site-data as a CmsSite object.<p> 1554 */ 1555 void submit() { 1556 1557 // switch to root site 1558 m_clonedCms.getRequestContext().setSiteRoot(""); 1559 1560 CmsSite site = getSiteFromForm(); 1561 1562 if (m_site == null) { 1563 1564 //Show report field and hide form fields 1565 m_report.setVisible(true); 1566 m_tab.setVisible(false); 1567 m_ok.setEnabled(false); 1568 m_ok.setVisible(true); 1569 //Change cancel caption to close (will not interrupt site creation anymore) 1570 m_cancel.setVisible(false); 1571 setOkButtonEnabled(); 1572 m_cancel.setCaption( 1573 CmsVaadinUtils.getMessageText(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_CLOSE_0)); 1574 1575 Map<String, String> bundle = getBundleMap(); 1576 1577 boolean createOU = m_fieldCreateOU.isEnabled() & m_fieldCreateOU.getValue().booleanValue(); 1578 CmsCreateSiteThread createThread = new CmsCreateSiteThread( 1579 m_clonedCms, 1580 m_manager, 1581 site, 1582 m_site, 1583 m_fieldLoadSiteTemplate.getValue(), 1584 getFieldTemplate(), 1585 createOU, 1586 (String)m_fieldSelectParentOU.getValue(), 1587 (String)m_fieldSelectOU.getValue(), 1588 m_os, 1589 bundle, 1590 new Runnable() { 1591 1592 public void run() { 1593 1594 } 1595 1596 }); 1597 1598 CmsReportWidget report = new CmsReportWidget(createThread); 1599 1600 report.setWidth("100%"); 1601 report.setHeight("350px"); 1602 1603 m_threadReport.addComponent(report); 1604 createThread.start(); 1605 } else { 1606 if (!site.getSiteRoot().equals(m_site.getSiteRoot())) { 1607 m_manager.deleteElements(Collections.singletonList(m_site.getSiteRoot())); 1608 } 1609 m_manager.writeElement(site); 1610 m_manager.closeDialogWindow(true); 1611 } 1612 1613 } 1614 1615 /** 1616 * Toogles secure server options.<p> 1617 */ 1618 void toggleSecureServer() { 1619 1620 if (m_fieldSecureServer.isEmpty()) { 1621 m_fieldExclusiveURL.setEnabled(false); 1622 m_fieldExclusiveError.setEnabled(false); 1623 return; 1624 } 1625 m_fieldExclusiveURL.setEnabled(true); 1626 m_fieldExclusiveError.setEnabled(true); 1627 } 1628 1629 /** 1630 * Toogles the select OU combo box depending on create ou check box.<p> 1631 */ 1632 void toggleSelectOU() { 1633 1634 boolean create = m_fieldCreateOU.getValue().booleanValue(); 1635 1636 m_fieldSelectOU.setEnabled(!create); 1637 m_fieldSelectParentOU.setEnabled(create); 1638 m_fieldSelectOU.select("/"); 1639 } 1640 1641 /** 1642 * Reads out all aliases from the form.<p> 1643 * 1644 * @return a List of CmsSiteMatcher 1645 */ 1646 private List<CmsSiteMatcher> getAliases() { 1647 1648 List<CmsSiteMatcher> ret = new ArrayList<CmsSiteMatcher>(); 1649 for (I_CmsEditableGroupRow row : m_aliasGroup.getRows()) { 1650 FormLayout layout = (FormLayout)(row.getComponent()); 1651 CheckBox box = (CheckBox)(layout.getComponent(1)); 1652 TextField field = (TextField)layout.getComponent(0); 1653 CmsSiteMatcher matcher = new CmsSiteMatcher(field.getValue()); 1654 matcher.setRedirect(box.getValue().booleanValue()); 1655 ret.add(matcher); 1656 } 1657 return ret; 1658 } 1659 1660 /** 1661 * Returns the correct varaint of a resource name accoreding to locale.<p> 1662 * 1663 * @param path where the considered resource is. 1664 * @param baseName of the resource 1665 * @return localized name of resource 1666 */ 1667 private String getAvailableLocalVariant(String path, String baseName) { 1668 1669 //First look for a bundle with the locale of the folder.. 1670 try { 1671 CmsProperty propLoc = m_clonedCms.readPropertyObject(path, CmsPropertyDefinition.PROPERTY_LOCALE, true); 1672 if (!propLoc.isNullProperty()) { 1673 if (m_clonedCms.existsResource(path + baseName + "_" + propLoc.getValue())) { 1674 return baseName + "_" + propLoc.getValue(); 1675 } 1676 } 1677 } catch (CmsException e) { 1678 LOG.error("Can not read locale property", e); 1679 } 1680 1681 //If no bundle was found with the locale of the folder, or the property was not set, search for other locales 1682 A_CmsUI.get(); 1683 List<String> localVariations = CmsLocaleManager.getLocaleVariants( 1684 baseName, 1685 UI.getCurrent().getLocale(), 1686 false, 1687 true); 1688 1689 for (String name : localVariations) { 1690 if (m_clonedCms.existsResource(path + name)) { 1691 return name; 1692 } 1693 } 1694 1695 return null; 1696 } 1697 1698 /** 1699 * Reads out bundle values from UI and stores keys with values in HashMap.<p> 1700 * 1701 * @return hash map 1702 */ 1703 private Map<String, String> getBundleMap() { 1704 1705 Map<String, String> bundles = new HashMap<String, String>(); 1706 1707 if (m_bundleComponentKeyMap != null) { 1708 Set<TextField> fields = m_bundleComponentKeyMap.keySet(); 1709 1710 for (TextField field : fields) { 1711 bundles.put(m_bundleComponentKeyMap.get(field), field.getValue()); 1712 } 1713 } 1714 return bundles; 1715 } 1716 1717 /** 1718 * Reads ComboBox with Template information.<p> 1719 * 1720 * @return string of chosen template path. 1721 */ 1722 private String getFieldTemplate() { 1723 1724 if (m_fieldKeepTemplate.getValue().booleanValue()) { 1725 return ""; //No template property will be changed 1726 } 1727 Object value = m_simpleFieldTemplate.getValue(); 1728 if (value != null) { 1729 return (String)value; 1730 } 1731 return ""; 1732 } 1733 1734 /** 1735 * Gets localized property object.<p> 1736 * 1737 * @return Properties object 1738 * @throws CmsException exception 1739 * @throws IOException exception 1740 */ 1741 private Properties getLocalizedBundle() throws CmsException, IOException { 1742 1743 CmsResource bundleResource = m_clonedCms.readResource( 1744 m_fieldLoadSiteTemplate.getValue() 1745 + CmsSiteManager.MACRO_FOLDER 1746 + "/" 1747 + getAvailableLocalVariant( 1748 m_fieldLoadSiteTemplate.getValue() + CmsSiteManager.MACRO_FOLDER + "/", 1749 CmsSiteManager.BUNDLE_NAME)); 1750 1751 Properties ret = new Properties(); 1752 InputStreamReader reader = new InputStreamReader( 1753 new ByteArrayInputStream(m_clonedCms.readFile(bundleResource).getContents()), 1754 StandardCharsets.UTF_8); 1755 ret.load(reader); 1756 1757 return ret; 1758 } 1759 1760 /** 1761 * Reads parameter from form.<p> 1762 * 1763 * @return a Map with Parameter information. 1764 */ 1765 private Map<String, String> getParameter() { 1766 1767 Map<String, String> ret = new TreeMap<String, String>(); 1768 for (Component c : m_parameter) { 1769 if (c instanceof CmsRemovableFormRow<?>) { 1770 String[] parameterStringArray = ((String)((CmsRemovableFormRow<? extends AbstractField<?>>)c).getInput().getValue()).split( 1771 "="); 1772 ret.put(parameterStringArray[0], parameterStringArray[1]); 1773 } 1774 } 1775 return ret; 1776 } 1777 1778 /** 1779 * Map entry of parameter to String representation.<p> 1780 * 1781 * @param parameter Entry holding parameter info. 1782 * @return the parameter formatted as string 1783 */ 1784 private String getParameterString(Entry<String, String> parameter) { 1785 1786 return parameter.getKey() + "=" + parameter.getValue(); 1787 } 1788 1789 /** 1790 * Reads out all forms and creates a site object.<p> 1791 * 1792 * @return the site object. 1793 */ 1794 private CmsSite getSiteFromForm() { 1795 1796 String siteRoot = getSiteRoot(); 1797 CmsSiteMatcher matcher = (CmsStringUtil.isNotEmpty(m_fieldSecureServer.getValue()) 1798 & m_simpleFieldEncryption.getValue().equals(CmsSSLMode.SECURE_SERVER)) 1799 ? new CmsSiteMatcher(m_fieldSecureServer.getValue()) 1800 : null; 1801 CmsSite site = OpenCms.getSiteManager().getSiteForSiteRoot(siteRoot); 1802 CmsUUID uuid = new CmsUUID(); 1803 if ((site != null) && (site.getSiteMatcher() != null)) { 1804 uuid = (CmsUUID)site.getSiteRootUUID().clone(); 1805 } 1806 String errorPage = CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_fieldErrorPage.getValue()) 1807 ? m_fieldErrorPage.getValue() 1808 : null; 1809 List<CmsSiteMatcher> aliases = getAliases(); 1810 CmsSite ret = new CmsSite( 1811 siteRoot, 1812 uuid, 1813 getFieldTitle(), 1814 new CmsSiteMatcher(getFieldServer()), 1815 ((PositionComboBoxElementBean)m_fieldPosition.getValue()).getPosition() == -1 1816 ? String.valueOf(m_site.getPosition()) 1817 : String.valueOf(((PositionComboBoxElementBean)m_fieldPosition.getValue()).getPosition()), 1818 errorPage, 1819 matcher, 1820 m_fieldExclusiveURL.getValue().booleanValue(), 1821 m_fieldExclusiveError.getValue().booleanValue(), 1822 m_fieldWebServer.getValue().booleanValue(), 1823 aliases); 1824 ret.setParameters((SortedMap<String, String>)getParameter()); 1825 ret.setSSLMode((CmsSSLMode)m_simpleFieldEncryption.getValue()); 1826 return ret; 1827 } 1828 1829 /** 1830 * Get ou name for current site.<p> 1831 * 1832 * @return Full ou name 1833 */ 1834 private String getSiteOU() { 1835 1836 try { 1837 m_clonedCms.getRequestContext().setSiteRoot(""); 1838 CmsResource resource = m_clonedCms.readResource(m_site.getSiteRoot()); 1839 List<CmsRelation> relations = m_clonedCms.getRelationsForResource(resource, CmsRelationFilter.SOURCES); 1840 for (CmsRelation relation : relations) { 1841 if (relation.getSourcePath().startsWith("/system/orgunits/")) { 1842 return (relation.getSourcePath().substring("/system/orgunits/".length())); 1843 } 1844 } 1845 } catch (CmsException e) { 1846 LOG.error("Error on reading OUs", e); 1847 } 1848 return "/"; 1849 } 1850 1851 /** 1852 * Gets the site root.<p> 1853 * Usable for new sites and for existing sites. 1854 * 1855 * @return site root string 1856 */ 1857 private String getSiteRoot() { 1858 1859 String res; 1860 1861 if (m_simpleFieldSiteRoot.isVisible()) { 1862 res = m_simpleFieldSiteRoot.getValue(); 1863 } else { 1864 res = "/" + ensureFoldername(getParentFolder()) + ensureFoldername(getFieldFolder()); 1865 res = res.endsWith("/") ? res.substring(0, res.length() - 1) : res; 1866 } 1867 return res; 1868 } 1869 1870 /** 1871 * Checks if given Ou has resources matching to currently set parent folder.<p> 1872 * 1873 * @param ou to check 1874 * @return true if ou is ok for parent folder 1875 */ 1876 private boolean ouIsOK(CmsOrganizationalUnit ou) { 1877 1878 try { 1879 for (CmsResource res : OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit( 1880 m_clonedCms, 1881 ou.getName())) { 1882 1883 if (m_simpleFieldParentFolderName.getValue().startsWith(res.getRootPath())) { 1884 return true; 1885 } 1886 1887 } 1888 } catch (CmsException e) { 1889 LOG.error("Unable to read Resources for Org Unit", e); 1890 } 1891 return false; 1892 } 1893 1894 /** 1895 * Sets the server field.<p> 1896 * 1897 * @param newValue value of the field. 1898 */ 1899 private void setFieldServer(String newValue) { 1900 1901 m_simpleFieldServer.setValue(newValue); 1902 } 1903 1904 /** 1905 * Sets the fields for a given site (m_site).<p> 1906 * 1907 * @param enableAll if true, the site is editable 1908 */ 1909 private void setFieldsForSite(boolean enableAll) { 1910 1911 try { 1912 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(m_site.getSiteRoot())) { 1913 CmsProperty prop = m_clonedCms.readPropertyObject( 1914 m_site.getSiteRoot(), 1915 CmsPropertyDefinition.PROPERTY_TEMPLATE, 1916 false); 1917 if (!prop.isNullProperty()) { 1918 if (!m_templates.contains(prop.getValue())) { 1919 m_simpleFieldTemplate.addItem(prop.getValue()); 1920 } 1921 m_simpleFieldTemplate.select(prop.getValue()); 1922 } else { 1923 if (!m_templates.isEmpty()) { 1924 m_simpleFieldTemplate.setValue(m_templates.get(0).getRootPath()); 1925 } 1926 } 1927 m_simpleFieldTemplate.setEnabled(enableAll); 1928 } 1929 } catch (CmsException e) { 1930 LOG.error("Unable to read template property.", e); 1931 } 1932 1933 m_simpleFieldSiteRoot.setVisible(true); 1934 m_simpleFieldSiteRoot.setValue(m_site.getSiteRoot()); 1935 m_simpleFieldSiteRoot.setCmsObject(m_clonedCms); 1936 m_simpleFieldSiteRoot.addValidator(new SiteRootValidator()); 1937 m_simpleFieldSiteRoot.setEnabled(enableAll); 1938 m_simpleFieldSiteRoot.addValueChangeListener(new ValueChangeListener() { 1939 1940 /**vaadin serial id. */ 1941 private static final long serialVersionUID = 4680456758446195524L; 1942 1943 public void valueChange(ValueChangeEvent event) { 1944 1945 setTemplateField(); 1946 checkOnOfflineSiteRoot(); 1947 } 1948 1949 }); 1950 m_simpleFieldParentFolderName.setVisible(false); 1951 m_simpleFieldFolderName.setVisible(false); 1952 1953 displayResourceInfoDirectly( 1954 Collections.singletonList( 1955 new CmsResourceInfo( 1956 m_site.getTitle(), 1957 m_site.getSiteRoot(), 1958 m_manager.getFavIcon(m_site.getSiteRoot())))); 1959 1960 m_tab.removeTab(m_tab.getTab(4)); 1961 m_simpleFieldTitle.removeTextChangeListener(null); 1962 m_simpleFieldTitle.setEnabled(enableAll); 1963 m_simpleFieldParentFolderName.setEnabled(false); 1964 m_simpleFieldParentFolderName.setValue( 1965 m_site.getSiteRoot().substring( 1966 0, 1967 m_site.getSiteRoot().length() 1968 - m_site.getSiteRoot().split("/")[m_site.getSiteRoot().split("/").length - 1].length())); 1969 1970 m_simpleFieldFolderName.removeAllValidators(); //can not be changed 1971 m_fieldCreateOU.setVisible(false); 1972 1973 m_alreadyUsedURL.remove(m_site.getSiteMatcher().forDifferentScheme("https")); //Remove current url to avoid validation problem 1974 m_alreadyUsedURL.remove(m_site.getSiteMatcher().forDifferentScheme("http")); 1975 1976 setFieldTitle(m_site.getTitle()); 1977 setFieldFolder(getFolderNameFromSiteRoot(m_site.getSiteRoot())); 1978 m_simpleFieldFolderName.setEnabled(false); 1979 m_simpleFieldTitle.setEnabled(enableAll); 1980 1981 setFieldServer(m_site.getUrl()); 1982 m_simpleFieldServer.setEnabled(enableAll); 1983 if (m_site.hasSecureServer()) { 1984 m_fieldSecureServer.setValue(m_site.getSecureUrl()); 1985 } 1986 if (m_site.getErrorPage() != null) { 1987 m_fieldErrorPage.setValue(m_site.getErrorPage()); 1988 } 1989 m_fieldWebServer.setValue(new Boolean(m_site.isWebserver())); 1990 m_fieldWebServer.setEnabled(enableAll); 1991 m_fieldExclusiveURL.setValue(new Boolean(m_site.isExclusiveUrl())); 1992 m_fieldExclusiveURL.setEnabled(enableAll); 1993 m_fieldExclusiveError.setValue(new Boolean(m_site.isExclusiveError())); 1994 m_fieldExclusiveError.setEnabled(enableAll); 1995 1996 Map<String, String> siteParameters = m_site.getParameters(); 1997 for (Entry<String, String> parameter : siteParameters.entrySet()) { 1998 addParameter(getParameterString(parameter)); 1999 } 2000 2001 List<CmsSiteMatcher> siteAliases = m_site.getAliases(); 2002 2003 for (CmsSiteMatcher siteMatcher : siteAliases) { 2004 if (enableAll) { 2005 m_aliasGroup.addRow(createAliasComponent(siteMatcher.getUrl(), siteMatcher.isRedirect())); 2006 } else { 2007 Component c = createAliasComponent(siteMatcher.getUrl(), siteMatcher.isRedirect()); 2008 c.setEnabled(false); 2009 m_aliases.addComponent(c); 2010 } 2011 } 2012 2013 setTemplateField(); 2014 2015 setUpComboBoxPosition(); 2016 2017 if (!m_fieldSecureServer.isEmpty()) { 2018 m_fieldExclusiveURL.setEnabled(true && enableAll); 2019 m_fieldExclusiveError.setEnabled(true && enableAll); 2020 } 2021 setFaviconIfExist(); 2022 checkOnOfflineSiteRoot(); 2023 m_fieldUploadFavIcon.setVisible(false); 2024 m_simpleFieldEncryption.setContainerDataSource(getSSLModeContainer("caption", true, m_site.getSSLMode())); 2025 m_simpleFieldEncryption.select(m_site.getSSLMode()); 2026 m_simpleFieldEncryption.setEnabled(enableAll); 2027 2028 m_fieldErrorPage.setEnabled(enableAll); 2029 m_addParameter.setVisible(enableAll); 2030 m_fieldPosition.setEnabled(enableAll); 2031 } 2032 2033 /** 2034 * Sets the title field.<p> 2035 * 2036 * @param newValue value of the field. 2037 */ 2038 private void setFieldTitle(String newValue) { 2039 2040 m_simpleFieldTitle.setValue(newValue); 2041 } 2042 2043 /** 2044 * Set the combo box for the position.<p> 2045 * Copied from workplace tool.<p> 2046 */ 2047 private void setUpComboBoxPosition() { 2048 2049 m_fieldPosition.removeAllItems(); 2050 2051 List<CmsSite> sites = new ArrayList<CmsSite>(); 2052 List<PositionComboBoxElementBean> beanList = new ArrayList<PositionComboBoxElementBean>(); 2053 for (CmsSite site : OpenCms.getSiteManager().getAvailableSites(m_clonedCms, true)) { 2054 if (site.getSiteMatcher() != null) { 2055 sites.add(site); 2056 } 2057 } 2058 2059 float maxValue = 0; 2060 float nextPos = 0; 2061 2062 // calculate value for the first navigation position 2063 float firstValue = 1; 2064 if (sites.size() > 0) { 2065 try { 2066 maxValue = sites.get(0).getPosition(); 2067 } catch (Exception e) { 2068 // should usually never happen 2069 } 2070 } 2071 2072 if (maxValue != 0) { 2073 firstValue = maxValue / 2; 2074 } 2075 2076 // add the first entry: before first element 2077 beanList.add( 2078 new PositionComboBoxElementBean( 2079 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_FIRST_0), 2080 firstValue)); 2081 2082 // show all present navigation elements in box 2083 for (int i = 0; i < sites.size(); i++) { 2084 2085 float navPos = sites.get(i).getPosition(); 2086 String siteRoot = sites.get(i).getSiteRoot(); 2087 // get position of next nav element 2088 nextPos = navPos + 2; 2089 if ((i + 1) < sites.size()) { 2090 nextPos = sites.get(i + 1).getPosition(); 2091 } 2092 // calculate new position of current nav element 2093 float newPos; 2094 if ((nextPos - navPos) > 1) { 2095 newPos = navPos + 1; 2096 } else { 2097 newPos = (navPos + nextPos) / 2; 2098 } 2099 // check new maxValue of positions and increase it 2100 if (navPos > maxValue) { 2101 maxValue = navPos; 2102 } 2103 // if the element is the current file, mark it in select box 2104 if ((m_site != null) && (m_site.getSiteRoot() != null) && m_site.getSiteRoot().equals(siteRoot)) { 2105 beanList.add( 2106 new PositionComboBoxElementBean( 2107 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_CURRENT_1, m_site.getTitle()), 2108 -1)); 2109 } else { 2110 beanList.add(new PositionComboBoxElementBean(sites.get(i).getTitle(), newPos)); 2111 } 2112 } 2113 2114 // add the entry: at the last position 2115 PositionComboBoxElementBean lastEntry = new PositionComboBoxElementBean( 2116 CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_LAST_0), 2117 maxValue + 1); 2118 beanList.add(lastEntry); 2119 2120 // add the entry: no change 2121 beanList.add( 2122 new PositionComboBoxElementBean(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_NOCHANGE_0), -1)); 2123 2124 BeanItemContainer<PositionComboBoxElementBean> objects = new BeanItemContainer<PositionComboBoxElementBean>( 2125 PositionComboBoxElementBean.class, 2126 beanList); 2127 2128 m_fieldPosition.setContainerDataSource(objects); 2129 m_fieldPosition.setItemCaptionPropertyId("title"); 2130 m_fieldPosition.setValue(beanList.get(beanList.size() - 1)); 2131 if (m_site == null) { 2132 m_fieldPosition.setValue(lastEntry); 2133 } 2134 } 2135 2136 /** 2137 * Sets up the ComboBox for the SSL Mode.<p> 2138 */ 2139 private void setUpComboBoxSSL() { 2140 2141 IndexedContainer container = getSSLModeContainer("caption", true, null); 2142 2143 m_simpleFieldEncryption.setContainerDataSource(container); 2144 m_simpleFieldEncryption.setItemCaptionPropertyId("caption"); 2145 m_simpleFieldEncryption.setNullSelectionAllowed(false); 2146 m_simpleFieldEncryption.setNewItemsAllowed(false); 2147 m_simpleFieldEncryption.select(CmsSSLMode.getDefault()); 2148 2149 m_simpleFieldEncryption.addValueChangeListener(new ValueChangeListener() { 2150 2151 private static final long serialVersionUID = 3267990233897064320L; 2152 2153 public void valueChange(ValueChangeEvent event) { 2154 2155 if (m_blockChange) { 2156 return; 2157 } 2158 handleSSLChange(); 2159 } 2160 }); 2161 2162 m_fieldSecureServer.setVisible(CmsSSLMode.getDefault().equals(CmsSSLMode.SECURE_SERVER)); 2163 m_fieldExclusiveError.setVisible(CmsSSLMode.getDefault().equals(CmsSSLMode.SECURE_SERVER)); 2164 m_fieldExclusiveURL.setVisible(CmsSSLMode.getDefault().equals(CmsSSLMode.SECURE_SERVER)); 2165 2166 } 2167 2168 /** 2169 * Sets the combobox for the template.<p> 2170 */ 2171 private void setUpComboBoxTemplate() { 2172 2173 try { 2174 I_CmsResourceType templateType = OpenCms.getResourceManager().getResourceType( 2175 CmsResourceTypeJsp.getContainerPageTemplateTypeName()); 2176 m_templates = m_clonedCms.readResources("/system/", CmsResourceFilter.DEFAULT.addRequireType(templateType)); 2177 for (CmsResource res : m_templates) { 2178 m_simpleFieldTemplate.addItem(res.getRootPath()); 2179 } 2180 2181 if (!m_templates.isEmpty()) { 2182 m_simpleFieldTemplate.setValue(m_templates.get(0).getRootPath()); 2183 } 2184 2185 m_simpleFieldTemplate.setNewItemsAllowed(true); 2186 m_simpleFieldTemplate.setNullSelectionAllowed(true); 2187 2188 } catch (CmsException e) { 2189 // should not happen 2190 } 2191 } 2192}