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.ade.sitemap.client.edit; 029 030import org.opencms.ade.sitemap.client.CmsSitemapView; 031import org.opencms.ade.sitemap.client.Messages; 032import org.opencms.ade.sitemap.client.control.CmsSitemapController; 033import org.opencms.ade.sitemap.client.ui.css.I_CmsSitemapLayoutBundle; 034import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry; 035import org.opencms.file.CmsResource; 036import org.opencms.gwt.client.property.CmsReloadMode; 037import org.opencms.gwt.shared.CmsListInfoBean; 038import org.opencms.gwt.shared.property.CmsClientProperty; 039import org.opencms.gwt.shared.property.CmsClientTemplateBean; 040import org.opencms.gwt.shared.property.CmsPropertyModification; 041import org.opencms.util.CmsUUID; 042 043import java.util.ArrayList; 044import java.util.Collections; 045import java.util.List; 046import java.util.Map; 047 048/** 049 * The mode handler for the 'edit entry' mode of the sitemap entry editor.<p> 050 * 051 * @since 8.0.0 052 */ 053public class CmsEditEntryHandler extends A_CmsSitemapEntryEditorHandler { 054 055 private String m_defaultFilePath; 056 057 /** True if the sitemap editor is in simple mode. */ 058 private boolean m_isSimpleMode; 059 060 /** The page info bean. */ 061 private CmsListInfoBean m_pageInfo; 062 063 /** 064 * Creates a new instance of this class.<p> 065 * 066 * @param controller the sitemap controller for this mode 067 * @param entry the sitemap entry for this mode 068 * @param isSimpleMode true if the sitemap entry editor is in simple mode 069 */ 070 public CmsEditEntryHandler(CmsSitemapController controller, CmsClientSitemapEntry entry, boolean isSimpleMode) { 071 072 super(controller, entry); 073 m_isSimpleMode = isSimpleMode; 074 075 } 076 077 /** 078 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getAllPropertyNames() 079 */ 080 public List<String> getAllPropertyNames() { 081 082 return CmsSitemapView.getInstance().getController().getData().getAllPropertyNames(); 083 } 084 085 /** 086 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFileId() 087 */ 088 public CmsUUID getDefaultFileId() { 089 090 return m_entry.getDefaultFileId(); 091 } 092 093 /** 094 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFilePath() 095 */ 096 @Override 097 public String getDefaultFilePath() { 098 099 return m_defaultFilePath; 100 } 101 102 /** 103 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDefaultFileProperties() 104 */ 105 public Map<String, CmsClientProperty> getDefaultFileProperties() { 106 107 return m_entry.getDefaultFileProperties(); 108 } 109 110 /** 111 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getDialogTitle() 112 */ 113 public String getDialogTitle() { 114 115 return Messages.get().key(Messages.GUI_EDIT_ENTRY_TITLE_0); 116 117 } 118 119 /** 120 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getForbiddenUrlNames() 121 */ 122 public List<String> getForbiddenUrlNames() { 123 124 if (m_entry.getSitePath().equals("/")) { 125 return Collections.<String> emptyList(); 126 } 127 128 List<String> result = new ArrayList<String>(); 129 String parentPath = CmsResource.getParentFolder(m_entry.getSitePath()); 130 CmsClientSitemapEntry parent = m_controller.getEntry(parentPath); 131 if (parent == null) { 132 return result; 133 } 134 for (CmsClientSitemapEntry child : parent.getSubEntries()) { 135 if (child != m_entry) { 136 result.add(child.getName()); 137 } 138 } 139 return result; 140 } 141 142 /** 143 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getId() 144 */ 145 public CmsUUID getId() { 146 147 return m_entry.getId(); 148 } 149 150 /** 151 * Gets the property object which would be inherited by a sitemap entry.<p> 152 * 153 * @param name the name of the property 154 * @return the property object which would be inherited 155 */ 156 public CmsClientProperty getInheritedProperty(String name) { 157 158 return CmsSitemapView.getInstance().getController().getInheritedPropertyObject(m_entry, name); 159 } 160 161 /** 162 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getModeClass() 163 */ 164 public String getModeClass() { 165 166 if (CmsSitemapView.getInstance().isNavigationMode()) { 167 return I_CmsSitemapLayoutBundle.INSTANCE.sitemapItemCss().navMode(); 168 } else { 169 return I_CmsSitemapLayoutBundle.INSTANCE.sitemapItemCss().vfsMode(); 170 } 171 } 172 173 /** 174 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getOwnProperties() 175 */ 176 public Map<String, CmsClientProperty> getOwnProperties() { 177 178 return m_entry.getOwnProperties(); 179 } 180 181 /** 182 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPageInfo() 183 */ 184 public CmsListInfoBean getPageInfo() { 185 186 return m_pageInfo; 187 } 188 189 /** 190 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPath() 191 */ 192 public String getPath() { 193 194 return m_entry.getSitePath(); 195 } 196 197 /** 198 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#getPossibleTemplates() 199 */ 200 public Map<String, CmsClientTemplateBean> getPossibleTemplates() { 201 202 return CmsSitemapView.getInstance().getController().getData().getTemplates(); 203 } 204 205 /** 206 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#handleSubmit(java.lang.String, java.lang.String, java.util.List, boolean, org.opencms.gwt.client.property.CmsReloadMode) 207 */ 208 public void handleSubmit( 209 String newUrlName, 210 String vfsPath, 211 List<CmsPropertyModification> propertyChanges, 212 boolean editedName, 213 CmsReloadMode reloadStatus) { 214 215 if (editedName) { 216 m_controller.editAndChangeName(m_entry, newUrlName, propertyChanges, false, reloadStatus); 217 } else { 218 m_controller.edit(m_entry, propertyChanges, reloadStatus); 219 } 220 221 } 222 223 /** 224 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#hasEditableName() 225 */ 226 public boolean hasEditableName() { 227 228 return !getEntry().isRoot(); 229 } 230 231 /** 232 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isFolder() 233 */ 234 public boolean isFolder() { 235 236 return m_entry.isFolderType(); 237 } 238 239 /** 240 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isHiddenProperty(java.lang.String) 241 */ 242 public boolean isHiddenProperty(String key) { 243 244 return CmsSitemapView.getInstance().getController().isHiddenProperty(key); 245 } 246 247 /** 248 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#isSimpleMode() 249 */ 250 public boolean isSimpleMode() { 251 252 return m_isSimpleMode; 253 } 254 255 /** 256 * Sets the default file path 257 * @param defaultFilePath the new default file path 258 */ 259 public void setDefaultFilePath(String defaultFilePath) { 260 261 m_defaultFilePath = defaultFilePath; 262 } 263 264 /** 265 * Sets the page info bean.<p> 266 * 267 * @param pageInfo the page info bean 268 */ 269 public void setPageInfo(CmsListInfoBean pageInfo) { 270 271 m_pageInfo = pageInfo; 272 } 273 274 /** 275 * @see org.opencms.gwt.client.property.I_CmsPropertyEditorHandler#useAdeTemplates() 276 */ 277 public boolean useAdeTemplates() { 278 279 return true; 280 } 281 282 /** 283 * Gets the edited sitemap entry.<p> 284 * 285 * @return the edited sitemap entry 286 */ 287 protected CmsClientSitemapEntry getEntry() { 288 289 return m_entry; 290 } 291 292 /** 293 * Returns the path for the given URL name.<p> 294 * 295 * @param urlName the URL name to create the path for 296 * 297 * @return the new path for the given URL name 298 */ 299 protected String getPath(String urlName) { 300 301 if (urlName.equals("")) { 302 return m_entry.getSitePath(); 303 } 304 return CmsResource.getParentFolder(m_entry.getSitePath()) + urlName + "/"; 305 } 306 307}