{"id":752,"date":"2012-07-15T12:02:34","date_gmt":"2012-07-15T10:02:34","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=752"},"modified":"2012-07-15T12:02:34","modified_gmt":"2012-07-15T10:02:34","slug":"xpages-access-resources-and-their-content","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=752","title":{"rendered":"XPages: Access resources and their content"},"content":{"rendered":"<p>To access XPages resources during runtime and to get their content as a string, you can use the following SSJS code snippet:<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;xp:view xmlns:xp=\"http:\/\/www.ibm.com\/xsp\/core\"&gt;\r\n\r\n\u00a0\u00a0 \u00a0&lt;xp:label id=\"label1\"&gt;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;xp:this.value&gt;&lt;![CDATA[#{javascript:\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0var url = \"\/WEB-INF\/faces-config.xml\";\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0var data = facesContext.getExternalContext().\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0getResourceAsStream( url );\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0var txt = \"\";\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0while( data.available() ){\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0txt += @Char(data.read());\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0txt}]]&gt;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;\/xp:this.value&gt;\r\n\u00a0\u00a0 \u00a0&lt;\/xp:label&gt;\r\n\r\n&lt;\/xp:view&gt;<\/pre>\n<p><em>[This displays the current faces-config.xml]<\/em><\/p>\n<p>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 &#8222;.jss&#8220; at the end of the library&#8217;s name. For accessing a java class, the &#8222;dots&#8220; in the package names have to be replaced with &#8222;slashes&#8220;.<\/p>\n<p>To access f.e. the java file for class <em>ch.hasselba.jsf.debug.ResourceUtil\u00a0<\/em>the url has to look like this:<\/p>\n<pre>var url = \"ch\/hasselba\/jsf\/debug\/ResourceUtil.java\";<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To access XPages resources during runtime and to get their content as a string, you can use the following SSJS code snippet: &lt;?xml version=&#8220;1.0&#8243; encoding=&#8220;UTF-8&#8243;?&gt; &lt;xp:view xmlns:xp=&#8220;http:\/\/www.ibm.com\/xsp\/core&#8220;&gt; \u00a0\u00a0 \u00a0&lt;xp:label id=&#8220;label1&#8243;&gt; \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;xp:this.value&gt;&lt;![CDATA[#{javascript: \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0var url = &#8222;\/WEB-INF\/faces-config.xml&#8220;; &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=752\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89,9,76,74],"tags":[33,14,7,5,32,3],"class_list":["post-752","post","type-post","status-publish","format-standard","hentry","category-java","category-javascript","category-ssjs","category-xpages","tag-8-5-3","tag-designer","tag-domino","tag-ssjs","tag-tipp","tag-xpages"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=752"}],"version-history":[{"count":10,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/752\/revisions"}],"predecessor-version":[{"id":762,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/752\/revisions\/762"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}