1 20 21 package jahiatemplates.org.jahia.portlets_api; 22 23 import java.io.File ; 24 import java.util.Enumeration ; 25 import java.util.Vector ; 26 27 import org.jahia.data.containers.JahiaContainer; 28 import org.jahia.exceptions.JahiaException; 29 import org.jahia.registries.ServicesRegistry; 30 import org.jahia.services.acl.ACLNotFoundException; 31 import org.jahia.services.acl.JahiaACLEntry; 32 import org.jahia.services.acl.JahiaBaseACL; 33 import org.jahia.services.usermanager.JahiaGroup; 34 import org.jahia.services.usermanager.JahiaGroupManagerService; 35 import org.jahia.services.usermanager.JahiaUser; 36 import org.jahia.utils.JahiaConsole; 37 38 public class PortletsBean 39 { 40 41 private static PortletsBean theObject = null; 42 private static String theDefaultUser = "guest"; 43 private DesktopObj theDesktop; 44 private PortletObj thePortlet; 45 private SkinObj theSkin; 46 private Vector thePortletList; 47 private int theColumnCount; 48 49 50 56 private PortletsBean() 57 { 58 JahiaConsole.println( "PortletsBean", "***** Starting the PortletBean *****" ); 59 } 60 61 62 68 public static synchronized PortletsBean getInstance() 69 { 70 if (theObject == null) { 71 theObject = new PortletsBean(); 72 } 73 return theObject; 74 } 76 77 78 84 public Enumeration getPortlets(int thePageID, String theUserName, String uRLtoTemplatesDir) { 85 try { 86 String theFile = theUserName + ".xml"; 87 String theDefaultFile = theDefaultUser + ".xml"; 88 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 89 thePortletList = XMLFile.getPortletList(); 90 } catch (JahiaException e) { 91 JahiaConsole.println( "PortletsBean -> loadPortlet", e.toString() ); 92 } 93 return thePortletList.elements(); 94 } 96 97 103 public Enumeration getPortletsFromColumn(int theColumn, int thePageID, String theUserName, String uRLtoTemplatesDir) { 104 try { 105 String theFile = theUserName + ".xml"; 106 String theDefaultFile = theDefaultUser + ".xml"; 107 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 108 thePortletList = XMLFile.getPortletListFromColumn(theColumn); 109 } catch (JahiaException e) { 110 JahiaConsole.println( "PortletsBean -> loadPortlet", e.toString() ); 111 } 112 return thePortletList.elements(); 113 } 115 116 122 public PortletObj getPortletByID(int thePortletID, int thePageID, String theUserName, String uRLtoTemplatesDir) { 123 try { 124 String theFile = theUserName + ".xml"; 125 String theDefaultFile = theDefaultUser + ".xml"; 126 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 127 thePortlet = XMLFile.getPortlet(thePortletID); 128 } catch (JahiaException e) { 129 JahiaConsole.println( "PortletsBean -> loadPortlet", e.toString() ); 130 } 131 return thePortlet; 132 } 134 135 136 142 public void addPortlet(int theJahiaEventObjectID, int theJahiaEventPageID, String theJahiaEventUserName, String uRLtoTemplatesDir) { 143 try { 144 String theFile = theJahiaEventUserName + ".xml"; 145 String theDefaultFile = theDefaultUser + ".xml"; 146 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, theJahiaEventPageID); 147 XMLFile.addPortlet(theJahiaEventObjectID); 148 } catch (JahiaException e) { 149 JahiaConsole.println( "PortletsBean -> addPortlet", e.toString() ); 150 } 151 } 153 154 160 public void setPortlet(PortletObj thePortlet, int thePageID, String theUserName, String uRLtoTemplatesDir) { 161 try { 162 String theFile = theUserName + ".xml"; 163 String theDefaultFile = theDefaultUser + ".xml"; 164 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 165 XMLFile.updatePortlet(thePortlet); 166 } catch (JahiaException e) { 167 JahiaConsole.println( "PortletsBean -> setPortlet", e.toString() ); 168 } 169 } 171 172 178 public void delPortlet(int theJahiaEventObjectID, int theJahiaEventPageID, String theJahiaEventUserName, String uRLtoTemplatesDir) { 179 try { 180 String theFile = theJahiaEventUserName + ".xml"; 181 String theDefaultFile = theDefaultUser + ".xml"; 182 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, theJahiaEventPageID); 183 XMLFile.deletePortlet(theJahiaEventObjectID); 184 } catch (JahiaException e) { 185 JahiaConsole.println( "PortletsBean -> addPortlet", e.toString() ); 186 } 187 } 189 190 196 public void addPortletGroup(int theJahiaEventObjectID, String theJahiaEventUserName, String uRLtoTemplatesDir) { 197 try { 198 String theFile = theJahiaEventUserName + ".xml"; 199 String theDefaultFile = theDefaultUser + ".xml"; 200 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, theJahiaEventObjectID); 201 XMLFile.addPortletGroup(); 202 } catch (JahiaException e) { 203 JahiaConsole.println( "PortletsBean -> addPortletGroup", e.toString() ); 204 } 205 } 207 208 214 public int getPortletsColumnCount(int thePageID, String theUserName, String uRLtoTemplatesDir) { 215 try { 216 String theFile = theUserName + ".xml"; 217 String theDefaultFile = theDefaultUser + ".xml"; 218 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 219 theColumnCount = XMLFile.getColumnCount(); 220 } catch (JahiaException e) { 221 JahiaConsole.println( "PortletsBean -> getPortletsColumnCount", e.toString() ); 222 } 223 return theColumnCount; 224 } 226 227 233 public void movePortletRight(int thePortletID, int thePageID, String theUserName, String uRLtoTemplatesDir) { 234 try { 235 String theFile = theUserName + ".xml"; 236 String theDefaultFile = theDefaultUser + ".xml"; 237 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 238 XMLFile.moveRightPortlet(thePortletID); 239 } catch (JahiaException e) { 240 JahiaConsole.println( "PortletsBean -> moveXMLPortletRight", e.toString() ); 241 } 242 } 244 245 251 public void movePortletLeft(int thePortletID, int thePageID, String theUserName, String uRLtoTemplatesDir) { 252 try { 253 String theFile = theUserName + ".xml"; 254 String theDefaultFile = theDefaultUser + ".xml"; 255 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 256 XMLFile.moveLeftPortlet(thePortletID); 257 } catch (JahiaException e) { 258 JahiaConsole.println( "PortletsBean -> moveXMLPortletLeft", e.toString() ); 259 } 260 } 262 263 269 public void movePortletBottom(int thePortletID, int thePageID, String theUserName, String uRLtoTemplatesDir) { 270 try { 271 String theFile = theUserName + ".xml"; 272 String theDefaultFile = theDefaultUser + ".xml"; 273 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 274 XMLFile.moveBottomPortlet(thePortletID); 275 } catch (JahiaException e) { 276 JahiaConsole.println( "PortletsBean -> moveXMLPortletBottom", e.toString() ); 277 } 278 } 280 281 287 public void movePortletTop(int thePortletID, int thePageID, String theUserName, String uRLtoTemplatesDir) { 288 try { 289 String theFile = theUserName + ".xml"; 290 String theDefaultFile = theDefaultUser + ".xml"; 291 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 292 XMLFile.moveTopPortlet(thePortletID); 293 } catch (JahiaException e) { 294 JahiaConsole.println( "PortletsBean -> moveXMLPortletTop", e.toString() ); 295 } 296 } 298 299 305 public void copyPortletGroup(int thePageID, String theUserName, String uRLtoTemplatesDir) { 306 try { 307 String theFile = theUserName + ".xml"; 308 String theDefaultFile = theDefaultUser + ".xml"; 309 XMLPortlets XMLFile = new XMLPortlets(uRLtoTemplatesDir, theFile, theDefaultFile, thePageID); 310 311 File portletsAPIPathDir = new File ( uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator ); 312 File [] portletsAPIFileList = portletsAPIPathDir.listFiles(); 313 314 Vector sourceIDList = XMLFile.copyXMLPortletGroup(uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator + theDefaultFile); 315 for(int i=0; i<portletsAPIFileList.length; i++) { 316 if (!portletsAPIFileList[i].getAbsolutePath().equals(uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator + theFile) && !portletsAPIFileList[i].getAbsolutePath().equals(uRLtoTemplatesDir + File.separator + "portlets_api" + File.separator + theDefaultFile)) { 317 XMLFile.copyXMLPortletGroup(portletsAPIFileList[i].getAbsolutePath()); 318 } 319 } 320 unassignRightsToPortlets (sourceIDList); 321 322 } catch (JahiaException e) { 323 JahiaConsole.println( "PortletsBean -> copyPortletGroup", e.toString() ); 324 } 325 } 327 328 334 public SkinObj loadSkin(String theType, int theID) { 335 try { 336 PortletsDBManager DB = PortletsDBManager.getInstance(); 337 if (theType.equals("portlet")) { 338 theSkin = DB.load_portlet_skin(theID); 339 } else if (theType.equals("desktop")) { 340 theSkin = DB.load_desktop_skin(theID); 341 } 342 if (theSkin == null) { 343 theSkin = new SkinObj(1,"",""); 344 } 345 } catch (JahiaException e) { 346 theSkin = new SkinObj(1,"",""); 347 JahiaConsole.println( "PortletsBean -> loadSkin", e.toString() ); 348 } 349 return theSkin; 350 } 352 353 359 public void consoleOutput(String theFirst, String theSecond) { 360 JahiaConsole.println( theFirst, theSecond ); 361 } 363 364 365 private void unassignRightsToPortlets (Vector ctnids) { 367 368 String adminGroupName = 370 JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME; 371 372 JahiaGroup adminGroup = ServicesRegistry.getInstance(). 374 getJahiaGroupManagerService (). 375 lookupGroup (JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME); 376 377 JahiaGroup usersGroup = ServicesRegistry.getInstance(). 379 getJahiaGroupManagerService (). 380 lookupGroup (JahiaGroupManagerService.USERS_GROUPNAME); 381 382 JahiaGroup guestGroup = ServicesRegistry.getInstance(). 384 getJahiaGroupManagerService (). 385 lookupGroup (JahiaGroupManagerService.GUEST_GROUPNAME); 386 387 388 if (adminGroup == null) { 391 return; 392 } 393 394 395 for (int index = 0; index < ctnids.size(); index++) { 397 try { 398 int ctnid = ((Integer )ctnids.get (index)).intValue(); 400 401 JahiaContainer container = ServicesRegistry.getInstance(). 403 getJahiaContainersService().loadContainerInfo (ctnid); 404 405 if (container != null) { 406 408 try { 409 JahiaBaseACL acl = new JahiaBaseACL (container.getAclID()); 410 if (acl != null) { 411 412 416 Vector usernames = acl.getUsernameList (null); 418 if (usernames.size() > 0) { 419 for (int i=0; i<usernames.size(); i++) { 420 String username = (String )usernames.get(i); 421 JahiaUser user = ServicesRegistry. 422 getInstance(). 423 getJahiaUserManagerService(). 424 lookupUser (container.getSiteID(),username); 426 if ((user != null) && 427 (!user.isMemberOfGroup (container.getSiteID(),adminGroupName))) 428 { 429 acl.removeUserEntry (user); 430 } 431 } 432 } 433 434 JahiaACLEntry entry = new JahiaACLEntry (0, 0); 436 entry.setPermission (JahiaBaseACL.READ_RIGHTS, JahiaACLEntry.ACL_YES); 437 438 acl.setGroupEntry (usersGroup, entry); 439 acl.setGroupEntry (guestGroup, entry); 440 441 JahiaACLEntry adminEntry = new JahiaACLEntry (); 443 for (int i=0; i<acl.size(); i++) { 444 adminEntry.setPermission (i, JahiaACLEntry.ACL_YES); 445 } 446 447 acl.setGroupEntry (adminGroup, adminEntry); 448 } 449 } 450 catch (ACLNotFoundException ex) { 451 } 453 } 454 455 } 456 catch (JahiaException ex) { 457 } 459 } 460 } 461 462 } 463 | Popular Tags |