Java browser: SearchPreferences.java

Content of SearchPreferences.java extracted from search.jar

/*
IMPORTANT NOTICE, please read:
 
This software is licensed under the terms of the GNU GENERAL PUBLIC LICENSE,
please read the enclosed file license.txt or http://www.gnu.org/licenses/licenses.html
 
Note that this software is freeware and it is not designed, licensed or intended
for use in mission critical, life support and military purposes.
 
The use of this software is at the risk of the user.
*/
 
/* 
 
class SearchPreferences provides the preferences of the search
 
used by Search.java 
 
01-11-2006 version 0.1.1: added methods readXML() and writeXML()
 
*/
 
package search;
 
import java.util.*;
import java.io.*;
 
interface Match {
	public boolean matchFile(File f);
}
 
public class SearchPreferences {  
	static final String preferencesFile = "search.xml";
	String searchStr;
	String dir;
	boolean caseSensitive;
	boolean searchSubfolders;
	String pattern;
	Match match;
 
// empty constructor
	public SearchPreferences () {  
	}
 
// readXML()
// read preferences from default file, as defined in preferencesFile
// note that default values will be used if IO failure occurs
	public SearchPreferences readXML() {  
		InputStream is;
		try	{
			is = new FileInputStream(new File(preferencesFile));
		}	catch (IOException ex) { is = null;}
		return readXML(is);
	}
 
// readXML(InputStream is)
// note that default values will be used if IO failure occurs
	public SearchPreferences readXML(InputStream is) {  
		Properties props=new Properties();
		if (is != null)
		try	{
			props.loadFromXML(is);
		}	catch (IOException ex) {	}
		searchStr=props.getProperty("searchStr","string");
		dir=props.getProperty("dir",".");
		caseSensitive=Boolean.valueOf(props.getProperty("caseSensitive","false"));
		searchSubfolders=Boolean.valueOf(props.getProperty("searchSubfolders","true"));
		pattern=props.getProperty("pattern","*.java");
		return this;
	}
 
// writeXML()
	public void writeXML() throws FileNotFoundException, IOException {  
		writeXML(new FileOutputStream(new File(preferencesFile)));
	}
 
// writeXML(OutputStream os)
	public void writeXML(OutputStream os) throws FileNotFoundException, IOException {  
			Properties props=new Properties();
			props.setProperty("searchStr",searchStr);
			props.setProperty("dir",dir);
			props.setProperty("caseSensitive",String.valueOf(caseSensitive));
			props.setProperty("searchSubfolders",String.valueOf(searchSubfolders));
			props.setProperty("pattern",String.valueOf(pattern));
			props.storeToXML(os,"generated by Search");
	}
 
};
Condividi: Share Share on Facebook Bookmark on OkNo Share on Twitter Bookmark on Google Bookmark on del.icio.us Bookmark on digg.com Bookmark on Segnalo Bookmark on Reddit
Privacy Creative Commons Attribution-Share Alike Trovami