1 31 32 package org.opencms.workplace; 33 34 import org.opencms.file.CmsPropertyDefinition; 35 import org.opencms.file.CmsResource; 36 import org.opencms.file.CmsResourceFilter; 37 import org.opencms.i18n.CmsMessageContainer; 38 import org.opencms.i18n.I_CmsMessageBundle; 39 import org.opencms.jsp.CmsJspActionElement; 40 import org.opencms.main.CmsException; 41 import org.opencms.main.CmsLog; 42 import org.opencms.main.CmsMultiException; 43 import org.opencms.security.CmsPermissionSet; 44 import org.opencms.util.CmsStringUtil; 45 46 import java.util.ArrayList ; 47 import java.util.Collections ; 48 import java.util.Iterator ; 49 import java.util.List ; 50 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 import javax.servlet.jsp.PageContext ; 54 55 import org.apache.commons.logging.Log; 56 57 72 public abstract class CmsMultiDialog extends CmsDialog { 73 74 75 public static final String DELIMITER_RESOURCES = "|"; 76 77 78 public static final String PARAM_RESOURCELIST = "resourcelist"; 79 80 81 private CmsMultiException m_multiOperationException; 82 83 84 private String m_paramResourcelist; 85 86 87 private List m_resourceList; 88 89 90 private static final Log LOG = CmsLog.getLog(CmsMultiDialog.class); 91 92 97 public CmsMultiDialog(CmsJspActionElement jsp) { 98 99 super(jsp); 100 m_multiOperationException = new CmsMultiException(); 101 } 102 103 110 public CmsMultiDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 111 112 this(new CmsJspActionElement(context, req, res)); 113 } 114 115 123 public void addMultiOperationException(CmsException exc) { 124 125 m_multiOperationException.addException(exc); 126 } 127 128 133 public String buildResourceList() { 134 135 StringBuffer result = new StringBuffer (1024); 136 result.append("<table border=\"0\">\n"); 137 Iterator i = getResourceList().iterator(); 138 while (i.hasNext()) { 139 String resName = (String )i.next(); 140 result.append("\t<tr>\n"); 141 result.append("\t\t<td style=\"vertical-align:top;\">./"); 142 result.append(CmsResource.getName(resName)); 143 result.append(" </td>\n\t\t<td style=\"vertical-align:top;\">"); 144 String title = null; 145 try { 146 title = getCms().readPropertyObject(resName, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue(null); 148 } catch (CmsException e) { 149 } 151 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(title)) { 152 result.append(title); 154 } 155 result.append("</td>\n\t</tr>\n"); 156 } 157 result.append("</table>"); 158 return result.toString(); 159 } 160 161 168 public void checkMultiOperationException(I_CmsMessageBundle messages, String key) throws CmsException { 169 170 if (m_multiOperationException.hasExceptions()) { 171 m_multiOperationException.setMessage(new CmsMessageContainer( 172 messages, 173 key, 174 new Object [] {m_multiOperationException})); 175 throw m_multiOperationException; 176 } 177 } 178 179 186 public String getParamResourcelist() { 187 188 if (CmsStringUtil.isNotEmpty(m_paramResourcelist) && !"null".equals(m_paramResourcelist)) { 189 return m_paramResourcelist; 190 } else { 191 return null; 192 } 193 } 194 195 203 public List getResourceList() { 204 205 if (m_resourceList == null) { 206 if (getParamResourcelist() != null) { 208 m_resourceList = CmsStringUtil.splitAsList(getParamResourcelist(), DELIMITER_RESOURCES, true); 210 Collections.sort(m_resourceList); 211 } else { 212 m_resourceList = new ArrayList (1); 214 m_resourceList.add(getParamResource()); 215 } 216 } 217 return m_resourceList; 218 } 219 220 225 public boolean isMultiOperation() { 226 227 return (getResourceList().size() > 1); 228 } 229 230 236 public void setDialogTitle(String singleKey, String multiKey) { 237 238 if (isMultiOperation()) { 239 String resCount = String.valueOf(getResourceList().size()); 241 String currentFolder = CmsResource.getFolderPath(getSettings().getExplorerResource()); 242 currentFolder = CmsStringUtil.formatResourceName(currentFolder, 40); 243 Object [] params = new Object [] {resCount, currentFolder}; 244 setParamTitle(key(multiKey, params)); 245 } else { 246 String resourceName = CmsStringUtil.formatResourceName(getParamResource(), 50); 248 setParamTitle(key(singleKey, new Object [] {resourceName})); 249 } 250 } 251 252 257 public void setParamResourcelist(String paramResourcelist) { 258 259 m_paramResourcelist = paramResourcelist; 260 } 261 262 273 protected boolean checkResourcePermissions(CmsPermissionSet required, boolean neededForFolder) { 274 275 if (isMultiOperation()) { 276 return true; 278 } else { 279 return super.checkResourcePermissions(required, neededForFolder); 281 } 282 } 283 284 289 protected boolean isOperationOnFolder() { 290 291 Iterator i = getResourceList().iterator(); 292 while (i.hasNext()) { 293 String resName = (String )i.next(); 294 try { 295 CmsResource curRes = getCms().readResource(resName, CmsResourceFilter.ALL); 296 if (curRes.isFolder()) { 297 return true; 299 } 300 } catch (CmsException e) { 301 if (LOG.isInfoEnabled()) { 303 LOG.info(e.getLocalizedMessage()); 304 } 305 } 306 } 307 return false; 308 } 309 310 316 protected abstract boolean performDialogOperation() throws CmsException; 317 318 }
| Popular Tags
|