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

📄 searchmodel.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		}
		else if (filter.startsWith("|"))
		{
			buffy.append("(|");				//TE: append '(|'.
			count++;
			filter = filter.substring(1);	//TE: remove | from beginning of filter.
		}		

		ArrayList list = getJoinFilterNames(filter);						//TE: get the filter names in this filter.

		String[] names = (String[])list.toArray(new String[list.size()]);	//TE: convert the list array to a string array.

        for (int i=0; i<names.length; i++)
        {	 
			String name = names[i];
			getValue(buffy, name);			//TE: get the filter value for each subfilter e.g, (cn=f*).
        }

		for(int i=0; i<count; i++)
			buffy.append(")");				//TE: append ')'.
    }

   /**
    *	If a filter value is raw e.g. (cn=f*) this method appends the value to the string buffer other wise
	*	it calls the getOperator() method again in a recursive manner until the raw filter is reached.
	*	@param buffy the string buffer which is used to append the filter parts.
	*	@param filter e.g. 'JXFilter.myFilter1'.
	*/
    protected void getValue(StringBuffer buffy, String filter)
    {     
		ArrayList list = getFilterNames(BUILDFILTER);
	  
        if (list.contains(filter))   //TE: if the filter is raw e.g. (cn=f*) append it to the buffer otherwise iterate the process.
        {
            buffy.append(getFilter(filter));
        }
		else 
		{			
			getOperator(buffy, getFilter(filter)); 			
		}				
    }	

   /**
    *	Returns true if the property file (search_filter.txt) contains the supplied
	*	filter.
	*	@param name the name of the filter for example, 'myfilter'.  The method provides the filter
	*	name prefix 'JXFilter.'.
	*	@return true if the property file contains the filter, false otherwise.
	*/
	protected boolean exists(String name)
	{
		if(properties.containsKey(NAME+name))	//TE: check if the filter (JXFilter.blah) name already exists, if so return true.
			return true;
		else if(properties.containsKey(TEXTNAME+name))	//TE: check if the filter (JXTextFilter.blah) name already exists, if so return true.
			return true;					
		
		return false;
	}

   /**
    *	Returns true if the given filter is a text filter by checking the property
	*	file for 'JXTextFilter+name'.  
	*	@param name the name of the filter without the 'JXTextFilter' prefix.
	*	@return true if the filter is a text filter, false otherwise.
	*/
	protected boolean isTextFilter(String name)
	{
		if(properties.containsKey(TEXTNAME+name))
			return true;
			
		return false;		
	}

   /**
    *	Saves a filter to the property file 'search_filter.txt'.  The name of the filter is added to the filter name prefix
	*	'JXFilter.' e.g. 'JXFilter.myFilter1'.  Saves either a raw filter e.g. 'JXFilter.myFilter1=(cn=f*)' or a combination of
	*	filters e.g.'JXFilter.myFilter1=&JXFilter.myFilter2JXFilter.myFilter3'
	*	@param name the name of the filter e.g. 'myFilter'.  The filter name prefix is added to this before saving.
	*		The saved name should look like: 'JXFilter.myFilter".
	*	@param filter the value that is being saved e.g. (cn=f*) or '&JXFilter.myFilter2JXFilter.myFilter3'.
	*/
	protected void saveFilter(String name, String filter)
	{			
		properties.setProperty(NAME+name, filter);
		CBUtility.writePropertyFile(searchFilterConfig, properties, "");
	}

   /**
    *	Saves a text filter to the property file 'search_filter.txt'.  The name of the filter is added to the filter name prefix
	*	'JXTextFilter.' e.g. 'JXFilter.myFilter1=(cn=f*)'.
	*	@param name the name of the filter e.g. 'myFilter'.  The filter name prefix is added to this before saving.
	*		The saved name should look like: 'JXTextFilter.myFilter".
	*	@param filter the value that is being saved e.g. (cn=f*).
	*/
	protected void saveTextFilter(String name, String filter)
	{
		properties.setProperty(TEXTNAME+name, filter);
		CBUtility.writePropertyFile(searchFilterConfig, properties, "");
	}

   /**
    *	Saves the given value to the property file with the name of the filter
	*	and the type of item as the key (e.g. name.baseDN=whatever).
	*	@param name the name of the filter (without the JXFilter prefix).
	*	@param type of value being saved (baseDN, retAttrs).
	*	@param value
	*/
	protected void saveValue(String name, String type, String value)
	{
		properties.setProperty(name+"."+type, value);
		CBUtility.writePropertyFile(searchFilterConfig, properties, "");
	}

   /**
    *	Saves the search level to the property file ('search_filters.txt') as name.searchLevel.
	*	@param name the name of the filter (without the JXFilter prefix).
	*	@param searchLevel the search level that the user wants saved with the filter.
	*/
	protected void saveSearchLevel(String name, int searchLevel)
	{
		properties.setProperty(name+"."+SEARCHLEVEL, Integer.toString(searchLevel));
		CBUtility.writePropertyFile(searchFilterConfig, properties, "");
	}
	
   /**
    *	Saves the search level to the property file ('search_filters.txt') as name.searchLevel.
	*	@param name the name of the filter (without the JXFilter prefix).
	*	@param aliasType the type of alias handling ('finding' etc.).
	*/
	protected void saveAlias(String name, String aliasType, boolean state)
	{
		if(state)
			properties.setProperty(name+"."+aliasType, "true");
		else
			properties.setProperty(name+"."+aliasType, "false");
				
		CBUtility.writePropertyFile(searchFilterConfig, properties, "");
	}	
	
   /**
    *	Returns the value associated with the key from the property file.
	*	This does a pure look up regardless of filter prefixes like JXFilter.
	*	@param key the key which we want the value returned (this is the actual
	*		key that we will use to look in the property file i.e. no modification
	*		is done to it.
	*	@return the value that the key stores (null if not present).
	*/
	public String getValue(String key)
	{
		if(properties.containsKey(key))
			return properties.getProperty(key);
		
		return null;	
	}			

   /**
    *	Checks if the property file contains the value.  If it does it gets the
	*	key for that value and checks if the key contains 'retAttrs'.  If it does
	*	the entry is removed from the property file.
	*	@param value the value that we are looking in the property file for in order to delete its entry.
	*/
	protected void removeRetAttrs(String value)
	{
		if(properties.containsValue(value))
		{
			Enumeration en = properties.propertyNames();
			while (en.hasMoreElements())
			{
				String temp = (en.nextElement()).toString();
				if (temp.indexOf(RETATTRS)>-1)		
				{
					if(((properties.get(temp)).toString()).equalsIgnoreCase(value))
						properties.remove(temp);
				}					
			}		

			CBUtility.writePropertyFile(searchFilterConfig, properties, "");
		}
	}

   /**	
    *	Removes an array of filters from the property file search_filters.txt.
	*	@param filterNames the array of filters names (keys) to be removed (deleted).
	*/
	protected void removeFilters(String[] filterNames)
	{
		for(int i=0;i<filterNames.length;i++)
		{
			removeFilter(filterNames[i]);			
		}	
	}

   /**	
    *	Removes a filter from the property file search_filters.txt.
	*	@param filterName the filter name (key) to be removed (deleted).  Expects the filter prefix.
	*/
	protected void removeFilter(String filterName)
	{
		properties.remove(filterName);

		String name = filterName.startsWith(NAME)? filterName.substring(9) : filterName.substring(13);

		Enumeration en = properties.propertyNames();
		while (en.hasMoreElements())
		{
			String temp = (en.nextElement()).toString();
			if(temp.startsWith(name))
				properties.remove(temp);
		}
		
		CBUtility.writePropertyFile(searchFilterConfig, properties, "");
	}

   /**
    *	Returns an Array List of filters that depend on the filter that the user is trying to delete,
	*	and any filters that depend on those filters and so on.
	*	@param filterName the name of the filter that the user wants to delete.
	*	@return the list of all dependand filters (filters that use this filter directly or indirectly).
	*/
	protected ArrayList getDependants(Object filterName)
	{
		dependantFilters.clear();							//TE: clear the global Array Lists.
		tempList.clear();
		
		if (!dependantFilters.contains(filterName))			//TE: make sure the filter being deleted is added to the list.
			dependantFilters.add(NAME+filterName);
		getDependantFilters(NAME+filterName);
		
		return dependantFilters;
	}
	
   /**
    *	This method tries to determine if there are any filters that use the filter that is supplied
	*	as a parameter.  The filters are constructed in a way that any one filter can be used by any
	*	other filters to make new filters.  Therefore deleting a filter can have a cascading effect of
	*	rendering other filters useless.  
	*	<p>
	*	This method searches all of the values from the property file 'search_filter.txt', to see if any
	*	contain the filter name.  If so the name of that filter (or the key) is saved in an Array List. 
	*	The process is repeated for each one of these saved keys.</p>
	*	<p>
	*	NOTE: Text filters don't have dependant filters.	
	*	@param filterName the name of the filter that is being checked for dependant filters.
	*/
	protected void getDependantFilters(Object filterName)
	{																	//TE: key=value.
		Collection col = properties.values();							//TE: get all the values from the property file.
		Object[] allValues = col.toArray();								//TE: make them usable.
		
		for(int i=0;i<allValues.length;i++)
		{
			if (allValues[i].toString().indexOf(filterName.toString())>-1)
			{
				String temp = getKeyForValue(allValues[i].toString());	//TE: get the key for the value.
				
				if (!temp.equalsIgnoreCase(""))
				{
					if (!dependantFilters.contains(temp))				//TE: add this to the list of filters that need to be deleted. && !dependantFilters.contains(temp))					//TE: add this to the list of filters that need to be deleted.
					{
						dependantFilters.add(temp);
						tempList.add(temp);
						getDependantFilters(temp); 						//TE: check this filter for any dependant filters.	
					}
				}							
			}
		}
	}
	
   /**
    *	Gets an enumeration of keys from the property list where the search filters are stored,
	*	then puts these keys into a string array.  It then extracts the value of each of these keys
	*	from the property file until it finds one that matches the supplied value.  In short, this
	*	method returns the key of the value supplied.
	*	@param value the value whose key we want returned.
	*	@return the key of the supplied value (returns and empty string if no key is found).
	*/
	protected String getKeyForValue(String value)
	{
		String[] allKeys = new String[properties.size()];
		Enumeration en = properties.propertyNames();
		int counter =0;
		
		while (en.hasMoreElements())
		{
			allKeys[counter]= (en.nextElement()).toString();	//TE: get all of the values from the enumeration and store them in the string array.
			counter++;
		}		
				
		for(int i=0;i<allKeys.length;i++)
		{
			if(properties.getProperty(allKeys[i]).equalsIgnoreCase(value) && !tempList.contains(allKeys[i]))	//TE: find which key has the supplied value and return it.	
				return allKeys[i];			
		}
			
		return "";			
	}

   /**
    *	This Comparator compares two case ignore Strings.
	*	@author Trudi.
    */
    public static class StringComparator implements Comparator
    {     
       /**
        *   This Comparator compares two case ignore Strings.
        *   @param o1 one of the two items to be compared.
        *   @param o2 the other of the items to be compared.
        *   @return the result of the compare (0 if the strings of o1 & o2 are equal, -1 if o1 < o2, 1 if o1 > o2).
		*
        */        
        public int compare(Object o1, Object o2) 
        {
            return ((String)o1).compareToIgnoreCase((String)o2);
        }
    }		
}

⌨️ 快捷键说明

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