1 31 32 package org.opencms.workplace.explorer; 33 34 import org.opencms.file.CmsResource; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.lock.CmsLock; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.CmsLog; 39 import org.opencms.site.CmsSiteManager; 40 import org.opencms.workplace.CmsWorkplaceSettings; 41 import org.opencms.workplace.commons.CmsPropertyAdvanced; 42 43 import java.io.IOException ; 44 import java.util.HashMap ; 45 import java.util.List ; 46 import java.util.Map ; 47 48 import javax.servlet.ServletException ; 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 51 import javax.servlet.jsp.JspException ; 52 import javax.servlet.jsp.PageContext ; 53 54 import org.apache.commons.logging.Log; 55 56 71 public class CmsNewResourceSibling extends CmsNewResourcePointer { 72 73 74 public static final String PARAM_KEEPPROPERTIES = "keepproperties"; 75 76 77 private static final Log LOG = CmsLog.getLog(CmsNewResourceSibling.class); 78 79 private String m_paramKeepProperties; 80 81 86 public CmsNewResourceSibling(CmsJspActionElement jsp) { 87 88 super(jsp); 89 } 90 91 98 public CmsNewResourceSibling(PageContext context, HttpServletRequest req, HttpServletResponse res) { 99 100 this(new CmsJspActionElement(context, req, res)); 101 } 102 103 108 public void actionCreateResource() throws JspException { 109 110 try { 111 String fullResourceName = computeFullResourceName(); 113 String newResourceParam = fullResourceName; 114 String targetName = getParamLinkTarget(); 116 if (targetName == null) { 117 targetName = ""; 118 } 119 120 boolean restoreSiteRoot = false; 122 try { 123 if (CmsSiteManager.getSiteRoot(targetName) != null) { 124 String siteRootFolder = getCms().getRequestContext().getSiteRoot(); 126 if (siteRootFolder.endsWith("/")) { 127 siteRootFolder = siteRootFolder.substring(0, siteRootFolder.length() - 1); 128 } 129 fullResourceName = siteRootFolder + fullResourceName; 130 getCms().getRequestContext().saveSiteRoot(); 131 getCms().getRequestContext().setSiteRoot("/"); 132 restoreSiteRoot = true; 133 } 134 135 boolean isFolder = false; 137 CmsResource targetRes = getCms().readResource(targetName); 138 isFolder = targetRes.isFolder(); 139 140 if (isFolder) { 141 if (targetName.endsWith("/")) { 143 targetName = targetName.substring(0, targetName.length() - 1); 144 } 145 getCms().copyResource(targetName, fullResourceName, CmsResource.COPY_AS_SIBLING); 147 } else { 148 List targetProperties = null; 150 boolean keepProperties = Boolean.valueOf(getParamKeepProperties()).booleanValue(); 151 if (keepProperties) { 152 try { 154 targetProperties = getCms().readPropertyObjects(targetName, false); 155 } catch (Exception e) { 156 LOG.error(e); 157 } 158 } 159 getCms().createSibling(targetName, fullResourceName, targetProperties); 160 } 161 162 } finally { 163 if (restoreSiteRoot) { 165 getCms().getRequestContext().restoreSiteRoot(); 166 } 167 } 168 169 setParamResource(newResourceParam); 171 setResourceCreated(true); 172 } catch (Throwable e) { 173 setParamMessage(Messages.get().getBundle(getLocale()).key(Messages.ERR_CREATE_LINK_0)); 175 includeErrorpage(this, e); 176 } 177 178 } 179 180 191 public void actionEditProperties() throws IOException , JspException , ServletException { 192 193 boolean editProps = Boolean.valueOf(getParamNewResourceEditProps()).booleanValue(); 194 String newRes = getParamResource(); 196 try { 198 CmsLock lock = getCms().getLock(newRes); 199 if (lock.getType() != CmsLock.TYPE_EXCLUSIVE) { 201 editProps = false; 202 } 203 } catch (CmsException e) { 204 throw new JspException (e); 205 } 206 if (editProps) { 207 Map params = new HashMap (); 209 params.put(PARAM_RESOURCE, getParamResource()); 210 params.put(CmsPropertyAdvanced.PARAM_DIALOGMODE, CmsPropertyAdvanced.MODE_WIZARD); 211 sendForward(CmsPropertyAdvanced.URI_PROPERTY_DIALOG_HANDLER, params); 212 } else { 213 actionCloseDialog(); 215 } 216 } 217 218 223 public String getCurrentPath() { 224 225 String path = getSettings().getExplorerResource(); 226 if (path == null) { 227 path = "/"; 228 } 229 return CmsResource.getFolderPath(path); 230 } 231 232 237 public String getParamKeepProperties() { 238 239 return m_paramKeepProperties; 240 } 241 242 247 public void setParamKeepProperties(String keepProperties) { 248 249 m_paramKeepProperties = keepProperties; 250 } 251 252 255 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 256 257 fillParamValues(request); 259 setParamDialogtype(DIALOG_TYPE); 261 if (DIALOG_OK.equals(getParamAction())) { 263 setAction(ACTION_OK); 264 } else if (DIALOG_CANCEL.equals(getParamAction())) { 265 setAction(ACTION_CANCEL); 266 } else { 267 setAction(ACTION_DEFAULT); 268 setParamTitle(key(Messages.GUI_NEWRESOURCE_SIBLING_0)); 270 } 271 } 272 273 } | Popular Tags |