get a list of available .properties / .theme files in an application


package de.eknori.nsf;

import java.util.Vector;
import javax.faces.context.FacesContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.NoteCollection;
import lotus.domino.NotesException;

public class DesignElements {

	private final String SUFFIX_PROPERTY = ".lang.properties";
	private final String SUFFIX_THEME = ".theme";
	private final String FLAG_PROPERTY = "345CgQ";
	private final String FLAG_THEME = "34567Cg~`";
	
	private final String EMPTY_STRING = "";
	private final String FIELD_$FLAGS = "$Flags";
	private final String FIELD_TITLE = "$TITLE";

	private String elementFlag;
	private String elementSuffix;
	private boolean noSuffix = true;
	private boolean toUpper = true;
	
	/**
	 * removes the suffix from a design element
	 * 
	 * @see SUFFIX_PROPERTY, SUFFIX_THEME
	 * 
	 * @param  stripSuffix
	 * @author Ulrich Krause
	 * @version 1.0
	 */	
	public void setRemoveSuffix(boolean stripSuffix) {
		this.noSuffix = stripSuffix;
	}	

	/**
	 * converts the output to uppercase 
	 * 
	 * @param  toUpper
	 * @author Ulrich Krause
	 * @version 1.0
	 */	
	public void setConvertToUpper(boolean toUpper) {
		this.toUpper = toUpper;
	}

	/**
	 * get DesignElementFlag 
	 * 
	 * @author Ulrich Krause
	 * @version 1.0
	 */	
	public String getDesignElementFlag() {
		return elementFlag;
	}

	/**
	 * set DesignElementFlag 
	 * 
	 * @param flag 
	 * @author Ulrich Krause
	 * @version 1.0
	 */	
	public void setDesignElementFlag(String flag) {
		elementFlag = flag;
	}

	/**
	 * get DesignElementSuffix
	 * 
	 * @author Ulrich Krause
	 * @version 1.0
	 */	
	public String getDesignElementSuffix() {
		return elementSuffix;
	}

	/**
	 * set DesignElementSuffix
	 * 
	 * @param suffix
	 * @author Ulrich Krause
	 * @version 1.0
	 */	
	public void setDesignElementSuffix(String suffix) {
		elementSuffix = suffix;
	}

	/**
	 * returns Vector containing a list of specific design elements
	 * 
	 * @author Ulrich Krause
	 * @author Sven Hasselbach
	 * @see http://stackoverflow.com/questions/13495847/how-to-get-a-list-of-all-properties-files-in-an-application
	 * @version 0.2
	 */
	public Vector<String> getDesignElementList() {
		FacesContext fc = FacesContext.getCurrentInstance();

		Vector<String> vec = new Vector<String>();
		try {
			Database db = (Database) fc.getApplication().getVariableResolver()
			.resolveVariable(fc, "database");

			NoteCollection nc = db.createNoteCollection(false);
			nc.setSelectMiscFormatElements(true);
			nc.buildCollection();
			String nid = "";
			String rf = "";
			nid = nc.getFirstNoteID();

			Document doc = null;

			while (!(EMPTY_STRING.equals(nid))) {
				doc = db.getDocumentByID(nid);
				rf = doc.getItemValueString(FIELD_TITLE);
				
				if (this.getDesignElementFlag().equals(
						doc.getItemValueString(FIELD_$FLAGS))) {
					if (rf.contains(this.getDesignElementSuffix())) {
						
						if (this.noSuffix) {
							rf = rf.replace(this.getDesignElementSuffix(), "");		
						} 
						if (this.toUpper) {
							rf = rf.toUpperCase();		
						} 
						vec.add(rf);
					}
				}
				nid = nc.getNextNoteID(nid);
				recycleObject(doc);
			}

		} catch (NotesException e) {
			e.printStackTrace();
		}
		return vec;

	}

	/**
	 * returns Vector containing all property files in a database
	 * 
	 * @author Ulrich Krause
	 * @version 0.2
	 */
	public Vector<String> getPropertyFilesList() {
		this.setDesignElementSuffix(SUFFIX_PROPERTY);
		this.setDesignElementFlag(FLAG_PROPERTY);
		return getDesignElementList();
	}
	
	/**
	 * returns Vector containing all theme files in a database
	 * 
	 * @author Ulrich Krause
	 * @version 0.1
	 */
	public Vector<String> getThemeFilesList() {
		this.setDesignElementSuffix(SUFFIX_THEME);
		this.setDesignElementFlag(FLAG_THEME);
		return getDesignElementList();
	}

	/**
	 * recycles an object instance
	 * 
	 * @param  obj 
	 * @author Sven Hasselbach
	 * @version 1.1
	 */
	public static void recycleObject(lotus.domino.Base obj) {
		if (obj != null) {
			try {
				obj.recycle();
			} catch (Exception e) {
			}
		}
	}

}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...