1

I'm looking for a method to get a list of filenames of all properties files in an application using java.

The target is to dynamically build the content for a language selection dropdown.

1
  • you should add JSF tag to this question, I think it is more JSF related question Nov 21, 2012 at 15:52

1 Answer 1

4

This class provides the method getPropertFileList() which returns all property files (language resource files) in the current database as a java..util.Vector

package ch.hasselba.xpages;

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 EMPTY_STRING = "";
    private final String FLAG_PROPERTY = "gC~4K2P";
    private final String FIELD_$FLAGS = "$Flags";
    private final String FIELD_TITLE = "$TITLE";

    /**
     * returns Vector containing all property files 
     * of a database
     * 
     * No error handling included!
     * 
     * @category Domino
     * @author Sven Hasselbach
     * @category Tools
     * @version 0.1
     */
    public Vector getPropertFileList() {

        FacesContext fc = FacesContext.getCurrentInstance();

        Vector data = new Vector();
        try {

            // get DB
            Database db = (Database) fc.getApplication().getVariableResolver()
                    .resolveVariable(fc, "database");

            // get all design docs
            NoteCollection nc = db.createNoteCollection(false);
            nc.selectAllDesignElements(true);
            nc.buildCollection();

            // process all notes 
            String noteId = "";
            noteId = nc.getFirstNoteID();

            Document doc = null;
            // 
            while (!(EMPTY_STRING.equals(noteId))) {

                // get design doc
                doc = db.getDocumentByID(noteId);

                // check if its a property file
                if (FLAG_PROPERTY.equals(doc.getItemValueString(FIELD_$FLAGS))) {
                    // add to Vector
                    data.add(doc.getItemValueString(FIELD_TITLE));
                }

                // next one
                noteId = nc.getNextNoteID(noteId);

                // recycle doc
                recycleObject( doc );
            }

        } catch (NotesException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return data;

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

To use it in a XPage just call it like this:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

   <xp:comboBox id="comboBox1">
      <xp:selectItems>
         <xp:this.value>
            <![CDATA[#{javascript:
               importPackage(ch.hasselba.xpages);
               DesignElements().getPropertFileList()
            }]]>
         </xp:this.value>
      </xp:selectItems>
   </xp:comboBox>
</xp:view>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.