⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupstools.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  GroupsTools//  NK      21.03.2001////package org.jahia.services.usermanager;import java.util.Vector;import org.apache.regexp.RE;import org.apache.regexp.RESyntaxException;import org.jahia.exceptions.JahiaException;import org.jahia.utils.*;                       	// JahiaConsoleimport org.jahia.services.fields.*;                	// Fields Servicesimport org.jahia.registries.*;                  	// ServicesRegistry/** * Tools class to handle Application Role Groups * * @author NK */public class GroupsTools{	/** 	 * Pattern used to match Application Role Group Name:  	 * 	 *	 * ex: 		 *	 *		In case of Application Role Group Names:	 *		appid + "_" + fieldid + "_" + role name	 *	 *		23_1_administrator : 	 *									app id = 23, 	 * 									field id = 1, 	 *									stored database group name = 23_1_administrator	 *									role name part = administrator 	 *	 **/		/** 	 * Pattern used to match the identifier composed by : appid + "_" + fieldid + "_" + role name	 * in case of groups that are applications' roles	 *	 **/	private static String mRole_GroupName_Pattern 		= "^\\d+_\\d+_[\\w|_]+";		/** 	 * Pattern used to extract the first id part 	 *	 **/	private static String mFirstIDPart 					= "(^\\d+)_.+";	/** 	 * Pattern used to extract the second id part 	 *	 **/	private static String mSecondIDPart 				= "^\\d+_(\\d+)_.+";	/** 	 * Pattern used to extract the human readable role name part	 * in case of Role Group Name : appid + "_" + fieldid + "_" + role name	 **/	private static String mRoleNamePart 				= "^\\d+_\\d+_([\\w|_]+$)";	/** 	 * The RExp used to match the Application Role Group Name Pattern 	 *	 **/	private static org.apache.regexp.RE mRExpRoleGroupName = null;	/** 	 * The RExp used to extract the first id part 	 *	 **/	private static org.apache.regexp.RE mRExpFirstIDPart = null;		/** 	 * The RExp used to extract the second id part 	 *	 **/	private static org.apache.regexp.RE mRExpSecondIDPart = null;	/** 	 * The RExp used to extract the role name part in the Application role group name pattern	 *	 **/	private static org.apache.regexp.RE mRExpRoleNamePart = null;	static {		try{			mRExpRoleGroupName = new RE(mRole_GroupName_Pattern);			mRExpFirstIDPart = new RE(mFirstIDPart);			mRExpSecondIDPart = new RE(mSecondIDPart);			mRExpRoleNamePart = new RE(mRoleNamePart);		} catch ( Throwable t ){			//System.out.println(" Reg Exp Exception " + t.getMessage() );		}	}		//--------------------------------------------------------------------------    /**     * Return the role name part in the Application Role Group Name	 *     * @param 	String Application Role Group Ident     * @return  String The Role Name Part or null if not matching     * @author  NK     */	public static String getRoleNamePart(String appRoleGroupNameIdent){				if ( appRoleGroupNameIdent == null ){			return null;		}		mRExpRoleNamePart.match(appRoleGroupNameIdent);		return mRExpRoleNamePart.getParen(1);			}	//--------------------------------------------------------------------------    /**     * Return the first id part ( = the app id ) in the Application Role Group Name	 *      * @param 	String Application Role Group Ident     * @return  String The First ID part or null if not matching     * @author  NK     */	public static String getAppIDPart(String appRoleGroupNameIdent){				if ( appRoleGroupNameIdent == null ){			return null;		}		mRExpFirstIDPart.match(appRoleGroupNameIdent);		return mRExpFirstIDPart.getParen(1);			}	//--------------------------------------------------------------------------    /**     * Return the second id Part ( = the field id ) in the Application Role Group Name	 *      * @param 	String Application Role Group Ident     * @return  String The Second ID part or null if not matching     * @author  NK     */	public static String getFieldIDPart(String appRoleGroupNameIdent){				if ( appRoleGroupNameIdent == null ){			return null;		}		mRExpSecondIDPart.match(appRoleGroupNameIdent);		return mRExpSecondIDPart.getParen(1);			}	//-------------------------------------------------------------------------	/**	 * Check if a group name is in fact an Application Role	 *	 */	public static boolean isRole(String grpName){				if ( grpName == null ){			return false;		}				return mRExpRoleGroupName.match(grpName);		}	//-------------------------------------------------------------------------	/**	 * Return a vector of Jahia Groups or Application Role Groups	 *	 * @param boolean isRoleGroup if true, return only Application Role Groups	 *				  otherwise return only Jahia Groups			 */	public static Vector getGroups(boolean isRoleGroup){			Vector allGroups = ServicesRegistry.getInstance()										.getJahiaGroupManagerService()										.getGroupList();		if ( allGroups == null ){			return null;		}		Vector reqGroups = new Vector();				int size = allGroups.size();		String grpKey = null;		JahiaGroup grp = null;				for (int i=0 ; i<size ; i++){			grpKey = (String)allGroups.get(i);			grp = ServicesRegistry.getInstance()									.getJahiaGroupManagerService()									.lookupGroup(grpKey);			if ( grp != null ){										if ( isRoleGroup && mRExpRoleGroupName.match(grp.getGroupname()) ){					reqGroups.add(grp);				} else if (	!isRoleGroup && !mRExpRoleGroupName.match(grp.getGroupname()) ){							reqGroups.add(grp);				}									}		}			return reqGroups;		}		//-------------------------------------------------------------------------	/**	 * Return a vector of Jahia Groups or Application Role Groups	 *	 * @param int the site id	 * @param boolean isRoleGroup if true, return only Application Role Groups	 *				  otherwise return only Jahia Groups			 */	public static Vector getGroups( int siteID, boolean isRoleGroup)	throws JahiaException{		//JahiaConsole.println("GroupsTools","started site=" + siteID);			Vector reqGroups = new Vector();				Vector fieldIDs = fieldIDs = ServicesRegistry.getInstance()									.getJahiaFieldService()									.getAllFieldIDs(siteID);		//JahiaConsole.println("GroupsTools","nbfields=" + fieldIDs.size());				if ( fieldIDs == null ){			return reqGroups;		}		int nbFieldIDs = fieldIDs.size();				Vector allGroups = null;		int id = siteID;		if ( isRoleGroup ){			id = 0;		}		allGroups = ServicesRegistry.getInstance()							.getJahiaGroupManagerService()							.getGroupList(id);		//JahiaConsole.println("GroupsTools","all grps=" + allGroups.size());		if ( allGroups == null ){			return reqGroups;		}				int size = allGroups.size();		String grpKey = null;		JahiaGroup grp = null;		int fieldID = 0;		Integer vFieldID = null;				for (int i=0 ; i<size ; i++){			grpKey = (String)allGroups.get(i);			grp = ServicesRegistry.getInstance()									.getJahiaGroupManagerService()									.lookupGroup(grpKey);			if ( grp != null ){										if ( isRoleGroup && mRExpRoleGroupName.match(grp.getGroupname()) ){					//JahiaConsole.println("GroupsTools","all grp=" + grp.getGroupname());										// Need to check on field					try {						fieldID = Integer.parseInt(getFieldIDPart(grp.getGroupname()));												//JahiaConsole.println("GroupsTools","field part=" + fieldID);						for ( int j=0; j<nbFieldIDs ; j++ ){							vFieldID = (Integer)fieldIDs.get(j);							if ( fieldID == vFieldID.intValue() ){								reqGroups.add(grp);							}								}					}catch ( Throwable t ) {						JahiaConsole.println("GroupsTools","exception " + t.getMessage() );					} 				} else if (	!isRoleGroup && !mRExpRoleGroupName.match(grp.getGroupname()) ){							reqGroups.add(grp);				}									}		}			return reqGroups;		}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -