1 28 29 package com.opencms.defaults; 30 31 import org.opencms.db.CmsUserSettings; 32 import org.opencms.file.CmsGroup; 33 import org.opencms.file.CmsObject; 34 import org.opencms.file.CmsProject; 35 import org.opencms.file.CmsResource; 36 import org.opencms.file.CmsUser; 37 import org.opencms.i18n.CmsEncoder; 38 import org.opencms.main.CmsException; 39 import org.opencms.main.CmsLog; 40 import org.opencms.util.CmsDateUtil; 41 import org.opencms.util.CmsUUID; 42 43 import com.opencms.core.I_CmsSession; 44 import com.opencms.defaults.master.CmsPlausibilizationException; 45 import com.opencms.legacy.CmsLegacyException; 46 import com.opencms.legacy.CmsXmlTemplateLoader; 47 import com.opencms.template.A_CmsXmlContent; 48 import com.opencms.template.CmsXmlTemplateFile; 49 import com.opencms.workplace.CmsWorkplaceDefault; 50 import com.opencms.workplace.CmsXmlLanguageFile; 51 import com.opencms.workplace.CmsXmlWpTemplateFile; 52 53 import java.lang.reflect.Constructor ; 54 import java.lang.reflect.InvocationTargetException ; 55 import java.lang.reflect.Method ; 56 import java.util.Enumeration ; 57 import java.util.Hashtable ; 58 import java.util.List ; 59 import java.util.Vector ; 60 61 83 public abstract class A_CmsBackoffice extends CmsWorkplaceDefault { 84 85 86 public static int C_NOT_LOCKED = -1; 87 88 89 public static int C_NO_ACCESS = -2; 90 91 private static String C_DEFAULT_SELECTOR = "(default)"; 92 private static String C_DONE_SELECTOR = "done"; 93 94 95 private static final String C_STYLE_UNCHANGED = "dateingeandert"; 96 97 98 private static final String C_STYLE_NOTINPROJECT = "dateintprojekt"; 99 100 101 private static final String C_STYLE_NEW = "dateineu"; 102 103 104 private static final String C_STYLE_DELETED = "dateigeloescht"; 105 106 107 private static final String C_STYLE_CHANGED = "dateigeaendert"; 108 109 110 protected static final int C_DEFAULT_PERMISSIONS = 383; 111 112 113 protected static final String [] C_ACCESS_FLAGS = {"1", "2", "4", "8", "16", "32", "64", "128", "256"}; 114 115 125 public abstract String getBackofficeUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception ; 126 136 public abstract String getCreateUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception ; 137 138 148 public abstract String getEditUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception ; 149 150 160 public String getDeleteUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 161 162 return getBackofficeUrl(cms, tagcontent, doc, userObject); 163 } 164 165 175 public String getUndeleteUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 176 177 return getBackofficeUrl(cms, tagcontent, doc, userObject); 178 } 179 180 190 public String getPublishUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 191 192 return getBackofficeUrl(cms, tagcontent, doc, userObject); 193 } 194 195 205 public String getHistoryUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 206 207 return getBackofficeUrl(cms, tagcontent, doc, userObject); 208 } 209 210 220 public String getUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 221 return ""; 222 } 223 224 234 public String getSetupUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 235 return ""; 236 } 237 238 248 public String getPreviewUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws Exception { 249 return ""; 250 } 251 252 268 269 public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 270 271 byte[] returnProcess = null; 273 274 A_CmsContentDefinition cd = null; 276 277 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 279 session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 280 CmsXmlWpTemplateFile template = new CmsXmlWpTemplateFile(cms, templateFile); 282 String selectBox = (String )parameters.get("selectbox"); 284 String filterParam = (String )parameters.get("filterparameter"); 285 String id = (String )parameters.get("id"); 286 String idlock = (String )parameters.get("idlock"); 287 String iddelete = (String )parameters.get("iddelete"); 288 String idedit = (String )parameters.get("idedit"); 289 String action = (String )parameters.get("action"); 290 String parentId = (String )parameters.get("parentId"); 291 String ok = (String )parameters.get("ok"); 292 String setaction = (String )parameters.get("setaction"); 293 String idundelete = (String )parameters.get("idundelete"); 294 String idpublish = (String )parameters.get("idpublish"); 295 String idhistory = (String )parameters.get("idhistory"); 296 String idpermissions = (String )parameters.get("idpermissions"); 297 String idcopy = (String )parameters.get("idcopy"); 298 320 321 String hasFilterParam = (String )session.getValue("filterparameter"); 322 template.setData("filternumber", "0"); 323 324 if ((hasFilterParam == null) && (filterParam == null) && (setaction == null)) { 326 if (selectBox != null) { 327 session.putValue("filter", selectBox); 328 template.setData("filternumber", selectBox); 329 } 330 } else { 331 template.setData("filternumber", (String )session.getValue("filter")); 332 } 333 334 if (idlock != null) { 336 id = idlock; 337 session.putValue("idlock", idlock); 338 session.removeValue("idedit"); 339 session.removeValue("idnew"); 340 session.removeValue("iddelete"); 341 session.removeValue("idundelete"); 342 session.removeValue("idpublish"); 343 session.removeValue("idhistory"); 344 session.removeValue("idpermissions"); 345 session.removeValue("idcopy"); 346 } 347 if (idedit != null) { 348 id = idedit; 349 session.putValue("idedit", idedit); 350 session.removeValue("idlock"); 351 session.removeValue("idnew"); 352 session.removeValue("iddelete"); 353 session.removeValue("idundelete"); 354 session.removeValue("idpublish"); 355 session.removeValue("idhistory"); 356 session.removeValue("idpermissions"); 357 session.removeValue("idcopy"); 358 } 359 if (iddelete != null) { 360 id = iddelete; 361 session.putValue("iddelete", iddelete); 362 session.removeValue("idedit"); 363 session.removeValue("idnew"); 364 session.removeValue("idlock"); 365 session.removeValue("idundelete"); 366 session.removeValue("idpublish"); 367 session.removeValue("idhistory"); 368 session.removeValue("idpermissions"); 369 session.removeValue("idcopy"); 370 } 371 if (idundelete != null) { 372 id = idundelete; 373 session.putValue("idundelete", idundelete); 374 session.removeValue("idedit"); 375 session.removeValue("idnew"); 376 session.removeValue("idlock"); 377 session.removeValue("iddelete"); 378 session.removeValue("idpublish"); 379 session.removeValue("idhistory"); 380 session.removeValue("idpermissions"); 381 session.removeValue("idcopy"); 382 } 383 if (idpublish != null) { 384 id = idpublish; 385 session.putValue("idpublish", idpublish); 386 session.removeValue("idedit"); 387 session.removeValue("idnew"); 388 session.removeValue("idlock"); 389 session.removeValue("iddelete"); 390 session.removeValue("idundelete"); 391 session.removeValue("idhistory"); 392 session.removeValue("idpermissions"); 393 session.removeValue("idcopy"); 394 } 395 396 if (idhistory != null) { 397 id = idhistory; 398 session.putValue("idhistory", idhistory); 399 session.removeValue("idedit"); 400 session.removeValue("idnew"); 401 session.removeValue("idlock"); 402 session.removeValue("iddelete"); 403 session.removeValue("idundelete"); 404 session.removeValue("idpublish"); 405 session.removeValue("idpermissions"); 406 session.removeValue("idcopy"); 407 } 408 409 if (idpermissions != null) { 410 id = idpermissions; 411 session.putValue("idpermissions", idpermissions); 412 session.removeValue("idedit"); 413 session.removeValue("idnew"); 414 session.removeValue("idlock"); 415 session.removeValue("iddelete"); 416 session.removeValue("idundelete"); 417 session.removeValue("idpublish"); 418 session.removeValue("idhistory"); 419 session.removeValue("idcopy"); 420 } 421 422 if (idcopy != null) { 423 id = idcopy; 424 session.putValue("idcopy", idcopy); 425 session.removeValue("idedit"); 426 session.removeValue("idnew"); 427 session.removeValue("idlock"); 428 session.removeValue("iddelete"); 429 session.removeValue("idundelete"); 430 session.removeValue("idpublish"); 431 session.removeValue("idhistory"); 432 session.removeValue("idpermissions"); 433 } 434 435 if ((id != null) && (id.equals("new"))) { 436 session.putValue("idnew", id); 437 session.removeValue("idedit"); 438 session.removeValue("iddelete"); 439 session.removeValue("idlock"); 440 session.removeValue("idundelete"); 441 session.removeValue("idpublish"); 442 session.removeValue("idhistory"); 443 session.removeValue("idpermissions"); 444 session.removeValue("idcopy"); 445 } 446 String idsave = (String )session.getValue("idsave"); 448 if (ok == null) { 449 450 idsave = null; 451 } 452 453 if (parentId != null) { 454 session.putValue("parentId", parentId); 455 } 456 457 459 if ((id != null) && (id.equals("new")) || ((idsave != null) && (idsave.equals("new")))) { 462 if (idsave != null) { 463 parameters.put("id", idsave); 464 } 465 if (id != null) { 466 parameters.put("id", id); 467 session.putValue("idsave", id); 468 } 469 return getContentNewInternal(cms, id, cd, session, template, elementName, parameters, templateSelector); 470 471 } 473 if ((id == null) && (idsave == null) && (action == null) && (idlock == null) && (iddelete == null) && (idedit == null) && (idundelete == null) && (idpublish == null) && (idhistory == null) && (idpermissions == null) && (idcopy == null)) { 475 returnProcess = getContentHead(cms, template, elementName, parameters, templateSelector); 477 return returnProcess; 479 } else { 480 if (action == null) { 482 action = ""; 483 } 484 if (action.equalsIgnoreCase("list")) { 485 session.removeValue("idsave"); 488 if (isExtendedList()) { 489 returnProcess = getContentExtendedList(cms, template, elementName, parameters, templateSelector); 490 } else { 491 returnProcess = getContentList(cms, template, elementName, parameters, templateSelector); 492 } 493 return returnProcess; 495 } else { 496 498 String ideditsave = (String )session.getValue("idedit"); 500 if ((idedit != null) || (ideditsave != null)) { 502 if (idsave != null) { 503 parameters.put("id", idsave); 504 } 505 if (id != null) { 506 parameters.put("id", id); 507 session.putValue("idsave", id); 508 } 509 return getContentEditInternal(cms, id, cd, session, template, elementName, parameters, templateSelector); 510 511 513 } else { 514 if (idsave != null) { 516 parameters.put("id", idsave); 517 session.removeValue("idsave"); 518 } else { 519 parameters.put("id", id); 520 session.putValue("idsave", id); 521 } 522 if (idundelete != null) { 524 returnProcess = getContentUndelete(cms, template, elementName, parameters, templateSelector); 525 return returnProcess; 526 } 527 String idpublishsave = (String )session.getValue("idpublish"); 530 if (idpublish != null || idpublishsave != null) { 531 returnProcess = getContentDirectPublish(cms, template, elementName, parameters, templateSelector); 532 return returnProcess; 533 } 534 String idhistorysave = (String )session.getValue("idhistory"); 537 if (idhistory != null || idhistorysave != null) { 538 returnProcess = getContentHistory(cms, template, elementName, parameters, templateSelector); 539 return returnProcess; 540 } 541 542 String idpermissionssave = (String )session.getValue("idpermissions"); 545 if (idpermissions != null || idpermissionssave != null) { 546 returnProcess = getContentPermissions(cms, template, elementName, parameters, templateSelector); 547 return returnProcess; 548 } 549 550 String idcopysave = (String )session.getValue("idcopy"); 553 if (idcopy != null || idcopysave != null) { 554 returnProcess = getContentCopy(cms, template, elementName, parameters, templateSelector); 555 return returnProcess; 556 } 557 558 String iddeletesave = (String )session.getValue("iddelete"); 560 if (((iddelete != null) || (iddeletesave != null)) && (idlock == null)) { 562 returnProcess = getContentDelete(cms, template, elementName, parameters, templateSelector); 563 return returnProcess; 564 } else { 565 returnProcess = getContentLock(cms, template, elementName, parameters, templateSelector); 567 return returnProcess; 569 } 570 } 571 } 572 } 573 } 574 575 580 public abstract Class getContentDefinitionClass(); 581 582 590 protected Object getContentDefinition(CmsObject cms, Class contentClass, CmsUUID contentId) { 591 Object o = null; 592 try { 593 Constructor c = contentClass.getConstructor(new Class [] {CmsObject.class, CmsUUID.class}); 594 o = c.newInstance(new Object [] {cms, contentId}); 595 } catch (InvocationTargetException ite) { 596 if (CmsLog.getLog(this).isWarnEnabled()) { 597 CmsLog.getLog(this).warn("Invocation target exception", ite); 598 } 599 } catch (NoSuchMethodException nsm) { 600 if (CmsLog.getLog(this).isWarnEnabled()) { 601 CmsLog.getLog(this).warn("Requested method was not found", nsm); 602 } 603 } catch (InstantiationException ie) { 604 if (CmsLog.getLog(this).isWarnEnabled()) { 605 CmsLog.getLog(this).warn("The reflected class is abstract", ie); 606 } 607 } catch (Exception e) { 608 if (CmsLog.getLog(this).isWarnEnabled()) { 609 CmsLog.getLog(this).warn("Other exception", e); 610 } 611 } 612 return o; 613 } 614 615 622 protected Object getContentDefinition(CmsObject cms, Class cdClass) { 623 Object o = null; 624 try { 625 Constructor c = cdClass.getConstructor(new Class [] {CmsObject.class}); 627 o = c.newInstance(new Object [] {cms}); 628 } catch (InvocationTargetException ite) { 629 if (CmsLog.getLog(this).isWarnEnabled()) { 630 CmsLog.getLog(this).warn("Invocation target exception", ite); 631 } 632 } catch (NoSuchMethodException nsm) { 633 if (CmsLog.getLog(this).isWarnEnabled()) { 634 CmsLog.getLog(this).warn("Requested method was not found", nsm); 635 } 636 } catch (InstantiationException ie) { 637 if (CmsLog.getLog(this).isWarnEnabled()) { 638 CmsLog.getLog(this).warn("The reflected class is abstract", ie); 639 } 640 } catch (Exception e) { 641 if (CmsLog.getLog(this).isWarnEnabled()) { 642 CmsLog.getLog(this).warn("Other exception", e); 643 } 644 } 645 return o; 646 } 647 648 656 protected Object getContentDefinition(CmsObject cms, Class cdClass, String id) { 657 Object o = null; 658 try { 659 Constructor c = cdClass.getConstructor(new Class [] {CmsObject.class, String .class}); 660 o = c.newInstance(new Object [] {cms, id}); 661 } catch (InvocationTargetException ite) { 662 if (CmsLog.getLog(this).isWarnEnabled()) { 663 CmsLog.getLog(this).warn("Invocation target exception", ite); 664 } 665 } catch (NoSuchMethodException nsm) { 666 if (CmsLog.getLog(this).isWarnEnabled()) { 667 CmsLog.getLog(this).warn("Requested method was not found", nsm); 668 } 669 } catch (InstantiationException ie) { 670 if (CmsLog.getLog(this).isWarnEnabled()) { 671 CmsLog.getLog(this).warn("The reflected class is abstract", ie); 672 } 673 } catch (Exception e) { 674 if (CmsLog.getLog(this).isWarnEnabled()) { 675 CmsLog.getLog(this).warn("Other exception", e); 676 } 677 } 678 return o; 679 } 680 681 686 public String readSaveUserName(CmsObject cms, CmsUUID userId) { 687 String userName = null; 688 try { 689 userName = cms.readUser(userId).getName(); 690 } catch (Exception e) { 691 userName = "" + userId; 692 } 693 return userName; 694 } 695 696 701 public String readSaveGroupName(CmsObject cms, CmsUUID groupId) { 702 String groupName = null; 703 try { 704 groupName = cms.readGroup(groupId).getName(); 705 } catch (Exception e) { 706 groupName = "" + groupId; 707 } 708 return groupName; 709 } 710 711 726 727 public byte[] getContentDelete(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 728 byte[] processResult = null; 730 731 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 733 Class cdClass = getContentDefinitionClass(); 735 736 String id = (String )parameters.get("id"); 738 if (id == null) { 739 id = ""; 740 } 741 742 String action = (String )parameters.get("action"); 744 745 if (action == null || action.equals("")) { 748 if (id != "") { 749 templateSelector = "delete"; 751 752 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 754 755 template.setData("deletetitle", lang.getLanguageValue("title.delete")); 757 template.setData("deletedialog", lang.getLanguageValue("messagebox.delete")); 758 template.setData("newsentry", id); 759 template.setData("setaction", "default"); 760 } 761 } else { 763 templateSelector = "done"; 765 session.removeValue("iddelete"); 767 CmsUUID contentId = new CmsUUID(id); 769 790 Object o = null; 792 o = getContentDefinition(cms, cdClass, contentId); 793 try { 795 ((A_CmsContentDefinition)o).delete(cms); 796 } catch (Exception e) { 797 templateSelector = "deleteerror"; 798 template.setData("deleteerror", e.getMessage()); 799 } 800 } 801 802 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 804 return processResult; 805 } 806 807 822 public byte[] getContentUndelete(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 823 byte[] processResult = null; 825 826 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 828 Class cdClass = getContentDefinitionClass(); 830 831 String id = (String )parameters.get("id"); 833 if (id == null) { 834 id = ""; 835 } 836 837 templateSelector = "done"; 839 session.removeValue("idundelete"); 841 CmsUUID contentId = new CmsUUID(id); 843 Object o = null; 866 o = getContentDefinition(cms, cdClass, contentId); 867 try { 869 ((I_CmsExtendedContentDefinition)o).undelete(cms); 870 } catch (Exception e) { 871 templateSelector = "undeleteerror"; 872 template.setData("undeleteerror", e.getMessage()); 873 } 874 875 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 877 return processResult; 878 } 879 880 895 public byte[] getContentCopy(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 896 byte[] processResult = null; 898 899 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 901 Class cdClass = getContentDefinitionClass(); 903 904 String id = (String )parameters.get("id"); 906 if (id == null) { 907 id = ""; 908 } 909 String action = (String )parameters.get("action"); 911 912 if (action == null || action.equals("")) { 915 if (id != "") { 916 Object o = getContentDefinition(cms, cdClass, new CmsUUID(id)); 918 String curOwner = readSaveUserName(cms, ((I_CmsExtendedContentDefinition)o).getOwner()); 920 String curGroup = readSaveGroupName(cms, ((I_CmsExtendedContentDefinition)o).getGroupId()); 921 922 templateSelector = "copy"; 924 925 template.setData("username", curOwner); 927 template.setData("groupname", curGroup); 928 template.setData("id", id); 929 template.setData("setaction", "default"); 930 } 931 } else { 933 templateSelector = "done"; 935 session.removeValue("idcopy"); 937 CmsUUID contentId = new CmsUUID(id); 939 Object o = getContentDefinition(cms, cdClass, contentId); 940 941 952 try { 954 ((I_CmsExtendedContentDefinition)o).copy(cms); 955 } catch (Exception e) { 956 templateSelector = "copyerror"; 957 template.setData("copyerror", e.getMessage()); 958 } 959 } 960 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 962 return processResult; 963 } 964 965 980 public byte[] getContentDirectPublish(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 981 byte[] processResult = null; 983 984 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 986 987 if (cms.isAdmin() || cms.isManagerOfProject()) { 988 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 990 Class cdClass = getContentDefinitionClass(); 992 993 String id = (String )parameters.get("id"); 995 if (id == null) { 996 id = ""; 997 } 998 999 String action = (String )parameters.get("action"); 1001 1002 if (action == null || action.equals("")) { 1005 if (id != "") { 1006 templateSelector = "publish"; 1008 1009 template.setData("publishtitle", lang.getLanguageValue("messagebox.title.publishresource")); 1011 template.setData("publishdialog1", lang.getLanguageValue("messagebox.message1.publishresource")); 1012 template.setData("newsentry", id); 1013 template.setData("publishdialog2", lang.getLanguageValue("messagebox.message4.publishresource")); 1014 template.setData("setaction", "default"); 1015 } 1016 } else { 1018 templateSelector = "done"; 1020 session.removeValue("idsave"); 1022 CmsUUID contentId = new CmsUUID(id); 1024 1046 Object o = null; 1048 o = getContentDefinition(cms, cdClass, contentId); 1049 try { 1051 ((I_CmsExtendedContentDefinition)o).publishResource(cms); 1052 } catch (Exception e) { 1053 templateSelector = "publisherror"; 1054 template.setData("publisherror", e.getMessage()); 1055 } 1056 } 1057 } else { 1058 templateSelector = "publisherror"; 1059 template.setData("publisherror", lang.getLanguageValue("error.message.publishresource") + "<br>" + lang.getLanguageValue("error.reason.publishresource")); 1060 } 1061 1062 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 1064 return processResult; 1065 } 1066 1067 1082 public byte[] getContentHistory(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 1083 byte[] processResult = null; 1085 1086 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 1088 Class cdClass = getContentDefinitionClass(); 1090 1091 String id = (String )parameters.get("id"); 1093 if (id == null) { 1094 id = ""; 1095 } 1096 1097 String action = (String )parameters.get("action"); 1099 if (action == null || action.equals("")) { 1102 if (id != "") { 1103 templateSelector = "history"; 1105 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 1107 template.setData("historytitle", lang.getLanguageValue("messagebox.title.history")); 1109 template.setData("id", id); 1111 template.setData("setaction", "detail"); 1112 } else { 1113 templateSelector = "done"; 1115 session.removeValue("idhistory"); 1117 } 1118 } else if (action.equalsIgnoreCase("detail")) { 1120 String versionId = (String )parameters.get("version"); 1121 if (versionId != null && !"".equals(versionId)) { 1122 templateSelector = "historydetail"; 1123 Object o = null; 1125 o = getContentDefinition(cms, cdClass, new CmsUUID(id)); 1126 try { 1128 I_CmsExtendedContentDefinition curVersion = (I_CmsExtendedContentDefinition) ((I_CmsExtendedContentDefinition)o).getVersionFromHistory(cms, Integer.parseInt(versionId)); 1129 String projectName = ""; 1130 String projectDescription = ""; 1131 String userName = ""; 1132 try { 1133 CmsProject theProject = cms.readBackupProject(curVersion.getLockedInProject()); 1134 projectName = theProject.getName(); 1135 projectDescription = theProject.getDescription(); 1136 } catch (CmsException ex) { 1137 projectName = ""; 1138 } 1139 try { 1140 CmsUser theUser = cms.readUser(curVersion.getLastModifiedBy()); 1141 userName = theUser.getName() + " " + theUser.getFirstname() + " " + theUser.getLastname(); 1142 } catch (CmsException ex) { 1143 userName = curVersion.getLastModifiedByName(); 1144 } 1145 template.setData("histproject", projectName); 1146 template.setData("version", versionId); 1147 template.setData("id", id); 1148 template.setData("histid", curVersion.getId().toString()); 1149 template.setData("histtitle", curVersion.getTitle()); 1150 template.setData("histlastmodified", CmsDateUtil.getDateTimeShort(curVersion.getDateLastModified())); 1151 template.setData("histpublished", CmsDateUtil.getDateTimeShort(curVersion.getDateCreated())); 1152 template.setData("histmodifiedby", userName); 1153 template.setData("histdescription", projectDescription); 1154 CmsUUID curUser = cms.getRequestContext().currentUser().getId(); 1155 int curProject = cms.getRequestContext().currentProject().getId(); 1156 if (((A_CmsContentDefinition)o).getLockstate().equals(curUser) && ((I_CmsExtendedContentDefinition)o).getLockedInProject() == curProject) { 1157 template.setData("BUTTONRESTORE", template.getProcessedDataValue("ENABLERESTORE", this)); 1159 template.setData("setaction", "restore"); 1160 } else { 1161 template.setData("BUTTONRESTORE", template.getProcessedDataValue("DISABLERESTORE", this)); 1162 template.setData("setaction", ""); 1163 } 1164 } catch (Exception e) { 1165 if (CmsLog.getLog(this).isWarnEnabled()) { 1166 CmsLog.getLog(this).warn("Backoffice: history method caused an exception", e); 1167 } 1168 templateSelector = "historyerror"; 1169 template.setData("historyerror", e.getMessage()); 1170 session.removeValue("idhistory"); 1172 } 1173 } else { 1174 templateSelector = "history"; 1177 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 1179 template.setData("historytitle", lang.getLanguageValue("messagebox.title.history")); 1181 template.setData("id", id); 1183 template.setData("setaction", "detail"); 1184 } 1185 } else if (action.equalsIgnoreCase("restore")) { 1186 String versionId = (String )parameters.get("version"); 1187 templateSelector = "history"; 1189 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 1191 template.setData("historytitle", lang.getLanguageValue("messagebox.title.history")); 1193 template.setData("id", id); 1195 template.setData("setaction", "detail"); 1196 if (versionId != null && !"".equals(versionId)) { 1197 Object o = null; 1199 o = getContentDefinition(cms, cdClass, new CmsUUID(id)); 1200 try { 1202 ((I_CmsExtendedContentDefinition)o).restore(cms, Integer.parseInt(versionId)); 1203 } catch (Exception e) { 1204 if (CmsLog.getLog(this).isWarnEnabled()) { 1205 CmsLog.getLog(this).warn("Restore method caused an exception", e); 1206 } 1207 templateSelector = "historyerror"; 1208 template.setData("historyerror", e.getMessage()); 1209 session.removeValue("idhistory"); 1211 } 1212 } 1213 } 1214 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 1216 return processResult; 1217 } 1218 1219 1234 1235 public Integer getHistory(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException { 1236 CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 1237 String id = (String )parameters.get("id"); 1238 if (id != null && !"".equals(id)) { 1239 Vector cdHistory = new Vector (); 1240 Class cdClass = getContentDefinitionClass(); 1242 Object o = null; 1244 o = getContentDefinition(cms, cdClass, new CmsUUID(id)); 1245 try { 1247 cdHistory = ((I_CmsExtendedContentDefinition)o).getHistory(cms); 1248 } catch (Exception e) { 1249 if (CmsLog.getLog(this).isErrorEnabled()) { 1250 CmsLog.getLog(this).error("History reading history for class " + cdClass.getName(), e); 1251 } 1252 } 1253 for (int i = 0; i < cdHistory.size(); i++) { 1255 try { 1256 I_CmsExtendedContentDefinition curCd = ((I_CmsExtendedContentDefinition)cdHistory.elementAt(i)); 1257 long updated = curCd.getDateCreated(); 1258 String userName = readSaveUserName(cms, curCd.getLastModifiedBy()); 1259 long lastModified = curCd.getDateLastModified(); 1260 String output = CmsDateUtil.getDateTimeShort(lastModified) + " " + CmsDateUtil.getDateTimeShort(updated) + " " + userName; 1261 names.addElement(output); 1262 values.addElement(curCd.getVersionId() + ""); 1263 } catch (Exception e) { 1264 if (CmsLog.getLog(this).isErrorEnabled()) { 1265 CmsLog.getLog(this).error(e); 1266 } 1267 } 1268 } 1269 } 1270 return new Integer (-1); 1271 } 1272 1273 1288 public byte[] getContentPermissions(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 1289 byte[] processResult = null; 1291 Object o = null; 1292 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 1294 Class cdClass = getContentDefinitionClass(); 1296 1297 String mode = (String )parameters.get("chmode"); 1299 if (mode == null || "".equals(mode)) { 1300 mode = ""; 1301 } 1302 String id = (String )parameters.get("id"); 1304 if (id == null) { 1305 id = ""; 1306 } 1307 String action = (String )parameters.get("action"); 1309 CmsUUID newOwner = CmsUUID.getNullUUID(); 1311 CmsUUID newGroup = CmsUUID.getNullUUID(); 1312 String newOwnerString = (String )parameters.get("owner"); 1313 if (newOwnerString != null && !"".equals(newOwnerString)) { 1314 newOwner = new CmsUUID(newOwnerString); 1315 } 1316 String newGroupString = (String )parameters.get("groupId"); 1317 if (newGroupString != null && !"".equals(newGroupString)) { 1318 newGroup = new CmsUUID(newGroupString); 1319 } 1320 int newAccessFlags = getAccessValue(parameters); 1321 if (action == null || action.equals("")) { 1324 if (id != "" && mode != "") { 1325 o = getContentDefinition(cms, cdClass, new CmsUUID(id)); 1327 templateSelector = mode; 1329 CmsUUID curOwner = ((I_CmsExtendedContentDefinition)o).getOwner(); 1330 CmsUUID curGroup = ((I_CmsExtendedContentDefinition)o).getGroupId(); 1331 int curAccessFlags = ((I_CmsExtendedContentDefinition)o).getAccessFlags(); 1332 this.setOwnerSelectbox(cms, template, curOwner); 1334 this.setGroupSelectbox(cms, template, curGroup); 1335 this.setAccessValue(template, curAccessFlags); 1336 template.setData("id", id); 1337 template.setData("setaction", mode); 1338 } 1339 } else { 1341 templateSelector = "done"; 1343 session.removeValue("idpermissions"); 1345 CmsUUID contentId = new CmsUUID(id); 1347 o = getContentDefinition(cms, cdClass, contentId); 1348 1357 try { 1359 if ("chown".equalsIgnoreCase(action) && !newOwner.isNullUUID()) { 1360 ((I_CmsExtendedContentDefinition)o).chown(cms, newOwner); 1361 } else if ("chgrp".equalsIgnoreCase(action) && !newGroup.isNullUUID()) { 1362 ((I_CmsExtendedContentDefinition)o).chgrp(cms, newGroup); 1363 } else if ("chmod".equalsIgnoreCase(action)) { 1364 ((I_CmsExtendedContentDefinition)o).chmod(cms, newAccessFlags); 1365 } 1366 } catch (Exception e) { 1367 if (CmsLog.getLog(this).isWarnEnabled()) { 1368 CmsLog.getLog(this).warn("Changing permissions method caused an exception", e); 1369 } 1370 templateSelector = "permissionserror"; 1371 template.setData("permissionserror", e.getMessage()); 1372 } 1373 } 1374 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 1376 return processResult; 1377 } 1378 1379 1393 1394 private byte[] getContentHead(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 1395 1396 byte[] processResult = null; 1398 1400 1402 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 1404 String uri = cms.getRequestContext().getUri(); 1405 String sessionSelectBoxValue = uri + "selectBoxValue"; 1406 String selectBoxValue = (String )parameters.get("selectbox"); 1408 if (selectBoxValue == null) { 1409 if ((String )session.getValue(sessionSelectBoxValue) != null) { 1411 selectBoxValue = (String )session.getValue(sessionSelectBoxValue); 1413 } else { 1414 selectBoxValue = "0"; 1416 } 1417 } 1418 boolean filterChanged = true; 1419 if (selectBoxValue.equals(session.getValue(sessionSelectBoxValue))) { 1420 filterChanged = false; 1421 } else { 1422 filterChanged = true; 1423 } 1424 1425 Vector filterMethods = getFilterMethods(cms); 1427 1428 if (Integer.parseInt(selectBoxValue) >= filterMethods.size()) { 1429 selectBoxValue = "0"; 1431 } 1432 1433 session.putValue(sessionSelectBoxValue, selectBoxValue); session.putValue("filter", selectBoxValue); 1436 String filterParam = (String )parameters.get("filterparameter"); 1437 String sessionFilterParam = uri + selectBoxValue + "filterparameter"; 1439 if (filterParam != null) { 1441 session.putValue(sessionFilterParam, filterParam); 1442 } 1443 1444 String moduleName = ""; 1446 moduleName = getClass().toString(); moduleName = moduleName.substring(5); moduleName = moduleName.trim(); 1449 moduleName = moduleName.replace('.', '_'); 1451 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 1453 template.setData("filterlabel", lang.getLanguageValue(moduleName + ".label.filter")); 1455 template.setData("filterparameterlabel", lang.getLanguageValue(moduleName + ".label.filterparameter")); 1456 1457 if (selectBoxValue == null) { 1459 CmsFilterMethod defaultFilter = (CmsFilterMethod)filterMethods.firstElement(); 1460 session.putValue("selectbox", defaultFilter.getFilterName()); 1461 } 1462 1463 CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(Integer.parseInt(selectBoxValue)); 1465 if (currentFilter.hasUserParameter()) { 1466 if (filterChanged) { 1467 template.setData("filterparameter", currentFilter.getDefaultFilterParam()); 1468 session.putValue(sessionFilterParam, currentFilter.getDefaultFilterParam()); 1470 } else if (filterParam != null) { 1471 template.setData("filterparameter", filterParam); 1472 } else { 1473 template.setData("filterparameter", (String )session.getValue(sessionFilterParam)); 1475 } 1476 if (filterMethods.size() < 2) { 1478 CmsFilterMethod defaultFilter = (CmsFilterMethod)filterMethods.firstElement(); 1480 template.setData("filtername", defaultFilter.getFilterName()); 1481 template.setData("insertFilter", template.getProcessedDataValue("noSelectboxWithParam", this, parameters)); 1482 } else { 1483 template.setData("insertFilter", template.getProcessedDataValue("selectboxWithParam", this, parameters)); 1484 } 1485 template.setData("setfocus", template.getDataValue("focus")); 1486 } else { 1487 if (filterMethods.size() < 2) { 1489 CmsFilterMethod defaultFilter = (CmsFilterMethod)filterMethods.firstElement(); 1491 template.setData("filtername", defaultFilter.getFilterName()); 1492 template.setData("insertFilter", template.getProcessedDataValue("noSelectbox", this, parameters)); 1493 } else { 1494 template.setData("insertFilter", template.getProcessedDataValue("singleSelectbox", this, parameters)); 1495 } 1496 } 1497 1498 String createButton = null; 1501 try { 1502 createButton = getCreateUrl(cms, null, null, null); 1503 } catch (Exception e) { } 1504 if (createButton == null) { 1505 String cb = template.getDataValue("nowand"); 1506 template.setData("createbutton", cb); 1507 } else { 1508 boolean buttonActiv = true; 1509 if (isExtendedList() && (cms.getRequestContext().currentProject().isOnlineProject())) { 1510 buttonActiv = false; 1511 } 1512 if (buttonActiv) { 1513 String cb = template.getProcessedDataValue("wand", this, parameters); 1514 template.setData("createbutton", cb); 1515 } else { 1516 String cb = template.getProcessedDataValue("deactivwand", this, parameters); 1517 template.setData("createbutton", cb); 1518 } 1519 } 1520 1521 String setupButton = null; 1523 try { 1524 setupButton = getSetupUrl(cms, null, null, null); 1525 } catch (Exception e) { } 1526 if ((setupButton == null) || (setupButton.equals(""))) { 1527 String sb = template.getDataValue("nosetup"); 1528 template.setData("setupbutton", sb); 1529 } else { 1530 String sb = template.getProcessedDataValue("setup", this, parameters); 1531 template.setData("setupbutton", sb); 1532 } 1533 1534 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 1536 return processResult; 1537 } 1538 1553 private byte[] getContentList(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 1554 byte[] processResult = null; 1556 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 1558 Class cdClass = getContentDefinitionClass(); 1560 1561 String filterMethodName = (String )session.getValue("filter"); 1563 if (filterMethodName == null) { 1564 filterMethodName = "0"; 1565 } 1566 1567 String uri = cms.getRequestContext().getUri(); 1568 String sessionFilterParam = uri + filterMethodName + "filterparameter"; 1569 String filterParam = (String )session.getValue(sessionFilterParam); 1571 if (filterParam == "") { 1572 filterParam = null; 1573 } 1574 1575 templateSelector = "list"; 1577 1578 String tableHead = ""; 1580 String singleRow = ""; 1581 String allEntrys = ""; 1582 String entry = ""; 1583 String url = ""; 1584 int columns = 0; 1585 1586 Vector columnsVector = new Vector (); 1588 String fieldNamesMethod = "getFieldNames"; 1589 Class paramClasses[] = {CmsObject.class}; 1590 Object params[] = {cms}; 1591 columnsVector = (Vector )getContentMethodObject(cms, cdClass, fieldNamesMethod, paramClasses, params); 1592 columns = columnsVector.size(); 1593 1594 String moduleName = ""; 1596 moduleName = getClass().toString(); moduleName = moduleName.substring(5); moduleName = moduleName.trim(); 1599 moduleName = moduleName.replace('.', '_'); 1601 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 1603 1604 for (int i = 0; i < columns; i++) { 1606 tableHead += (template.getDataValue("tabledatabegin")) + lang.getLanguageValue(moduleName + ".label." + columnsVector.elementAt(i).toString().toLowerCase().trim()) + (template.getDataValue("tabledataend")); 1607 } 1608 template.setData("tableheadline", tableHead); 1610 1611 Vector tableContent = new Vector (); 1614 try { 1615 Vector filterMethods = (Vector )cdClass.getMethod("getFilterMethods", new Class [] {CmsObject.class}).invoke(null, new Object [] {cms}); 1616 CmsFilterMethod filterMethod = null; 1617 CmsFilterMethod filterName = (CmsFilterMethod)filterMethods.elementAt(Integer.parseInt(filterMethodName)); 1618 filterMethodName = filterName.getFilterName(); 1619 for (int i = 0; i < filterMethods.size(); i++) { 1621 CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(i); 1622 if (currentFilter.getFilterName().equals(filterMethodName)) { 1623 filterMethod = currentFilter; 1624 break; 1625 } 1626 } 1627 1628 if (filterMethod == null) { 1630 filterMethod = (CmsFilterMethod)filterMethods.firstElement(); 1631 } 1632 tableContent = (Vector )cdClass.getMethod("applyFilter", new Class [] {CmsObject.class, CmsFilterMethod.class, String .class}).invoke(null, new Object [] {cms, filterMethod, filterParam}); 1634 } catch (InvocationTargetException ite) { 1635 if (CmsLog.getLog(this).isWarnEnabled()) { 1637 CmsLog.getLog(this).warn("Apply filter caused an InvocationTargetException", ite); 1638 } 1639 templateSelector = "error"; 1640 template.setData("filtername", filterMethodName); 1641 while (ite.getTargetException() instanceof InvocationTargetException ) { 1642 ite = ((InvocationTargetException )ite.getTargetException()); 1643 } 1644 template.setData("filtererror", ite.getTargetException().getMessage()); 1645 session.removeValue(sessionFilterParam); 1646 } catch (NoSuchMethodException nsm) { 1648 if (CmsLog.getLog(this).isWarnEnabled()) { 1649 CmsLog.getLog(this).warn("Apply filter method was not found", nsm); 1650 } 1651 templateSelector = "error"; 1652 template.setData("filtername", filterMethodName); 1653 template.setData("filtererror", nsm.getMessage()); 1654 session.removeValue(sessionFilterParam); 1655 } catch (Exception e) { 1657 if (CmsLog.getLog(this).isWarnEnabled()) { 1658 CmsLog.getLog(this).warn("Apply filter: Other Exception", e); 1659 } 1660 templateSelector = "error"; 1661 template.setData("filtername", filterMethodName); 1662 template.setData("filtererror", e.getMessage()); 1663 session.removeValue(sessionFilterParam); 1664 } 1666 1667 int rows = tableContent.size(); 1669 1670 Vector fieldMethods = new Vector (); 1672 try { 1673 fieldMethods = (Vector )cdClass.getMethod("getFieldMethods", new Class [] {CmsObject.class}).invoke(null, new Object [] {cms}); 1674 } catch (Exception exc) { 1675 if (CmsLog.getLog(this).isWarnEnabled()) { 1676 CmsLog.getLog(this).warn("getFieldMethods caused an exception", exc); 1677 } 1678 templateSelector = "error"; 1679 template.setData("filtername", filterMethodName); 1680 template.setData("filtererror", exc.getMessage()); 1681 } 1682 1683 String fieldEntry = ""; 1685 String id = ""; 1686 for (int i = 0; i < rows; i++) { 1687 entry = ""; 1689 singleRow = ""; 1690 Object entryObject = new Object (); 1691 entryObject = tableContent.elementAt(i); 1693 for (int j = 0; j < columns; j++) { 1695 fieldEntry = "+++ NO VALUE FOUND +++"; 1696 Method getMethod = null; 1698 try { 1699 getMethod = (Method )fieldMethods.elementAt(j); 1700 1701 } catch (Exception e) { 1702 if (CmsLog.getLog(this).isWarnEnabled()) { 1703 CmsLog.getLog(this).warn("Could not get field method for " + (String )columnsVector.elementAt(j) + " - check for correct spelling", e); 1704 } 1705 } 1706 try { 1707 Object fieldEntryObject = null; 1709 1710 fieldEntryObject = getMethod.invoke(entryObject, new Object [0]); 1711 1712 if (fieldEntryObject != null) { 1713 fieldEntry = fieldEntryObject.toString(); 1714 } else { 1715 fieldEntry = null; 1716 } 1717 } catch (InvocationTargetException ite) { 1718 if (CmsLog.getLog(this).isWarnEnabled()) { 1719 CmsLog.getLog(this).warn("Backoffice content definition object caused an InvocationTargetException", ite); 1720 } 1721 } catch (Exception e) { 1722 if (CmsLog.getLog(this).isWarnEnabled()) { 1723 CmsLog.getLog(this).warn("Backoffice content definition object: Other exception", e); 1724 } 1725 } 1726 1727 try { 1728 id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms); 1729 } catch (Exception e) { 1730 if (CmsLog.getLog(this).isWarnEnabled()) { 1731 CmsLog.getLog(this).warn("Backoffice: getUniqueId caused an Exception, e"); 1732 } 1733 } 1734 1735 if (id != null) { 1737 template.setData("uniqueid", id); 1738 } 1739 if (fieldEntry != null) { 1741 try { 1742 Vector v = new Vector (); 1743 v.addElement(new CmsUUID(id)); 1744 v.addElement(template); 1745 url = getUrl(cms, null, null, v); 1746 } catch (Exception e) { 1747 if (CmsLog.getLog(this).isErrorEnabled()) { 1748 CmsLog.getLog(this).error("Error getting URL for ID " + id, e); 1749 } 1750 1751 url = ""; 1752 } 1753 if (!url.equals("")) { 1754 entry += (template.getDataValue("tabledatabegin")) + (template.getProcessedDataValue("url", this, parameters)) + fieldEntry + (template.getDataValue("tabledataend")); 1756 } else { 1757 entry += (template.getDataValue("tabledatabegin")) + fieldEntry + (template.getDataValue("tabledataend")); 1759 } 1760 } else { 1761 entry += (template.getDataValue("tabledatabegin")) + "" + (template.getDataValue("tabledataend")); 1762 } 1763 } 1764 try { 1766 id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms); 1767 } catch (Exception e) { 1768 if (CmsLog.getLog(this).isWarnEnabled()) { 1769 CmsLog.getLog(this).warn("Backoffice: getUniqueId caused an Exception", e); 1770 } 1771 } 1772 1773 if (id != null) { 1775 template.setData("uniqueid", id); 1776 } 1777 1778 setLockstates(cms, template, cdClass, entryObject, parameters); 1780 1781 template.setData("entry", entry); 1783 1784 singleRow = template.getProcessedDataValue("singlerow", this, parameters); 1786 allEntrys += (template.getDataValue("tablerowbegin")) + singleRow + (template.getDataValue("tablerowend")); 1787 } 1788 1789 template.setData("tablecontent", "" + allEntrys); 1791 1792 session.putValue("selectbox", filterMethodName); 1794 1795 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 1797 return processResult; 1798 } 1799 1800 1815 private byte[] getContentExtendedList(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 1816 1817 byte[] processResult = null; 1819 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 1821 Class cdClass = getContentDefinitionClass(); 1823 1824 String filterMethodName = (String )session.getValue("filter"); 1826 if (filterMethodName == null) { 1827 filterMethodName = "0"; 1828 } 1829 String uri = cms.getRequestContext().getUri(); 1830 String sessionFilterParam = uri + filterMethodName + "filterparameter"; 1831 String filterParam = (String )session.getValue(sessionFilterParam); 1833 if (filterParam == "") { 1834 filterParam = null; 1835 } 1836 templateSelector = "list"; 1838 1839 StringBuffer tableHead = new StringBuffer (); 1841 String singleRow = new String (); 1842 StringBuffer allEntrys = new StringBuffer (); 1843 StringBuffer entry = new StringBuffer (); 1844 String url = ""; 1845 int columns = 0; 1846 String style = ">"; 1847 String url_style = ""; 1848 String tabledatabegin = template.getDataValue("tabledatabegin"); 1849 String tabledataend = template.getDataValue("tabledataend"); 1850 String tablerowbegin = template.getDataValue("tablerowbegin"); 1851 String tablerowend = template.getDataValue("tablerowend"); 1852 1853 Vector columnsVector = new Vector (); 1855 String fieldNamesMethod = "getFieldNames"; 1856 Class paramClasses[] = {CmsObject.class}; 1857 Object params[] = {cms}; 1858 columnsVector = (Vector )getContentMethodObject(cms, cdClass, fieldNamesMethod, paramClasses, params); 1859 columns = columnsVector.size(); 1860 String moduleName = ""; 1862 moduleName = getClass().toString(); moduleName = moduleName.substring(5); moduleName = moduleName.trim(); 1865 moduleName = moduleName.replace('.', '_'); 1867 CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 1869 for (int i = 0; i < columns; i++) { 1871 tableHead.append(tabledatabegin); 1872 tableHead.append(style); 1873 tableHead.append(lang.getLanguageValue(moduleName + ".label." + columnsVector.elementAt(i).toString().toLowerCase().trim())); 1874 tableHead.append(tabledataend); 1875 } 1876 template.setData("tableheadline", tableHead.toString()); 1878 Vector tableContent = new Vector (); 1881 try { 1882 Vector filterMethods = (Vector )cdClass.getMethod("getFilterMethods", new Class [] {CmsObject.class}).invoke(null, new Object [] {cms}); 1883 CmsFilterMethod filterMethod = null; 1884 CmsFilterMethod filterName = (CmsFilterMethod)filterMethods.elementAt(Integer.parseInt(filterMethodName)); 1885 filterMethodName = filterName.getFilterName(); 1886 for (int i = 0; i < filterMethods.size(); i++) { 1888 CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(i); 1889 if (currentFilter.getFilterName().equals(filterMethodName)) { 1890 filterMethod = currentFilter; 1891 break; 1892 } 1893 } 1894 if (filterMethod == null) { 1896 filterMethod = (CmsFilterMethod)filterMethods.firstElement(); 1897 } 1898 1899 tableContent = (Vector )cdClass.getMethod("applyFilter", new Class [] {CmsObject.class, CmsFilterMethod.class, String .class}).invoke(null, new Object [] {cms, filterMethod, filterParam}); 1901 } catch (InvocationTargetException ite) { 1902 if (CmsLog.getLog(this).isWarnEnabled()) { 1904 CmsLog.getLog(this).warn("Apply filter caused an InvocationTargetException", ite); 1905 } 1906 templateSelector = "error"; 1907 template.setData("filtername", filterMethodName); 1908 while (ite.getTargetException() instanceof InvocationTargetException ) { 1909 ite = ((InvocationTargetException )ite.getTargetException()); 1910 } 1911 template.setData("filtererror", ite.getTargetException().getMessage()); 1912 session.removeValue(sessionFilterParam); 1913 } catch (NoSuchMethodException nsm) { 1915 if (CmsLog.getLog(this).isWarnEnabled()) { 1916 CmsLog.getLog(this).warn("Apply filter method was not found", nsm); 1917 } 1918 templateSelector = "error"; 1919 template.setData("filtername", filterMethodName); 1920 template.setData("filtererror", nsm.getMessage()); 1921 session.removeValue(sessionFilterParam); 1922 } catch (Exception e) { 1924 if (CmsLog.getLog(this).isWarnEnabled()) { 1925 CmsLog.getLog(this).warn("Apply filter caused an Exception", e); 1926 } 1927 templateSelector = "error"; 1928 template.setData("filtername", filterMethodName); 1929 template.setData("filtererror", e.getMessage()); 1930 session.removeValue(sessionFilterParam); 1931 } 1933 1934 int rows = tableContent.size(); 1936 Vector fieldMethods = new Vector (); 1938 try { 1939 fieldMethods = (Vector )cdClass.getMethod("getFieldMethods", new Class [] {CmsObject.class}).invoke(null, new Object [] {cms}); 1940 } catch (Exception exc) { 1941 if (CmsLog.getLog(this).isWarnEnabled()) { 1942 CmsLog.getLog(this).warn("getFieldMethods caused an exception", exc); 1943 } 1944 templateSelector = "error"; 1945 template.setData("filtername", filterMethodName); 1946 template.setData("filtererror", exc.getMessage()); 1947 } 1948 1949 String fieldEntry = ""; 1951 String id = ""; 1952 1953 for (int i = 0; i < rows; i++) { 1954 entry = new StringBuffer (); 1956 singleRow = new String (); 1957 Object entryObject = new Object (); 1958 entryObject = tableContent.elementAt(i); 1960 style = this.getStyle(cms, template, entryObject) + ">"; 1963 url_style = this.getStyle(cms, template, entryObject); 1965 for (int j = 0; j < columns; j++) { 1968 fieldEntry = "+++ NO VALUE FOUND +++"; 1969 Method getMethod = null; 1971 try { 1972 getMethod = (Method )fieldMethods.elementAt(j); 1973 } catch (Exception e) { 1974 if (CmsLog.getLog(this).isWarnEnabled()) { 1975 CmsLog.getLog(this).warn("Could not get field method for " + (String )columnsVector.elementAt(j) + " - check for correct spelling", e); 1976 } 1977 } 1978 try { 1979 Object fieldEntryObject = null; 1981 fieldEntryObject = getMethod.invoke(entryObject, new Object [0]); 1982 if (fieldEntryObject != null) { 1983 fieldEntry = fieldEntryObject.toString(); 1984 } else { 1985 fieldEntry = null; 1986 } 1987 } catch (InvocationTargetException ite) { 1988 if (CmsLog.getLog(this).isWarnEnabled()) { 1989 CmsLog.getLog(this).warn("Backoffice content definition object caused an InvocationTargetException", ite); 1990 } 1991 } catch (Exception e) { 1992 if (CmsLog.getLog(this).isWarnEnabled()) { 1993 CmsLog.getLog(this).warn("Backoffice content definition object: Other exception", e); 1994 } 1995 } 1996 try { 1997 id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms); 1998 } catch (Exception e) { 1999 if (CmsLog.getLog(this).isWarnEnabled()) { 2000 CmsLog.getLog(this).warn("Backoffice getUniqueId caused an Exception", e); 2001 } 2002 } 2003 2004 if (id != null) { 2006 template.setData("uniqueid", id); 2007 } 2008 if (fieldEntry != null) { 2010 try { 2011 Vector v = new Vector (); 2012 v.addElement(new Integer (id)); 2013 v.addElement(template); 2014 url = getUrl(cms, null, null, v); 2015 } catch (Exception e) { 2016 url = ""; 2017 } 2018 if (!url.equals("")) { 2019 template.setData("url_style", url_style); 2021 entry.append(tabledatabegin); 2022 entry.append(style); 2023 entry.append(template.getProcessedDataValue("url", this, parameters)); 2024 entry.append(fieldEntry); 2025 entry.append(tabledataend); 2026 } else { 2027 entry.append(tabledatabegin); 2029 entry.append(style); 2030 entry.append(fieldEntry); 2031 entry.append(tabledataend); 2032 } 2033 } else { 2034 entry.append(tabledatabegin); 2035 entry.append(""); 2036 entry.append(tabledataend); 2037 } 2038 } 2039 try { 2041 id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms); 2042 } catch (Exception e) { 2043 if (CmsLog.getLog(this).isWarnEnabled()) { 2044 CmsLog.getLog(this).warn("Backoffice: getUniqueId caused an Exception", e); 2045 } 2046 } 2047 2048 if (id != null) { 2050 template.setData("uniqueid", id); 2051 } 2052 2053 setExtendedLockstates(cms, template, cdClass, entryObject, parameters); 2055 setProjectFlag(cms, template, cdClass, entryObject, parameters); 2057 setContextMenu(cms, template, entryObject); 2059 template.setData("entry", entry.toString()); 2061 singleRow = template.getProcessedDataValue("singlerow", this, parameters); 2063 allEntrys.append(tablerowbegin); 2064 allEntrys.append(singleRow); 2065 allEntrys.append(tablerowend); 2066 2067 } 2068 2069 template.setData("tablecontent", allEntrys.toString()); 2071 2072 session.putValue("selectbox", filterMethodName); 2074 2075 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 2077 return processResult; 2078 } 2079 2080 2095 2096 private byte[] getContentLock(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 2097 2098 byte[] processResult = null; 2099 2100 CmsUserSettings settings = new CmsUserSettings(cms); 2102 2103 if (!settings.getDialogShowLock()) { 2104 parameters.put("action", "go"); 2105 } 2106 2107 CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 2109 Class cdClass = getContentDefinitionClass(); 2111 2112 CmsUUID actUserId = cms.getRequestContext().currentUser().getId(); 2113 String id = (String )parameters.get("id"); 2115 if (id == null) 2116 id = ""; 2117 2126 2127 parameters.put("idlock", id); 2128 2129 String action = (String )parameters.get("action"); 2131 if (action == null || action.equals("")) { 2133 templateSelector = "lock"; 2135 CmsUUID contentId = new CmsUUID(id); 2136 2137 CmsUUID lockedByUserId = CmsUUID.getNullUUID(); 2138 2139 2155 Object o = null; 2157 if (contentId != null) { 2158 o = getContentDefinition(cms, cdClass, contentId); 2159 try { 2160 lockedByUserId = ((A_CmsContentDefinition)o).getLockstate(); 2161 } catch (Exception e) { 2162 if (CmsLog.getLog(this).isWarnEnabled()) { 2163 CmsLog.getLog(this).warn(e.getMessage()); 2164 } 2165 } 2166 } else { 2167 o = getContentDefinition(cms, cdClass, id); 2168 try { 2169 lockedByUserId = ((A_CmsContentDefinition)o).getLockstate(); 2170 } catch (Exception e) { 2171 if (CmsLog.getLog(this).isWarnEnabled()) { 2172 CmsLog.getLog(this).warn(e.getMessage()); 2173 } 2174 } 2175 } 2176 String moduleName = ""; 2178 moduleName = getClass().toString(); moduleName = moduleName.substring(5); moduleName = moduleName.trim(); 2181 moduleName = moduleName.replace('.', '_'); CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms); 2184 if (!lockedByUserId.isNullUUID() && !lockedByUserId.equals(actUserId)) { 2186 template.setData("locktitle", lang.getLanguageValue("messagebox.title.lockchange")); 2188 template.setData("lockstate", lang.getLanguageValue("messagebox.message1.lockchange")); 2189 } 2190 if (lockedByUserId.isNullUUID()) { 2191 template.setData("locktitle", lang.getLanguageValue("messagebox.title.lock")); 2193 template.setData("lockstate", lang.getLanguageValue("messagebox.message1.lock")); 2194 } 2195 if (lockedByUserId.equals(actUserId)) { 2196 template.setData("locktitle", lang.getLanguageValue("messagebox.title.unlock")); 2197 template.setData("lockstate", lang.getLanguageValue("messagebox.message1.unlock")); 2198 } 2199 2200 template.setData("newsentry", id); 2202 2203 template.setData("setaction", "default"); 2205 parameters.put("action", "done"); 2206 2207 } else { 2209 templateSelector = "done"; 2210 2211 CmsUUID contentId = new CmsUUID(id); 2213 2214 CmsUUID lockedByUserId = CmsUUID.getNullUUID(); 2215 2216 Object o = null; 2218 o = getContentDefinition(cms, cdClass, contentId); 2219 try { 2220 lockedByUserId = ((A_CmsContentDefinition)o).getLockstate(); 2221 } catch (Exception e) { 2222 if (CmsLog.getLog(this).isWarnEnabled()) { 2223 CmsLog.getLog(this).warn(e.getMessage()); 2224 } 2225 } 2226 2227 try { 2228 lockedByUserId = ((A_CmsContentDefinition)o).getLockstate(); 2229 } catch (Exception e) { 2230 if (CmsLog.getLog(this).isWarnEnabled()) { 2231 CmsLog.getLog(this).warn("Method getLockstate caused an exception", e); 2232 } 2233 } 2234 2235 if (lockedByUserId.equals(actUserId)) { 2238 if (isExtendedList()) { 2239 int curProjectId = cms.getRequestContext().currentProject().getId(); 2242 int lockedInProject = -1; 2243 try { 2244 lockedInProject = ((I_CmsExtendedContentDefinition)o).getLockedInProject(); 2245 } catch (Exception e) { 2246 if (CmsLog.getLog(this).isWarnEnabled()) { 2247 CmsLog.getLog(this).warn("Method getLockstate caused an exception", e); 2248 } 2249 } 2250 if (curProjectId == lockedInProject) { 2251 try { 2253 ((A_CmsContentDefinition)o).setLockstate(CmsUUID.getNullUUID()); 2254 } catch (Exception e) { 2255 if (CmsLog.getLog(this).isWarnEnabled()) { 2256 CmsLog.getLog(this).warn("Method setLockstate caused an exception", e); 2257 } 2258 } 2259 } else { 2260 try { 2262 ((A_CmsContentDefinition)o).setLockstate(actUserId); 2263 } catch (Exception e) { 2264 if (CmsLog.getLog(this).isWarnEnabled()) { 2265 CmsLog.getLog(this).warn("Method setLockstate caused an exception", e); 2266 } 2267 } 2268 } 2269 } else { 2270 try { 2273 ((A_CmsContentDefinition)o).setLockstate(CmsUUID.getNullUUID()); 2274 } catch (Exception e) { 2275 if (CmsLog.getLog(this).isWarnEnabled()) { 2276 CmsLog.getLog(this).warn("Method setLockstate caused an exception", e); 2277 } 2278 } 2279 } 2280 try { 2282 ((A_CmsContentDefinition)o).write(cms); } catch (Exception e) { 2284 if (CmsLog.getLog(this).isWarnEnabled()) { 2285 CmsLog.getLog(this).warn("Method write caused an exception", e); 2286 } 2287 } 2288 templateSelector = "done"; 2289 } else { 2290 if ((!lockedByUserId.isNullUUID()) && (!lockedByUserId.equals(actUserId))) { 2291 try { 2293 ((A_CmsContentDefinition)o).setLockstate(actUserId); 2294 } catch (Exception e) { 2295 if (CmsLog.getLog(this).isWarnEnabled()) { 2296 CmsLog.getLog(this).warn("Could not set lockstate", e); 2297 } 2298 } 2299 try { 2301 ((A_CmsContentDefinition)o).write(cms); 2302 } catch (Exception e) { 2303 if (CmsLog.getLog(this).isWarnEnabled()) { 2304 CmsLog.getLog(this).warn("Could not set lockstate", e); 2305 } 2306 } 2307 templateSelector = "done"; 2308 } else { 2309 try { 2311 ((A_CmsContentDefinition)o).setLockstate(actUserId); 2312 } catch (Exception e) { 2313 if (CmsLog.getLog(this).isWarnEnabled()) { 2314 CmsLog.getLog(this).warn("Could not set lockstate", e); 2315 } 2316 } 2317 try { 2319 ((A_CmsContentDefinition)o).write(cms); 2320 } catch (Exception e) { 2321 if (CmsLog.getLog(this).isWarnEnabled()) { 2322 CmsLog.getLog(this).warn("Could not write to content definition", e); 2323 } 2324 } 2325 } 2326 } 2327 } 2328 processResult = startProcessing(cms, template, elementName, parameters, templateSelector); 2330 return processResult; 2331 } 2332 2342 2343 private Object getContentMethodObject(CmsObject cms, Class cdClass, String method, Class paramClasses[], Object params[]) { 2344 2345 Object retObject = null; 2347 if (method != "") { 2348 try { 2349 retObject = cdClass.getMethod(method, paramClasses).invoke(null, params); 2350 } catch (InvocationTargetException ite) { 2351 if (CmsLog.getLog(this).isWarnEnabled()) { 2352 CmsLog.getLog(this).warn(method + " caused an InvocationTargetException", ite); 2353 } 2354 ite.getTargetException().printStackTrace(); 2355 } catch (NoSuchMethodException nsm) { 2356 if (CmsLog.getLog(this).isWarnEnabled()) { 2357 CmsLog.getLog(this).warn(method + ": Requested method was not found", nsm); 2358 } 2359 } catch (Exception e) { 2360 if (CmsLog.getLog(this).isWarnEnabled()) { 2361 CmsLog.getLog(this).warn(method + ": Other Exception", e); 2362 } 2363 } 2364 } 2365 return retObject; 2366 } 2367 2368 2381 public byte[] getContentNew(CmsObject cms, CmsXmlWpTemplateFile templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 2382 parameters.put("id", "new"); 2383 return getContentEdit(cms, templateFile, elementName, parameters, templateSelector); 2384 } 2385 2386 2401 public String getContentNew(CmsObject cms, CmsXmlWpTemplateFile template, A_CmsContentDefinition cd, String elementName, Enumeration keys, Hashtable parameters, String templateSelector) throws CmsException { 2402 parameters.put("id", "new"); 2403 return getContentEdit(cms, template, cd, elementName, keys, parameters, templateSelector); 2404 } 2405 2406 2419 public byte[] getContentEdit(CmsObject cms, CmsXmlWpTemplateFile templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 2420 return null; 2421 } 2422 2423 2437 public String getContentEdit(CmsObject cms, CmsXmlWpTemplateFile templateFile, A_CmsContentDefinition cd, String elementName, Enumeration keys, Hashtable parameters, String templateSelector) throws CmsException { 2438 return null; 2439 } 2440 2441 2450 private void setLockstates(CmsObject cms, CmsXmlWpTemplateFile template, Class cdClass, Object entryObject, Hashtable parameters) { 2451 2452 String la = "false"; 2454 Object laObject = new Object (); 2455 CmsUUID lockedByUserId = CmsUUID.getNullUUID(); 2456 String lockString = null; 2457 CmsUUID actUserId = cms.getRequestContext().currentUser().getId(); 2458 String isLockedBy = null; 2459 boolean hasWriteAccess = false; 2460 2461 try { 2463 Method laMethod = cdClass.getMethod("isLockable", new Class [] {}); 2465 laObject = laMethod.invoke(null, null); 2467 } catch (InvocationTargetException ite) { 2468 if (CmsLog.getLog(this).isWarnEnabled()) { 2469 CmsLog.getLog(this).warn("Method isLockable caused an Invocation target exception", ite); 2470 } 2471 } catch (NoSuchMethodException nsm) { 2472 if (CmsLog.getLog(this).isWarnEnabled()) { 2473 CmsLog.getLog(this).warn("Requested method isLockable was not found", nsm); 2474 } 2475 } catch (Exception e) { 2476 if (CmsLog.getLog(this).isWarnEnabled()) { 2477 CmsLog.getLog(this).warn("Method isLockable caused an exception", e); 2478 } 2479 } 2480 2481 la = laObject.toString(); 2483 if (la.equals("false")) { 2484 try { 2485 template.setData("backofficecontextmenue", "backofficeedit"); 2487 template.setData("lockedby", template.getDataValue("nolock")); 2488 } catch (Exception e) { 2489 if (CmsLog.getLog(this).isWarnEnabled()) { 2490 CmsLog.getLog(this).warn("Backoffice setLockstates:'not lockable' section caused an exception", e); 2491 } 2492 } 2493 } else { 2494 try { 2496 lockedByUserId = ((A_CmsContentDefinition)entryObject).getLockstate(); 2498 hasWriteAccess = ((A_CmsContentDefinition)entryObject).hasWriteAccess(cms); 2499 } catch (Exception e) { 2500 if (CmsLog.getLog(this).isWarnEnabled()) { 2501 CmsLog.getLog(this).warn("Method getLockstate caused an exception", e); 2502 } 2503 } 2504 try { 2505 if (lockedByUserId.equals(actUserId)) { 2507 isLockedBy = cms.getRequestContext().currentUser().getName(); 2509 template.setData("isLockedBy", isLockedBy); lockString = template.getProcessedDataValue("lockuser", this, parameters); 2511 template.setData("lockedby", lockString); 2512 template.setData("backofficecontextmenue", "backofficelockuser"); 2513 } else { 2514 if (!lockedByUserId.isNullUUID()) { 2515 if (!hasWriteAccess) { 2518 lockString = template.getProcessedDataValue("noaccess", this, parameters); 2519 template.setData("lockedby", lockString); 2520 template.setData("backofficecontextmenue", "backofficenoaccess"); 2521 } else { 2522 isLockedBy = readSaveUserName(cms, lockedByUserId); 2523 template.setData("isLockedBy", isLockedBy); 2524 lockString = template.getProcessedDataValue("lock", this, parameters); 2525 template.setData("lockedby", lockString); 2526 template.setData("backofficecontextmenue", "backofficelock"); 2527 } 2528 } else { 2529 lockString = template.getProcessedDataValue("nolock", this, parameters); 2531 template.setData("lockedby", lockString); 2532 template.setData("backofficecontextmenue", "backofficenolock"); 2533 } 2534 } 2535 } catch (Exception e) { 2536 if (CmsLog.getLog(this).isWarnEnabled()) { 2537 CmsLog.getLog(this).warn("Backoffice setLockstates caused an exception", e); 2538 } 2539 } 2540 } 2541 } 2542 2543 2552 private void setExtendedLockstates(CmsObject cms, CmsXmlWpTemplateFile template, Class cdClass, Object entryObject, Hashtable parameters) { 2553 2554 String la = "false"; 2556 Object laObject = new Object (); 2557 CmsUUID lockedByUserId = CmsUUID.getNullUUID(); 2558 String lockString = null; 2559 CmsUUID actUserId = cms.getRequestContext().currentUser().getId(); 2560 String isLockedBy = null; 2561 int lockedInProject = -1; 2562 int curProjectId = cms.getRequestContext().currentProject().getId(); 2563 boolean hasWriteAccess = false; 2564 2565 try { 2567 Method laMethod = cdClass.getMethod("isLockable", new Class [] {}); 2569 laObject = laMethod.invoke(null, null); 2571 } catch (InvocationTargetException ite) { 2572 if (CmsLog.getLog(this).isWarnEnabled()) { 2573 CmsLog.getLog(this).warn("Method isLockable caused an Invocation target exception", ite); 2574 } 2575 } catch (NoSuchMethodException nsm) { 2576 if (CmsLog.getLog(this).isWarnEnabled()) { 2577 CmsLog.getLog(this).warn("Requested method isLockable was not found", nsm); 2578 } 2579 } catch (Exception e) { 2580 if (CmsLog.getLog(this).isWarnEnabled()) { 2581 CmsLog.getLog(this).warn("Method isLockable caused an exception", e); 2582 } 2583 } 2584 2585 la = laObject.toString(); 2587 if (la.equals("false")) { 2588 try { 2589 template.setData("backofficecontextmenue", "backofficeedit"); 2591 template.setData("lockedby", template.getDataValue("nolock")); 2592 } catch (Exception e) { 2593 if (CmsLog.getLog(this).isWarnEnabled()) { 2594 CmsLog.getLog(this).warn("Backoffice setLockstates:'not lockable' section caused an exception", e); 2595 } 2596 } 2597 } else { 2598 try { 2600 lockedByUserId = ((A_CmsContentDefinition)entryObject).getLockstate(); 2602 hasWriteAccess = ((A_CmsContentDefinition)entryObject).hasWriteAccess(cms); 2603 } catch (Exception e) { 2604 if (CmsLog.getLog(this).isWarnEnabled()) { 2605 CmsLog.getLog(this).warn("Method getLockstate caused an exception", e); 2606 } 2607 } 2608 try { 2609 if (lockedByUserId.equals(actUserId)) { 2611 isLockedBy = cms.getRequestContext().currentUser().getName(); 2613 template.setData("isLockedBy", isLockedBy); try { 2616 lockedInProject = ((I_CmsExtendedContentDefinition)entryObject).getLockedInProject(); 2618 } catch (Exception e) { 2619 if (CmsLog.getLog(this).isWarnEnabled()) { 2620 CmsLog.getLog(this).warn("Method getLockedInProject caused an exception", e); 2621 } 2622 } 2623 if (lockedInProject == curProjectId) { 2624 lockString = template.getProcessedDataValue("lockuser", this, parameters); 2625 } else { 2626 lockString = template.getProcessedDataValue("lock", this, parameters); 2627 } 2628 template.setData("lockedby", lockString); 2629 } else { 2630 if (!lockedByUserId.isNullUUID()) { 2631 if (!hasWriteAccess) { 2634 lockString = template.getProcessedDataValue("noaccess", this, parameters); 2635 template.setData("lockedby", lockString); 2636 } else { 2637 isLockedBy = readSaveUserName(cms, lockedByUserId); 2638 template.setData("isLockedBy", isLockedBy); 2639 lockString = template.getProcessedDataValue("lock", this, parameters); 2640 template.setData("lockedby", lockString); 2641 } 2642 } else { 2643 lockString = template.getProcessedDataValue("nolock", this, parameters); 2645 template.setData("lockedby", lockString); 2646 } 2647 } 2648 } catch (Exception e) { 2649 if (CmsLog.getLog(this).isWarnEnabled()) { 2650 CmsLog.getLog(this).warn("Backoffice setLockstates caused an exception", e); 2651 } 2652 } 2653 } 2654 } 2655 2664 private void setProjectFlag(CmsObject cms, CmsXmlWpTemplateFile template, Class cdClass, Object entryObject, Hashtable parameters) { 2665 2666 int state = 0; 2668 int projectId = 1; 2669 String projectFlag = null; 2670 int actProjectId = cms.getRequestContext().currentProject().getId(); 2671 String isInProject = null; 2672 try { 2674 template.setData("projectflag", template.getDataValue("noproject")); 2675 } catch (Exception e) { 2676 if (CmsLog.getLog(this).isWarnEnabled()) { 2677 CmsLog.getLog(this).warn("Backoffice setProjectFlag:'no project' section caused an exception", e); 2678 } 2679 } 2680 2681 try { 2683 state = ((I_CmsExtendedContentDefinition)entryObject).getState(); 2684 } catch (Exception e) { 2685 if (CmsLog.getLog(this).isWarnEnabled()) { 2686 CmsLog.getLog(this).warn("Method getState caused an exception", e); 2687 } 2688 } 2689 2690 if (state == 0) { 2691 try { 2692 template.setData("projectflag", template.getDataValue("noproject")); 2694 } catch (Exception e) { 2695 if (CmsLog.getLog(this).isWarnEnabled()) { 2696 CmsLog.getLog(this).warn("Backoffice setProjectFlag:'no project' section caused an exception", e); 2697 } 2698 } 2699 } else { 2700 try { 2703 projectId = ((I_CmsExtendedContentDefinition)entryObject).getLockedInProject(); 2704 } catch (Exception e) { 2705 if (CmsLog.getLog(this).isWarnEnabled()) { 2706 CmsLog.getLog(this).warn("Method getLockedInProject caused an exception", e); 2707 } 2708 } 2709 try { 2710 try { 2712 isInProject = cms.readProject(projectId).getName(); 2713 } catch (CmsException e) { 2714 isInProject = ""; 2715 } 2716 template.setData("isInProject", isInProject); 2718 if (projectId == actProjectId) { 2719 projectFlag = template.getProcessedDataValue("thisproject", this, parameters); 2721 template.setData("projectflag", projectFlag); 2722 } else { 2723 projectFlag = template.getProcessedDataValue("otherproject", this, parameters); 2725 template.setData("projectflag", projectFlag); 2726 } 2727 } catch (Exception e) { 2728 if (CmsLog.getLog(this).isWarnEnabled()) { 2729 CmsLog.getLog(this).warn("Backoffice setLockstates caused an exception", e); 2730 } 2731 } 2732 } 2733 } 2734 2735 2744 private String getStyle(CmsObject cms, CmsXmlWpTemplateFile template, Object entryObject) { 2745 2746 int state = 0; 2748 int projectId = 1; 2749 int actProjectId = cms.getRequestContext().currentProject().getId(); 2750 String style = new String (); 2751 2752 try { 2754 projectId = ((I_CmsExtendedContentDefinition)entryObject).getProjectId(); 2755 } catch (Exception e) { 2756 if (CmsLog.getLog(this).isWarnEnabled()) { 2757 CmsLog.getLog(this).warn("Method getProjectId caused an exception", e); 2758 } 2759 } 2760 2761 if (actProjectId == CmsProject.ONLINE_PROJECT_ID) { 2762 style = C_STYLE_UNCHANGED; 2763 } else if (projectId != actProjectId) { 2764 style = C_STYLE_NOTINPROJECT; 2766 } else { 2767 try { 2769 ((A_CmsContentDefinition)entryObject).getLockstate(); 2770 } catch (Exception e) { 2771 if (CmsLog.getLog(this).isWarnEnabled()) { 2772 CmsLog.getLog(this).warn("Method getLockstate caused an exception", e); 2773 } 2774 } 2775 try { 2777 state = ((I_CmsExtendedContentDefinition)entryObject).getState(); 2778 } catch (Exception e) { 2779 if (CmsLog.getLog(this).isWarnEnabled()) { 2780 CmsLog.getLog(this).warn("Method getState caused an exception", e); 2781 } 2782 } 2783 2784 switch (state) { 2785 case CmsResource.STATE_NEW : 2786 style = C_STYLE_NEW; 2787 break; 2788 case CmsResource.STATE_CHANGED : 2789 style = C_STYLE_CHANGED; 2790 break; 2791 case CmsResource.STATE_DELETED : 2792 style = C_STYLE_DELETED; 2793 break; 2794 default : 2795 style = C_STYLE_UNCHANGED; 2796 break; 2797 } 2798 } 2799 return style; 2801 } 2802 2803 2810 private void setContextMenu(CmsObject cms, CmsXmlWpTemplateFile template, Object entryObject) { 2811 2812 int state = 0; 2814 CmsUUID lockedByUserId = CmsUUID.getNullUUID(); 2815 int projectId = 1; 2816 int lockedInProject = -1; 2817 int actProjectId = cms.getRequestContext().currentProject().getId(); 2818 2819 try { 2821 projectId = ((I_CmsExtendedContentDefinition)entryObject).getProjectId(); 2822 } catch (Exception e) { 2823 if (CmsLog.getLog(this).isWarnEnabled()) { 2824 CmsLog.getLog(this).warn("Method getProjectId caused an exception", e); 2825 } 2826 } 2827 2828 if (actProjectId == CmsProject.ONLINE_PROJECT_ID) { 2829 template.setData("backofficecontextmenue", "backofficeonline"); 2830 } else if (projectId != actProjectId) { 2831 template.setData("backofficecontextmenue", "backofficenoaccess"); 2833 } else { 2834 try { 2836 lockedByUserId = ((A_CmsContentDefinition)entryObject).getLockstate(); 2837 } catch (Exception e) { 2838 if (CmsLog.getLog(this).isWarnEnabled()) { 2839 CmsLog.getLog(this).warn("Method getLockstate caused an exception", e); 2840 } 2841 } 2842 try { 2844 state = ((I_CmsExtendedContentDefinition)entryObject).getState(); 2845 } catch (Exception e) { 2846 if (CmsLog.getLog(this).isWarnEnabled()) { 2847 CmsLog.getLog(this).warn("Method getState caused an exception", e); 2848 } 2849 } 2850 if (lockedByUserId.isNullUUID()) { 2851 if (state == CmsResource.STATE_UNCHANGED) { 2852 template.setData("backofficecontextmenue", "backofficenolock"); 2853 } else if (state == CmsResource.STATE_DELETED) { 2854 template.setData("backofficecontextmenue", "backofficedeleted"); 2855 } else { 2856 template.setData("backofficecontextmenue", "backofficenolockchanged"); 2857 } 2858 } else if (lockedByUserId.equals(cms.getRequestContext().currentUser().getId())) { 2859 try { 2861 lockedInProject = ((I_CmsExtendedContentDefinition)entryObject).getLockedInProject(); 2862 } catch (Exception e) { 2863 if (CmsLog.getLog(this).isWarnEnabled()) { 2864 CmsLog.getLog(this).warn("Method getLockedInProject caused an exception", e); 2865 } 2866 } 2867 if (lockedInProject == actProjectId) { 2868 template.setData("backofficecontextmenue", "backofficelockuser"); 2869 } else { 2870 template.setData("backofficecontextmenue", "backofficelock"); 2871 } 2872 } else { 2873 template.setData("backofficecontextmenue", "backofficelock"); 2874 } 2875 } 2876 } 2877 2878 2883 public boolean isExtendedList() { 2884 return false; 2885 } 2886 2887 2898 public Integer getFilter(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException { 2899 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 2900 int returnValue = 0; 2901 String uri = cms.getRequestContext().getUri(); 2902 String sessionSelectBoxValue = uri + "selectBoxValue"; 2903 Vector filterMethods = getFilterMethods(cms); 2904 String tmp = (String )session.getValue(sessionSelectBoxValue); 2905 if (tmp != null) { 2906 returnValue = Integer.parseInt(tmp); 2907 } 2908 for (int i = 0; i < filterMethods.size(); i++) { 2909 CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(i); 2910 names.addElement(currentFilter.getFilterName()); 2912 values.addElement("" + i); 2913 } 2914 return new Integer (returnValue); 2915 } 2916 2917 2927 public Object handleCheckbox(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException { 2928 Hashtable parameters = (Hashtable )userObject; 2929 String returnValue = ""; 2930 String selected = (String )parameters.get(tagcontent); 2931 if (selected != null && selected.equals("on")) { 2932 returnValue = "checked"; 2933 } 2934 return returnValue; 2935 } 2936 2937 2942 private Vector getFilterMethods(CmsObject cms) { 2943 Vector filterMethods = new Vector (); 2944 Class cdClass = getContentDefinitionClass(); 2945 try { 2946 filterMethods = (Vector )cdClass.getMethod("getFilterMethods", new Class [] {CmsObject.class}).invoke(null, new Object [] {cms}); 2947 } catch (InvocationTargetException ite) { 2948 if (CmsLog.getLog(this).isWarnEnabled()) { 2950 CmsLog.getLog(this).warn("InvocationTargetException", ite); 2951 } 2952 } catch (NoSuchMethodException nsm) { 2953 if (CmsLog.getLog(this).isWarnEnabled()) { 2954 CmsLog.getLog(this).warn("Requested method was not found", nsm); 2955 } 2956 } catch (Exception e) { 2957 if (CmsLog.getLog(this).isWarnEnabled()) { 2958 CmsLog.getLog(this).warn("Problem occured with your filter methods", e); 2959 } 2960 } 2961 return filterMethods; 2962 } 2963 2964 2975 public Integer getSelectedPage(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException { 2976 2977 int returnValue = 0; 2978 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 2979 Vector templateSelectors = (Vector )session.getValue("backofficepageselectorvector"); 2981 String selectedPage = (String )parameters.get("backofficepage"); 2983 if (selectedPage == null) { 2984 selectedPage = ""; 2985 } 2986 2987 if (templateSelectors != null) { 2989 for (int i = 0; i < templateSelectors.size(); i++) { 2990 String selector = (String )templateSelectors.elementAt(i); 2991 names.addElement(selector); 2992 values.addElement(selector); 2993 if (selectedPage.equals(selector)) { 2995 returnValue = i; 2996 } 2997 } 2998 } 2999 session.putValue("backofficeselectortransfer", values); 3000 session.putValue("backofficeselectedtransfer", new Integer (returnValue)); 3001 return new Integer (returnValue); 3002 } 3003 3004 3020 private byte[] getContentNewInternal(CmsObject cms, String id, A_CmsContentDefinition cd, I_CmsSession session, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 3021 3022 byte[] returnProcess = null; 3024 String error = ""; 3026 String action = (String )parameters.get("action"); 3028 3029 templateSelector = getTemplateSelector(cms, template, parameters, templateSelector); 3031 3032 returnProcess = getContentNew(cms, template, elementName, parameters, templateSelector); 3035 3036 if (returnProcess == null) { 3038 3039 cd = (A_CmsContentDefinition)session.getValue(this.getContentDefinitionClass().getName()); 3041 if (cd == null) { 3042 cd = (A_CmsContentDefinition)this.getContentDefinition(cms, this.getContentDefinitionClass()); 3044 } 3045 Enumeration keys = parameters.keys(); 3047 3048 error = getContentNew(cms, template, cd, elementName, keys, parameters, templateSelector); 3050 3051 Vector methods = this.getGetMethods(cd); 3053 Hashtable setMethods = this.getSetMethods(cd); 3055 this.fillContentDefinition(cms, cd, parameters, setMethods); 3057 3058 session.putValue(this.getContentDefinitionClass().getName(), cd); 3060 3061 if (!error.equals("")) { 3063 template.setData("error", template.getProcessedDataValue("errormsg") + error); 3064 } else { 3065 template.setData("error", ""); 3066 } 3067 3068 templateSelector = getContentButtonsInternal(cms, cd, session, template, parameters, templateSelector, action, error); 3070 3071 this.setDatablocks(cms, template, cd, methods); 3073 3074 returnProcess = startProcessing(cms, template, "", parameters, templateSelector); 3075 } 3076 3077 return returnProcess; 3079 } 3080 3081 3096 private byte[] getContentEditInternal(CmsObject cms, String id, A_CmsContentDefinition cd, I_CmsSession session, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 3097 3098 byte[] returnProcess = null; 3100 String error = ""; 3102 String action = (String )parameters.get("action"); 3104 3105 templateSelector = getTemplateSelector(cms, template, parameters, templateSelector); 3107 3108 returnProcess = getContentEdit(cms, template, elementName, parameters, templateSelector); 3111 3112 if (returnProcess == null) { 3114 cd = (A_CmsContentDefinition)session.getValue(this.getContentDefinitionClass().getName()); 3116 if (cd == null) { 3117 CmsUUID contentId = new CmsUUID(id); 3119 cd = (A_CmsContentDefinition)this.getContentDefinition(cms, this.getContentDefinitionClass(), contentId); 3120 } 3121 3122 Enumeration keys = parameters.keys(); 3124 error = getContentEdit(cms, template, cd, elementName, keys, parameters, templateSelector); 3126 3127 Vector getMethods = this.getGetMethods(cd); 3129 3130 Hashtable setMethods = this.getSetMethods(cd); 3132 3133 this.fillContentDefinition(cms, cd, parameters, setMethods); 3135 3136 session.putValue(this.getContentDefinitionClass().getName(), cd); 3138 3139 String previewButton = null; 3141 try { 3142 previewButton = getPreviewUrl(cms, null, null, null); 3143 } catch (Exception e) { } 3144 if (!((previewButton == null) || (previewButton.equals("")))) { 3145 session.putValue("weShallDisplayThePreviewButton", previewButton + "?id=" + cd.getUniqueId(cms)); 3146 } 3147 3148 if (!error.equals("")) { 3150 template.setData("error", template.getProcessedDataValue("errormsg") + error); 3151 } else { 3152 template.setData("error", ""); 3153 } 3154 3155 templateSelector = getContentButtonsInternal(cms, cd, session, template, parameters, templateSelector, action, error); 3157 3158 this.setDatablocks(cms, template, cd, getMethods); 3160 3161 returnProcess = startProcessing(cms, template, "", parameters, templateSelector); 3162 } 3163 3164 return returnProcess; 3166 } 3167 3168 3186 private String getContentButtonsInternal(CmsObject cms, A_CmsContentDefinition cd, I_CmsSession session, CmsXmlWpTemplateFile template, Hashtable parameters, String templateSelector, String action, String error) throws CmsException { 3187 3188 Vector errorCodes = null; 3190 String errorCode = null; 3192 String errorField = null; 3194 String errorType = null; 3196 3200 if (action != null) { 3201 if ((!action.equals("save")) && (!action.equals("saveexit")) && (!action.equals("exit"))) { 3203 try { 3204 cd.check(false); 3205 session.putValue("backofficepagetemplateselector", templateSelector); 3207 } catch (CmsPlausibilizationException plex) { 3208 errorCodes = plex.getErrorCodes(); 3210 for (int i = 0; i < errorCodes.size(); i++) { 3212 errorCode = (String )errorCodes.elementAt(i); 3213 if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode)) { 3215 error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode); 3216 } else { 3217 errorField = errorCode.substring(0, errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR)); 3219 if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField)) { 3220 error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField); 3221 } else { 3222 errorType = errorCode.substring(errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR) + 1, errorCode.length()); 3224 if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType)) { 3225 error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType); 3226 } else { 3227 error += "[" + errorCode + "]"; 3229 } 3230 } 3231 } 3232 } 3233 if (template.hasData("errormsg")) { 3235 error = template.getProcessedDataValue("errormsg") + error; 3236 } 3237 template.setData("error", error); 3238 if (session.getValue("backofficepagetemplateselector") != null) { 3239 3240 templateSelector = (String )session.getValue("backofficepagetemplateselector"); 3241 parameters.put("backofficepage", templateSelector); 3242 3243 } else { 3244 templateSelector = null; 3245 } 3246 3247 } } 3249 if (((action.equals("save")) || (action.equals("saveexit"))) && (error.equals(""))) { 3252 try { 3253 3255 cd.check(true); 3256 3257 3261 3262 cd.write(cms); 3264 3265 String previewButton = null; 3267 try { 3268 previewButton = getPreviewUrl(cms, null, null, null); 3269 } catch (Exception e) { } 3270 if (!((previewButton == null) || (previewButton.equals("")))) { 3271 session.putValue("weShallDisplayThePreviewButton", previewButton + "?id=" + cd.getUniqueId(cms)); 3272 } 3273 3274 } catch (CmsPlausibilizationException plex) { 3275 3276 errorCodes = plex.getErrorCodes(); 3278 3279 for (int i = 0; i < errorCodes.size(); i++) { 3281 errorCode = (String )errorCodes.elementAt(i); 3282 3283 if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode)) { 3285 error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode); 3286 } else { 3287 errorField = errorCode.substring(0, errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR)); 3289 if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField)) { 3290 error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField); 3291 } else { 3292 errorType = errorCode.substring(errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR) + 1, errorCode.length()); 3294 if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType)) { 3295 error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType); 3296 } else { 3297 error += "[" + errorCode + "]"; 3299 } 3300 } 3301 } 3302 3303 } 3304 3305 if (template.hasData("errormsg")) { 3307 error = template.getProcessedDataValue("errormsg") + error; 3308 } 3309 template.setData("error", error); 3310 3311 } catch (Exception ex) { 3312 session.removeValue(this.getContentDefinitionClass().getName()); 3315 session.removeValue("backofficepageselectorvector"); 3316 session.removeValue("backofficepagetemplateselector"); 3317 session.removeValue("media"); 3318 session.removeValue("selectedmediaCD"); 3319 session.removeValue("media_position"); 3320 session.removeValue("weShallDisplayThePreviewButton"); 3321 if (CmsLog.getLog(this).isErrorEnabled()) { 3322 CmsLog.getLog(this).error("Error while saving data to Content Definition", ex); 3323 } 3324 throw new CmsLegacyException(ex.getMessage(), CmsLegacyException.C_UNKNOWN_EXCEPTION, ex); 3325 } 3326 } 3328 if (errorCodes == null) { 3330 if ((action.equals("exit")) || ((action.equals("saveexit")) && (error.equals("")))) { 3332 try { 3333 session.removeValue(this.getContentDefinitionClass().getName()); 3335 session.removeValue("backofficepageselectorvector"); 3336 session.removeValue("backofficepagetemplateselector"); 3337 session.removeValue("media"); 3338 session.removeValue("selectedmediaCD"); 3339 session.removeValue("media_position"); 3340 session.removeValue("weShallDisplayThePreviewButton"); 3341 3342 return "done"; 3351 } catch (Exception e) { 3352 if (CmsLog.getLog(this).isErrorEnabled()) { 3353 CmsLog.getLog(this).error("Error while doing redirect ", e); 3354 } 3355 throw new CmsLegacyException(e.getMessage(), e); 3356 } 3357 } } } return templateSelector; 3361 } 3362 3363 3370 private Vector getGetMethods(A_CmsContentDefinition contentDefinition) { 3371 3372 Vector getMethods = new Vector (); 3373 Method [] methods = this.getContentDefinitionClass().getMethods(); 3375 for (int i = 0; i < methods.length; i++) { 3376 Method m = methods[i]; 3377 String name = m.getName().toLowerCase(); 3378 3379 if (name.startsWith("get") && !(name.endsWith("boignore"))) { 3382 Class [] param = m.getParameterTypes(); 3383 if (param.length == 0) { 3385 3386 Class retType = m.getReturnType(); 3387 if (retType.equals(java.lang.String .class)) { 3388 getMethods.addElement(m); 3389 } 3390 } 3391 } 3392 } return getMethods; 3394 } 3396 3402 private Hashtable getSetMethods(A_CmsContentDefinition contentDefinition) { 3403 Hashtable setMethods = new Hashtable (); 3404 Method [] methods = this.getContentDefinitionClass().getMethods(); 3406 for (int i = 0; i < methods.length; i++) { 3407 Method m = methods[i]; 3408 String name = m.getName().toLowerCase(); 3409 if (name.startsWith("set") && !(name.endsWith("boignore"))) { 3412 Class [] param = m.getParameterTypes(); 3413 if (param.length == 1) { 3415 if (param[0].equals(java.lang.String .class)) { 3417 Class retType = m.getReturnType(); 3418 if (retType.toString().equals("void")) { 3420 setMethods.put(m.getName().toLowerCase(), m); 3421 } 3422 } 3423 } 3424 } 3425 } return setMethods; 3427 } 3429 3439 private void setDatablocks(CmsObject cms, CmsXmlWpTemplateFile template, A_CmsContentDefinition contentDefinition, Vector methods) throws CmsException { 3440 String methodName = ""; 3441 String datablockName = ""; 3442 String value = ""; 3443 Method method; 3444 3445 for (int i = 0; i < methods.size(); i++) { 3446 method = (Method )methods.elementAt(i); 3448 methodName = method.getName(); 3449 datablockName = (methodName.substring(3, methodName.length())).toLowerCase(); 3451 if (datablockName.endsWith("string")) { 3453 datablockName = datablockName.substring(0, datablockName.indexOf("string")); 3454 } 3455 try { 3457 Object result = method.invoke(contentDefinition, new Object [] {}); 3458 if (result == null) { 3461 value = ""; 3462 } else { 3463 value = result + ""; 3465 } 3466 template.setData(datablockName, value); 3467 3468 String escapedValue = value; 3470 if (!"".equals(escapedValue.trim())) { 3471 escapedValue = CmsEncoder.escape(escapedValue, cms.getRequestContext().getEncoding()); 3472 } 3473 template.setData(datablockName + "escaped", escapedValue); 3474 } catch (Exception e) { 3475 if (CmsLog.getLog(this).isErrorEnabled()) { 3476 CmsLog.getLog(this).error("Error during automatic call method '" + methodName, e); 3477 } 3478 } } } 3482 3492 private void fillContentDefinition(CmsObject cms, A_CmsContentDefinition contentDefinition, Hashtable parameters, Hashtable setMethods) throws CmsException { 3493 3494 Enumeration keys = parameters.keys(); 3495 while (keys.hasMoreElements()) { 3497 String key = (String )keys.nextElement(); 3498 String value = parameters.get(key).toString(); 3499 3500 boolean isFile = false; 3502 Enumeration uploadedFiles = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getFileNames(); 3505 byte[] content = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getFile(value); 3506 while (uploadedFiles.hasMoreElements()) { 3507 String filename = (String )uploadedFiles.nextElement(); 3508 if (filename.equals(value)) { 3510 isFile = true; 3511 } 3512 } 3513 Method m = (Method )setMethods.get("set" + key); 3515 3516 if (m == null) { 3518 m = (Method )setMethods.get("set" + key + "string"); 3519 } 3520 if (m != null) { 3522 try { 3524 3525 m.invoke(contentDefinition, new Object [] {value}); 3526 3527 if (isFile) { 3530 String methodName = m.getName() + "Content"; 3532 Method contentMethod = this.getContentDefinitionClass().getMethod(methodName, new Class [] {byte[].class}); 3534 contentMethod.invoke(contentDefinition, new Object [] {content}); 3536 } 3537 } catch (Exception e) { 3538 if (CmsLog.getLog(this).isErrorEnabled()) { 3539 CmsLog.getLog(this).error("Error during automatic call method '" + m.getName(), e); 3540 } 3541 } } } } 3546 3556 private String getTemplateSelector(CmsObject cms, CmsXmlWpTemplateFile template, Hashtable parameters, String templateSelector) throws CmsException { 3557 I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true); 3558 if (templateSelector != null) { 3560 session.putValue("backofficepagetemplateselector", templateSelector); 3561 } 3562 Vector selectors = new Vector (); 3564 Vector filteredSelectors = new Vector (); 3566 selectors = template.getAllSections(); 3567 for (int i = 0; i < selectors.size(); i++) { 3569 String selector = (String )selectors.elementAt(i); 3570 if ((!selector.equals(C_DEFAULT_SELECTOR)) && (!selector.equals(C_DONE_SELECTOR))) { 3571 filteredSelectors.addElement(selector); 3572 } 3573 } 3574 3575 String selectedPage = (String )parameters.get("backofficepage"); 3576 3577 if (selectors.size() < 4) { 3579 template.setData("BOSELECTOR", ""); 3580 } 3581 3582 if (selectedPage != null && selectedPage.length() > 0) { 3583 3584 templateSelector = selectedPage; 3585 } else if (filteredSelectors.size() > 0) { 3586 templateSelector = (String )filteredSelectors.elementAt(0); 3587 session.putValue("backofficepagetemplateselector", templateSelector); 3588 } 3589 session.putValue("backofficepageselectorvector", filteredSelectors); 3590 3591 return templateSelector; 3592 } 3593 3594 3600 private int getAccessValue(Hashtable parameters) { 3601 int accessFlag = 0; 3602 for (int i = 0; i <= 8; i++) { 3603 String permissionsAtI = (String )parameters.get("permission_" + i); 3604 if (permissionsAtI != null) { 3605 if (permissionsAtI.equals("on")) { 3606 accessFlag += new Integer (C_ACCESS_FLAGS[i]).intValue(); 3607 } 3608 } 3609 } 3610 if (accessFlag == 0) { 3611 accessFlag = C_DEFAULT_PERMISSIONS; 3612 } 3613 return accessFlag; 3614 } 3615 3616 3622 private void setAccessValue(CmsXmlWpTemplateFile template, int accessFlags) { 3623 for (int i = 0; i <= 8; i++) { 3625 int accessValueAtI = new Integer (C_ACCESS_FLAGS[i]).intValue(); 3626 if ((accessFlags & accessValueAtI) > 0) { 3627 template.setData("permission_" + i, "checked"); 3628 } else { 3629 template.setData("permission_" + i, ""); 3630 } 3631 } 3632 } 3633 3634 3642 private void setGroupSelectbox(CmsObject cms, CmsXmlWpTemplateFile template, CmsUUID groupId) throws CmsException { 3643 List cmsGroups = cms.getGroups(); 3645 String groupOptions = ""; 3647 String groupName = readSaveGroupName(cms, groupId); 3649 for (int i = 0; i < cmsGroups.size(); i++) { 3650 String currentGroupName = ((CmsGroup)cmsGroups.get(i)).getName(); 3651 CmsUUID currentGroupId = ((CmsGroup)cmsGroups.get(i)).getId(); 3652 template.setData("name", currentGroupName); 3653 template.setData("value", currentGroupId.toString()); 3654 if (!groupId.isNullUUID() && groupName.equals(currentGroupName)) { 3655 template.setData("check", "selected"); 3656 } else { 3657 template.setData("check", ""); 3658 } 3659 groupOptions = groupOptions + template.getProcessedDataValue("selectoption", this); 3660 } 3661 template.setData("groups", groupOptions); 3662 template.setData("groupname", groupName); 3663 } 3664 3665 3673 private void setOwnerSelectbox(CmsObject cms, CmsXmlWpTemplateFile template, CmsUUID ownerId) throws CmsException { 3674 String userOptions = ""; 3676 List cmsUsers = cms.getUsers(); 3677 String ownerName = readSaveUserName(cms, ownerId); 3678 for (int i = 0; i < cmsUsers.size(); i++) { 3679 String currentUserName = ((CmsUser)cmsUsers.get(i)).getName(); 3680 CmsUUID currentUserId = ((CmsUser)cmsUsers.get(i)).getId(); 3681 template.setData("name", currentUserName); 3682 template.setData("value", currentUserId.toString()); 3683 if (!ownerId.isNullUUID() && ownerName.equals(currentUserName)) { 3684 template.setData("check", "selected"); 3685 } else { 3686 template.setData("check", ""); 3687 } 3688 userOptions = userOptions + template.getProcessedDataValue("selectoption", this); 3689 } 3690 template.setData("users", userOptions); 3691 template.setData("username", ownerName); 3692 } 3693 3694 3703 public Object checkbox(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException { 3704 String name = null; 3705 String param = ""; 3706 String value = ""; 3707 String checked = null; 3708 3709 CmsXmlTemplateFile temp = (CmsXmlTemplateFile)doc; 3710 int index = tagcontent.indexOf(","); 3712 if (index > -1 && index <= tagcontent.length()) { 3713 name = tagcontent.substring(0, index); 3714 param = tagcontent.substring(index + 1, tagcontent.length()); 3715 } else { 3716 name = tagcontent; 3717 } 3718 value = temp.getDataValue(name); 3720 if (value.equals("on")) { 3721 checked = "checked"; 3722 } else { 3723 checked = ""; 3724 } 3725 3726 String buf = "<input type=hidden name=\"" + name + "\" value=\"off\">" + "<input type=checkbox name=\"" + name + "\" " + checked + " " + param + ">\n"; 3727 3728 return buf.toString(); 3729 } 3730} 3731 | Popular Tags |