📄 addcontainer_engine.java
字号:
{ aField = (JahiaField) fList.nextElement(); /* aField = ServicesRegistry.getInstance(). getJahiaFieldService().loadField( aField.getID(), LoadFlags.ALL, jParams ); */ JahiaFieldDefinition theDef = aField.getDefinition(); if ( theDef != null ){ JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","Create new acl"); // create the ACL object... JahiaBaseACL newAcl = null; newAcl = new JahiaBaseACL (); newAcl.create(cList.getAclID()); cList.setProperty("view_field_acl_"+theDef.getName(), String.valueOf(newAcl.getID()) ); } } ServicesRegistry.getInstance(). getJahiaContainersService().saveContainerListInfo(cList, jParams.getPage().getAclID() ); // set again session vars HashMap ctnListFieldAcls = getCtnListFieldAclMap(theContainer,jParams); aclsMap = ctnListFieldAcls; engineMap.put( "ctnListFieldAcls", ctnListFieldAcls ); engineMap.put( "ctnListVisibleFields", getCtnListVisibleFieldsMap(jParams,theContainer,jParams.getUser(),ctnListFieldAcls) ); } } catch ( Throwable t ){ t.printStackTrace(); } } JahiaBaseACL acl = JahiaEngineTools.getCtnListFieldACL(aclsMap, startFieldID); if ( acl != null ){ try { if ( acl.getPermission(user,JahiaBaseACL.READ_RIGHTS, jParams.getSiteID()) || acl.getPermission(user,JahiaBaseACL.WRITE_RIGHTS, jParams.getSiteID()) || acl.getPermission(user,JahiaBaseACL.ADMIN_RIGHTS, jParams.getSiteID()) ){ //JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","startField is visible"); return startFieldID; } } catch ( Throwable t ){ JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","Exception : " + t.getMessage()); } } Enumeration fields = theContainer.getFields(); JahiaField theField = null; while (fields.hasMoreElements()) { theField = (JahiaField) fields.nextElement(); acl = JahiaEngineTools.getCtnListFieldACL(aclsMap, theField.getID()); if ( acl != null ){ try { if ( acl.getPermission(user,JahiaBaseACL.READ_RIGHTS, jParams.getSiteID()) || acl.getPermission(user,JahiaBaseACL.WRITE_RIGHTS, jParams.getSiteID()) || acl.getPermission(user,JahiaBaseACL.ADMIN_RIGHTS, jParams.getSiteID()) ){ //JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","Visible field is : " + theField.getID()); return theField.getID(); } } catch ( Throwable t ){ JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","Exception : " + t.getMessage()); } } } } else { return startFieldID; } //JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","No visble field at all"); return 0; } //-------------------------------------------------------------------------- /** * return a vector of neighbour simple fields for the requested field. * * @param JahiaContainer the current container * @param int fieldID * @param boolean doIncludeRequestedField, if true, add the requested field in the vector too. * @param HashMap visibleFields, where the keys are the id of visible fields. * @return Vector fieldIDs, a vector of simple field ids * @author Khue Nguyen */ static public Vector getNeighbourSimpleFields( JahiaContainer theContainer, int fieldID, boolean doIncludeRequestedField, HashMap visibleFields ){ boolean visible = false; Vector v = new Vector(); if ( visibleFields == null ) return v; boolean requestedFieldReached = false; Enumeration fields = theContainer.getFields(); JahiaField theField = null; JahiaBaseACL acl = null; while (fields.hasMoreElements()) { visible = false; theField = (JahiaField) fields.nextElement(); if ( theField != null ) { visible = ( visibleFields.get(new Integer(theField.getID())) != null ); if ( visible ) { if ( theField instanceof JahiaSimpleField ){ if ( doIncludeRequestedField ){ v.add(new Integer(theField.getID())); } else if ( theField.getID() != fieldID ) { v.add(new Integer(theField.getID())); } } else if ( !requestedFieldReached ){ v = new Vector(); // reset the fields group } else { return v; } if ( !requestedFieldReached ){ requestedFieldReached = ( theField.getID() == fieldID ); if ( requestedFieldReached && !(theField instanceof JahiaSimpleField) ){ return new Vector(); } } } } } return v; } //-------------------------------------------------------------------------- /** * Build a map that contains a pair of [fieldID (INTEGER),aclID (INTEGER)] for fields * of a given container list. The acl is the one set at container list level , not at field level !!! * * @param JahiaContainer ctn * @param ParamBean jParams * @return HashMap the map containing the list of editable fields * @author Khue Nguyen */ static public HashMap getCtnListFieldAclMap(JahiaContainer theContainer, ParamBean jParams){ JahiaConsole.println(CLASS_NAME+".getCtnListFieldAclMap","Started for container [" + theContainer.getID() + "]"); HashMap map = new HashMap(); if ( theContainer == null) return map; if (theContainer.getListID() == 0) { return map; } JahiaContainerList cList = null; try { cList = ServicesRegistry.getInstance(). getJahiaContainersService().loadContainerListInfo( theContainer.getListID() ); if ( cList == null ) return map; String prop = null; JahiaField aField = null; JahiaFieldDefinition theDef = null; Enumeration fList = theContainer.getFields(); while (fList.hasMoreElements()) { aField = (JahiaField) fList.nextElement(); if ( aField != null ) { JahiaConsole.println(CLASS_NAME+".getCtnListFieldAclMap","Field [" + aField.getID() + "]"); /* aField = ServicesRegistry.getInstance(). getJahiaFieldService().loadField( aField.getID(), LoadFlags.ALL, jParams ); */ JahiaConsole.println(CLASS_NAME+".getCtnListFieldAclMap","Field [" + aField.getID() + "]"); theDef = aField.getDefinition(); if ( theDef != null ){ prop = cList.getProperty("view_field_acl_"+theDef.getName()); if ( prop != null ){ JahiaConsole.println(CLASS_NAME+".getCtnListFieldAclMap","ACL found = "+ prop); try { int aclID = Integer.parseInt(prop); map.put(new Integer(aField.getID()),new Integer(aclID)); //JahiaConsole.println(CLASS_NAME+".getCtnListFieldAclMap","ACL added"); } catch ( Throwable t ){ JahiaConsole.println(CLASS_NAME+".getCtnListFieldAclMap()", " requested acl ( view_field_acl_" + theDef.getName() + "), exception :" + t.getMessage()); } } else { // create the acl, because field declaration can change in template JahiaBaseACL newAcl = null; newAcl = new JahiaBaseACL (); newAcl.create(cList.getAclID()); cList.setProperty("view_field_acl_"+theDef.getName(), String.valueOf(newAcl.getID()) ); ServicesRegistry.getInstance(). getJahiaContainersService().saveContainerListInfo(cList, jParams.getPage().getAclID() ); map.put(new Integer(aField.getID()), new Integer(newAcl.getID())); } } } } } catch ( Throwable t ){ t.printStackTrace(); } return map; } //-------------------------------------------------------------------------- /** * Build a map which keys are field def ids of the container list fields, if they * are visible ( READ or WRITE or ADMIN RIGHT of the acl return true ). * Note : if the container's list id is 0 ( that is, the list is not created yet, then returned map contains all fields ). * @param JahiaContainer ctn * @param JahiaUser the user to check access * @param HashMap aclsMap, the key is the fieldID and the value is the aclID.This map should be the one returned by getCtnListFieldAclMap. * @return HashMap the map containing the list of visible fields * @author Khue Nguyen */ static public HashMap getCtnListVisibleFieldsMap( ParamBean jParams, JahiaContainer theContainer, JahiaUser user, HashMap aclsMap ){ JahiaConsole.println(CLASS_NAME+".getCtnListVisibleFieldsMap","Started for container [" + theContainer.getID() + "]"); HashMap map = new HashMap(); if ( theContainer == null) return map; boolean cListExist = (theContainer.getListID() != 0); Enumeration fields = theContainer.getFields(); JahiaBaseACL acl = null; JahiaField aField = null; while ( fields.hasMoreElements() ){ aField = (JahiaField)fields.nextElement(); if ( aField != null ){ if ( !cListExist ){ map.put(new Integer(aField.getID()),new Integer(aField.getID())); } else { acl = JahiaEngineTools.getCtnListFieldACL(aclsMap, aField.getID()); if ( acl != null ){ try { if ( acl.getPermission(user,JahiaBaseACL.READ_RIGHTS, jParams.getSiteID()) || acl.getPermission(user,JahiaBaseACL.WRITE_RIGHTS, jParams.getSiteID()) || acl.getPermission(user,JahiaBaseACL.ADMIN_RIGHTS, jParams.getSiteID()) ){ map.put(new Integer(aField.getID()),new Integer(aField.getID())); } } catch ( Throwable t ){ JahiaConsole.println(CLASS_NAME+".getCtnListVisibleFieldsMap","Exception : " + t.getMessage()); } } } } } return map; } //------------------------------------------------------------------------- private synchronized void toDebug (String message) { if (true) { JahiaConsole.println(CLASS_NAME,message); } }} // end AddContainer_Engine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -