1 28 29 package com.opencms.defaults.master; 30 31 import org.opencms.db.CmsDbUtil; 32 import org.opencms.file.CmsObject; 33 import org.opencms.file.CmsUser; 34 import org.opencms.i18n.CmsEncoder; 35 import org.opencms.main.CmsException; 36 import org.opencms.util.CmsUUID; 37 import org.opencms.workplace.CmsWorkplace; 38 39 import com.opencms.core.I_CmsSession; 40 import com.opencms.defaults.A_CmsBackoffice; 41 import com.opencms.legacy.CmsXmlTemplateLoader; 42 import com.opencms.template.A_CmsXmlContent; 43 import com.opencms.workplace.CmsXmlLanguageFile; 44 import com.opencms.workplace.CmsXmlWpTemplateFile; 45 46 import java.util.Hashtable ; 47 import java.util.List ; 48 49 52 public class CmsChannelBackoffice extends A_CmsBackoffice{ 53 54 57 private CmsChannelContent m_channel; 58 59 62 private String m_channelId = "0"; 63 64 67 private CmsUUID m_folderId; 68 69 public Class getContentDefinitionClass() { 70 return CmsChannelContent.class; 71 } 72 73 public String getCreateUrl(CmsObject cms, String tagcontent, 74 A_CmsXmlContent doc, Object userObject) throws Exception { 75 return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/EditBackoffice.html"; 76 } 77 78 public String getBackofficeUrl(CmsObject cms, String tagcontent, 79 A_CmsXmlContent doc, Object userObject) throws Exception { 80 return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/Backoffice.html"; 81 } 82 83 public String getEditUrl(CmsObject cms, String tagcontent, 84 A_CmsXmlContent doc, Object userObject) throws Exception { 85 return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/EditBackoffice.html"; 86 } 87 88 public String getPublishUrl(CmsObject cms, String tagcontent, 89 A_CmsXmlContent doc, Object userObject) throws Exception { 90 return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/Backoffice.html"; 91 } 92 93 public String getSetupUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 95 return ""; 96 } 97 98 112 public byte[] getContentEdit(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, 113 Hashtable parameters, String templateSelector) throws CmsException { 114 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 116 String moduleName = ""; 118 moduleName = getClass().toString(); moduleName = moduleName.substring(5); moduleName = moduleName.trim(); 121 moduleName = moduleName.replace('.', '_'); I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 124 String error=""; 126 String action = (String ) parameters.get("action"); 129 if (action == null){ 130 action=""; 131 } else if (action.equals("exit")){ 132 clearSession(session); 133 templateSelector= "done"; 134 return startProcessing(cms, template, "", parameters, templateSelector); 135 } 136 137 139 String id = (String ) parameters.get("id"); 141 String channelId = (String ) parameters.get("channelId"); 142 String resourceId = (String ) parameters.get("resourceid"); 143 String nullUUIDStr = CmsUUID.getNullUUID().toString(); 144 145 String parentName = (String ) parameters.get("parentName"); 147 if(parentName == null || parentName.equals("")){ 148 parentName="/"; 149 } 150 151 String channelname = (String ) parameters.get("channelName"); 153 if(channelname == null){ 154 channelname = ""; 155 } 156 157 if(!action.equals("") && channelname.trim().equals("")){ 159 error = lang.getLanguageValue(moduleName+".error.message2"); 160 } 161 162 String title = (String ) parameters.get("title"); 164 165 String owner=(String ) parameters.get("owner"); 166 owner=(owner!=null?owner.trim():""); 167 String group=(String ) parameters.get("groupId"); 168 group=(group!=null?group.trim():""); 169 170 int accessFlags = this.getAccessValue(parameters); 171 172 if (id == null || id.equals("")){ 174 id = "new"; 175 } 176 if(channelId==null || channelId.trim().equals("")){ 177 channelId="-1"; 178 } 179 if(resourceId==null || resourceId.trim().equals("")){ 180 resourceId=nullUUIDStr; 181 } 182 if(id.equals("new")){ 183 if(resourceId.equals(nullUUIDStr)){ 184 m_channel=null; 185 }else{ 186 id=resourceId; 187 } 188 } 189 if (action.equals("") && !id.equals("new")) { 192 m_channel = new CmsChannelContent(cms,new CmsUUID(id)); 199 parentName=m_channel.getParentName(); 200 m_channelId=m_channel.getChannelId(); 201 m_folderId = m_channel.getId(); 202 channelname=m_channel.getChannelName(); 203 title=m_channel.getTitle(); 204 owner=m_channel.getOwner().toString(); 205 group=m_channel.getGroupId().toString(); 206 accessFlags=m_channel.getAccessFlags(); 207 }else if(m_channel==null){ 208 m_channel = new CmsChannelContent(cms); 210 m_channelId = CmsDbUtil.UNKNOWN_ID+""; 211 m_folderId = CmsUUID.getNullUUID(); 212 } 213 session.putValue("parentName",parentName); 215 session.putValue("id",m_folderId.toString()); 216 if(error.equals("") && !action.equals("")) { 218 m_channel.setChannelId(m_channelId); 219 m_channel.setParentName(parentName); 220 m_channel.setChannelName(channelname); 221 m_channel.setTitle(title); 222 m_channel.setGroup(new CmsUUID(group)); 223 m_channel.setOwner(new CmsUUID(owner)); 224 m_channel.setAccessFlags(accessFlags); 225 } 226 String defaultUser=cms.getRequestContext().currentUser().getName(); 229 String groupOptions=""; 233 template.setData("groups",groupOptions); 248 String userOptions=""; 250 List cmsUsers=cms.getUsers(); 251 for (int i=0;i<cmsUsers.size();i++) { 252 String userName=((CmsUser)cmsUsers.get(i)).getName(); 253 CmsUUID userId=((CmsUser)cmsUsers.get(i)).getId(); 254 template.setData("name",userName); 255 template.setData("value",userId.toString()); 256 if (!owner.equals("") && (cms.readUser(new CmsUUID(owner)).getName()).equals(userName)) { 257 template.setData("check","selected"); 258 }else if(m_channelId.equals(CmsDbUtil.UNKNOWN_ID+"") && userName.equals(defaultUser)){ 259 template.setData("check","selected"); 260 }else{ 261 template.setData("check",""); 262 } 263 userOptions=userOptions+template.getProcessedDataValue("selectoption",this); 264 } 265 template.setData("users",userOptions); 266 this.setAccessValue(template, m_channel.getAccessFlags()); 268 template.setData("channelId", ""+m_channel.getChannelId()); 270 template.setData("resourceid", m_channel.getId().toString()); 271 template.setData("channelName", m_channel.getChannelName()); 272 template.setData("title", CmsEncoder.escape(m_channel.getTitle(), 273 cms.getRequestContext().getEncoding())); 274 template.setData("parentName", m_channel.getParentName()); 275 template.setData("error", error); 276 277 if(action.equals("saveexit") && error.equals("")){ 279 try{ 280 m_channel.setChannelId(channelId); 281 m_channel.write(cms); 283 clearSession(session); 285 templateSelector = "done"; 286 return startProcessing(cms, template, "", parameters, templateSelector); 287 }catch (CmsException exc){ 288 template.setData("channelId", channelId); 289 template.setData("resourceid", m_channel.getId().toString()); 290 template.setData("channelName", channelname); 291 template.setData("title", CmsEncoder.escape(title, 292 cms.getRequestContext().getEncoding())); 293 template.setData("parentName", parentName); 294 error = lang.getLanguageValue(moduleName+".error.message3")+" "+exc.getMessage(); 295 template.setData("error", error); 296 exc.printStackTrace(System.err); 298 }catch (Exception e){ 299 template.setData("channelId", channelId); 300 template.setData("resourceid", m_channel.getId().toString()); 301 template.setData("channelName", channelname); 302 template.setData("title", CmsEncoder.escape(title, 303 cms.getRequestContext().getEncoding())); 304 template.setData("parentName", parentName); 305 error = lang.getLanguageValue(moduleName+".error.message3")+" "+e.getMessage(); 306 template.setData("error", error); 307 e.printStackTrace(System.err); 309 } 310 } 311 312 if(action.equals("save") && error.equals("")){ 314 try{ 315 m_channel.setChannelId(channelId); 316 m_channel.write(cms); 318 m_channelId=m_channel.getChannelId(); 319 template.setData("channelId", m_channelId); 320 template.setData("resourceid", m_channel.getId().toString()); 321 template.setData("newChannelId", m_channelId); 323 }catch (CmsException exc){ 324 template.setData("channelId", channelId); 325 template.setData("resourceid", m_channel.getId().toString()); 326 template.setData("channelName", channelname); 327 template.setData("title", CmsEncoder.escape(title, 328 cms.getRequestContext().getEncoding())); 329 template.setData("parentName", parentName); 330 error = lang.getLanguageValue(moduleName+".error.message3")+" "+exc.getMessage(); 331 template.setData("error", error); 332 exc.printStackTrace(System.err); 334 }catch (Exception e){ 335 e.printStackTrace(System.err); 336 template.setData("channelId", channelId); 337 template.setData("resourceid", m_channel.getId().toString()); 338 template.setData("channelName", channelname); 339 template.setData("title", CmsEncoder.escape(title, 340 cms.getRequestContext().getEncoding())); 341 template.setData("parentName", parentName); 342 error = lang.getLanguageValue(moduleName+".error.message3")+" "+e.getMessage(); 343 template.setData("error", error); 344 } 345 } 346 return startProcessing(cms, template, elementName, parameters, templateSelector); 348 } 349 350 353 private int getAccessValue(Hashtable parameters){ 354 int accessFlag = 0; 355 for(int i=0; i<=8; i++){ 356 String permissionsAtI=(String )parameters.get("permissions"+i); 357 if(permissionsAtI != null) { 358 if(permissionsAtI.equals("on")) { 359 accessFlag += new Integer (C_ACCESS_FLAGS[i]).intValue(); 360 } 361 } 362 } 363 if(accessFlag == 0){ 364 accessFlag = C_DEFAULT_PERMISSIONS; 365 } 366 return accessFlag; 367 } 368 369 372 private void setAccessValue(CmsXmlWpTemplateFile template, int accessFlags){ 373 for(int i=0; i<=8; i++) { 375 int accessValueAtI = new Integer (C_ACCESS_FLAGS[i]).intValue(); 376 if ((accessFlags & accessValueAtI) > 0) { 377 template.setData("permissions_check_"+i,"checked"); 378 } else { 379 template.setData("permissions_check_"+i,""); 380 } 381 } 382 } 383 386 private void clearSession(I_CmsSession session){ 387 session.removeValue("parentName"); 388 session.removeValue("id"); 389 } 390 393 public boolean isExtendedList(){ 394 return true; 395 } 396 }
| Popular Tags
|