问题
In the book "XPages Extension Library", Chapter 12, page 409 there is an example of JDBC connection file:
<jdbc>
<driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
<url>jdbc:derby:${rcp.data}\derby\XPagesJDBC;create=true</url>
<user>phil</user>
<password>phil</password>
</jdbc>
It is also mentioned in the text that "notice in previous example the use of the configuration property rcp.data in the computed expression ${rcp.data}. The connection files can take advantage of computed properties in their definitions."
My question is: what exactly are these "computed properties" and how are they used? I would like to store the username and password somewhere else and reference them using something like this:
<user>${SettingsBean.SQLUserName}</user>
<password>${SettingsBean.SQLPassword}</password>
However, I cannot get this to work. Here is what I have tried so far:
- Managed beans
- VariableResolver
- Resource bundle
- writing the connection file directly and through java.util.Properties
1 through 3 work when referenced in an XPage, but not in this file. Number 4 would work, if the connection file were of the "key=value" type. However, java.util.Properties cannot be used with XML files that do not conform to a certain DTD (like this file). And writing the whole file is not supported (under WEB-INF).
EDIT:
Some additional information:
- The bit above is from the XPagesJDBC.nsf (from OpenNTF) and not from the image in page 409. The text on that page seems to refer to this code.
- XPagesJDBC.nsf does not contain the word "rcp.data" elsewhere, at least it does not show up in search.
- The JDBC connection works flawlessly if username is hardcoded.
- The SQL error messages look something like this:
Unknown user: "${SettingsBean.SQLUserName}"
which seems to imply that this connection file is used "as-is".
回答1:
I am guessing the "rcp" is a reference to the Rich Client Platform environment object variable, and perhaps .data is the property that points to the WEB-INF directory.
The documentation definitely is taunting us in places with unexplained remarks like this. I see some similar looking stuffs ( like ${rcp.*} )in the Lotus Expeditor documents http://publib.boulder.ibm.com/infocenter/ledoc/v6r2/index.jsp?topic=/com.ibm.rcp.tools.doc.admin/updatingclientconfigurationsusingmanualupdates.html - check that out. I found this little gem there:
the Lotus Expeditor platform uses the System property rcp.data to identify the location >of the workspace.
File f = new File( System.getProperty( "rcp.data" ) );
As far as I can tell, these variable strings have access to operating system environment variables, and to expeditor property variables. How this stuff got grafted into the domino/XPages system is not yet documented, but many folks in the Expeditor team are now on the XSP team. Here's the clues I could find in the Expeditor docuemntation:
The placeholder ${env.”system environmental variable”} is used to specify the use of a >system environmental variable.
The placeholder ${prop.”rcplauncher_property”} is used to specify the use of a property >from rcplauncher.properties.
So perhaps you could put credentials in rcplauncher.properties and refer to them via ${prop.*} variables.
回答2:
There is a core XPages runtime fix required to remedy this. By core I mean something that cannot be fixed purely in the XPages Extension Library. Thus the fix will only be available in the next full Domino release.
来源:https://stackoverflow.com/questions/16938384/can-jdbc-connection-files-contain-computed-properties