您可以通過Java NAPI做到這一點。對於這一點,你必須創建一個新的Java類是這樣的:
package ch.hasselba.xpages.util;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Properties;
import com.ibm.designer.domino.napi.NotesAPIException;
import com.ibm.designer.domino.napi.NotesDatabase;
import com.ibm.designer.domino.napi.NotesNote;
import com.ibm.designer.domino.napi.NotesSession;
import com.ibm.designer.domino.napi.design.FileAccess;
public class Toolbox {
/**
* loads the properties from a file
*
* @param dbPath full path of the database
* @param fileName name of the file to load
* @return the properties object
*/
public Properties loadProperties(final String dbPath, final String fileName) {
try {
// load the file
InputStream inStream = getFile(dbPath, fileName);
// if file exists, init a properties object
if (inStream != null) {
Properties props = new Properties();
props.load(inStream);
return props;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* saves a property file to a database
*
* @author Sven Hasselbach
*
* @param dbPath full path of the database
* @param fileName name of the file to load
* @param props the properties object
*/
public void saveProperties(final String dbPath, final String fileName, final Properties props) {
try {
// init Notes objects
NotesSession nSession = new NotesSession();
NotesDatabase nDB = nSession.getDatabaseByPath(dbPath);
nDB.open();
// store properties in byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
props.store(bos, "My XSP Properties");
// save the property file
NotesNote nFile = FileAccess.getFileByPath(nDB, fileName);
FileAccess.saveData(nFile, fileName, bos.toByteArray());
// recycle the objects
nFile.recycle();
nDB.recycle();
nSession.recycle();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* loads a property file from a database
*
* @author Sven Hasselbach
* @param dbPath full path of the database
* @param fileName name of the file to load
* @return InputStream content of the file
*/
private InputStream getFile(final String dbPath, final String fileName) {
try {
// init Notes objects
NotesSession nSession = new NotesSession();
NotesDatabase nDB = nSession.getDatabaseByPath(dbPath);
nDB.open();
// get the file
NotesNote nNote = FileAccess.getFileByPath(nDB, fileName);
InputStream inStream = FileAccess.readFileContentAsInputStream(nNote);
// recycle the objects
nNote.recycle();
nDB.recycle();
nSession.recycle();
return inStream;
} catch (NotesAPIException apiEx) {
apiEx.printStackTrace();
}
return null;
}
}
要編譯這個類,你必須lwpd.domino.napi.jar添加JAR 到構建路徑。
現在你可以這樣創建一個按鈕:
<xp:button
value="Add property"
id="button1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action>
<![CDATA[#{javascript:
importPackage(ch.hasselba.xpages.util);
var toolbox:ch.hasselba.xpages.utils.Toolbox = new Toolbox();
var props:java.util.Properties = toolbox.loadProperties(database.getFilePath(), "WEB-INF/xsp.properties");
props.put("Test", "123");
toolbox.saveProperties(database.getFilePath(), "WEB-INF/xsp.properties", props);
}]]>
</xp:this.action>
</xp:eventHandler>
</xp:button>
這看起來應該起作用。我仍在努力讓設計元素的複製能夠正常工作(非常接近)。我有一個安裝過程,根據用戶正在執行的安裝類型,將特定設計元素複製到目標數據庫(可能已經存在或可能是新的)。我有這部分過程很好地工作,如果我去新的數據庫並手動設置屬性它能正常工作,但我想檢查,看看是否設置了特定的屬性,如果沒有設置它們。 –