To access XPages resources during runtime and to get their content as a string, you can use the following SSJS code snippet:
<?xml version="1.0" encoding="UTF-8"?> <xp:view xmlns:xp="http://www.ibm.com/xsp/core"> <xp:label id="label1"> <xp:this.value><![CDATA[#{javascript: var url = "/WEB-INF/faces-config.xml"; var data = facesContext.getExternalContext(). getResourceAsStream( url ); var txt = ""; while( data.available() ){ txt += @Char(data.read()); } txt}]]> </xp:this.value> </xp:label> </xp:view>
[This displays the current faces-config.xml]
By using the correct URL path it is for example possible to access the code of SSJS libraries or even the source code of java classes in the database. To access the source code of a XPage, just use the name of the XPage itself. Same procedure for SSJS libraries, just add a „.jss“ at the end of the library’s name. For accessing a java class, the „dots“ in the package names have to be replaced with „slashes“.
To access f.e. the java file for class ch.hasselba.jsf.debug.ResourceUtil the url has to look like this:
var url = "ch/hasselba/jsf/debug/ResourceUtil.java";
Pingback: XPages: Access resources and their content (2) | blog@hasselba.ch