2012-11-21 25 views

回答

4

这个类提供的方法getPropertFileList()这在当前数据库中返回所有的属性文件(语言资源文件)作为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) {} 
     } 
    } 
} 

要在使用它XPage就这样调用它:

<?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> 
相关问题