htmledit.xslt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: cpscrn
  5. (C) Copyright IBM Corp. 2005, 2011
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. -->
  12. <xsl:stylesheet version="1.0"
  13. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  15. xmlns:pui="http://developer.cognos.com/common/portal/logic/ui/1/"
  16. xmlns:layout="http://developer.cognos.com/common/layout"
  17. xmlns:valerr="http://developer.cognos.com/validation/errrormessages/1/"
  18. xmlns:java="java:com.cognos.portal.utils.CCLLocaleUtils"
  19. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt" exclude-result-prefixes="xts xtsext layout">
  20. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  21. <xsl:variable name="meta" select="/root/fragment/meta"/>
  22. <xsl:variable name="useLocale">
  23. <xsl:choose>
  24. <xsl:when test="not(/root/customs/param[@name='title']/value)">
  25. <xsl:value-of select="/root/preferences/param[@name='contentLocale']"/>
  26. </xsl:when>
  27. <xsl:otherwise>
  28. <xsl:variable name="langs">
  29. <xsl:for-each select="/root/customs/param[@name='title']/value">
  30. <xsl:value-of select="@xml:lang"/>
  31. <xsl:if test="not(position() = last())">,</xsl:if>
  32. </xsl:for-each>
  33. </xsl:variable>
  34. <xsl:value-of select="java:getBestFitLocale(string(/root/preferences/param[@name='contentLocale']),string($langs))"/>
  35. </xsl:otherwise>
  36. </xsl:choose>
  37. </xsl:variable>
  38. <layout:selectortemplates/>
  39. <xsl:template match="/">
  40. <div>
  41. <pui:aboutscript/>
  42. <pui:helpscript/>
  43. <layout:form name="_THIS_HTMLForm" action="_THIS?/THIS_" method="post">
  44. <layout:section format="header">
  45. <layout:text><xsl:value-of select="$meta/customProperties[@name='Description']/hint"/></layout:text>
  46. <layout:actionlist>
  47. <layout:action>
  48. <pui:aboutlink/>
  49. </layout:action>
  50. <layout:action>
  51. <pui:helplink/>
  52. </layout:action>
  53. </layout:actionlist>
  54. </layout:section>
  55. <layout:script>
  56. var _THIS_validationSuccess = "<xts:string id="IDS_PROP_VALIDATE_SUCCESSFUL" encode="javascript"/>";
  57. var _THIS_validationMessage = "<xts:string id="IDS_PROP_VALIDATE_DESCRIPTION" encode="javascript"/>";
  58. var _THIS_validationException = "<xts:string id="IDS_PROP_VALIDATE_EXCEPTION" encode="javascript"/>";
  59. function _THIS_refreshEdit(evt)
  60. {
  61. if(evt.eventPhase == evt.AT_TARGET)
  62. {
  63. checkToRefresh("_THIS_HTMLForm",evt,"<xts:string id="IDS_PROP_REFRESH_LANGUAGE_MSG" encode="javascript"/>");
  64. }
  65. }
  66. _THIS_.addEventListener("fragment.refresh","_THIS_refreshEdit",false);
  67. function _THIS_cancelEdit()
  68. {
  69. if (_THIS_.removeFragChildren)
  70. _THIS_.removeFragChildren();
  71. _THIS_.setMode('view');
  72. }
  73. function _THIS_processModeHTML(formaction,cur,sForm,content,select)
  74. {
  75. if (formaction == "save")
  76. {
  77. //first validate the title
  78. var titleErr = validateMultiLingualProperty("Selector", "title", "HTMLForm", "_THIS_", _THIS_, _THIS_itemList);
  79. if (titleErr != CValidator.RES_VALID)
  80. {
  81. var entryEl = document.getElementById("_THIS_title");
  82. alert(entryEl.getAttribute("valerr:message"));
  83. entryEl.focus();
  84. return false;
  85. }
  86. }
  87. cForm = document.forms[cur+sForm];
  88. elem = $(cur+content);
  89. if( formaction != 'edit' &amp;&amp; formaction != 'cancel' )
  90. {
  91. if( elem &amp;&amp; elem.value != '' )
  92. {
  93. formaction = _THIS_validateHTML(elem, formaction);
  94. var selector = $("_THIS_Selector");
  95. var languageSpecificPropertyName = "HTMLMarkup-" +(selector.options[selector.selectedIndex]).value;
  96. var currentLanguageItem = cForm.elements[languageSpecificPropertyName];
  97. currentLanguageItem.value = elem.value;
  98. }
  99. }
  100. if( formaction != "validate")
  101. {
  102. setHiddenItemValue(cForm,'formaction',formaction);
  103. cForm.submit();
  104. }
  105. }
  106. function _THIS_validateHTML(elem,formaction)
  107. {
  108. var bnchmrkVal = markup = elem.value;
  109. <!-- How to read this expression - find < optionally with / then one of these tags with anything before the >; make it global, case insensitive and mulitple lines -->
  110. var tagsList = /&lt;(\/)?(html|script|body|form|head|frameset|frame).*?\&gt;/gim;
  111. var hasTags = tagsList.test(bnchmrkVal);
  112. if(hasTags)
  113. {
  114. <!-- How to read these expressions - find any control characters, then < optionally with / then the tag name with anything before the >, -->
  115. <!-- then any control characters; make it global and case insensitive -->
  116. var removeTagsOnly = /(\0|\r|\n|\t|\v|\f)*&lt;(\/)?(html|body|form).*?\&gt;(\0|\r|\n)*/gi;
  117. if(removeTagsOnly.test(markup))
  118. markup = markup.replace(removeTagsOnly,"");
  119. <!-- How to read these expressions - find any control characters, then the < tag name with anything before the >, -->
  120. <!-- then any characters or control characters, then the </ tag name >, then any control characters; make it global, case insensitive and multiple lines -->
  121. <!-- ***** NOTE *****: the following conditions are not to be combined since doing so causes too much trimming of the input HTML code -->
  122. var regxHead = /(\0|\r|\n|\t|\v|\f)*&lt;head.*?\&gt;(?:(.|\n)*)&lt;\/head\&gt;(\0|\r|\n)*/gim;
  123. var regxScript = /(\0|\r|\n|\t|\v|\f)*&lt;script.*?\&gt;(?:(.|\n)*)&lt;\/script\&gt;(\0|\r|\n)*/gim;
  124. var regxFrameset = /(\0|\r|\n|\t|\v|\f)*&lt;frameset.*?\&gt;(?:(.|\n)*)&lt;\/frameset\&gt;(\0|\r|\n)*/gim;
  125. var regxFrame = /(\0|\r|\n|\t|\v|\f)*&lt;frame.*?\&gt;(?:(.|\n)*)&lt;\/frame\&gt;(\0|\r|\n)*/gim;
  126. <!-- look for the matching head tags -->
  127. if(markup.match(regxHead))
  128. markup = markup.replace(regxHead,"");
  129. <!-- look for the matching script tags -->
  130. if(markup.match(regxScript))
  131. markup = markup.replace(regxScript,"");
  132. <!-- look for the matching frameset tags -->
  133. if(markup.match(regxFrameset))
  134. markup = markup.replace(regxFrameset,"");
  135. <!-- look for the matching frame tags -->
  136. if(markup.match(regxFrame))
  137. markup = markup.replace(regxFrame,"");
  138. <!-- Clean up any orphaned head or frame* tags -->
  139. regxFrame = /(\0|\r|\n|\t|\v|\f)*&lt;(\/)?(head|frame|script).*?\&gt;/gi;
  140. if(markup.match(regxFrame))
  141. markup = markup.replace(regxFrame,"");
  142. }
  143. if(hasTags || !(markup === elem.value))
  144. {
  145. elem.value = markup;
  146. alert(_THIS_validationMessage);
  147. }
  148. else if(formaction=='validate')
  149. alert(_THIS_validationSuccess);
  150. return formaction;
  151. }
  152. </layout:script>
  153. <layout:localeselectorcontrol name="Selector">
  154. <layout:label>
  155. <layout:text><xts:string id="IDS_PROP_LANGUAGE_CAPTION"/></layout:text>
  156. </layout:label>
  157. <layout:controlparameters>
  158. <formname>_THIS_HTMLForm</formname>
  159. <contentlocales><xsl:copy-of select="/root/input[@name='configurationResponse']/config/param[@name='contentLocales']/*"/></contentlocales>
  160. <customs><xsl:copy-of select="/root/customs/*"/></customs>
  161. <fieldlist>title,HTMLMarkup</fieldlist>
  162. <preferences><xsl:copy-of select="/root/preferences/*"/></preferences>
  163. </layout:controlparameters>
  164. </layout:localeselectorcontrol>
  165. <layout:field id="title" type="text" size="40" maxlength="256" onblur="javascript:savelangitem('_THIS_','HTMLForm','Selector',this)" >
  166. <xsl:attribute name="message" namespace="http://developer.cognos.com/validation/errrormessages/1/" ><xts:string id="IDS_GEN_TITLE_VALIDATION_ERROR" /></xsl:attribute>
  167. <layout:label><layout:text><xsl:value-of select="$meta/customProperties[@name='title']/label"/></layout:text></layout:label>
  168. <layout:value>
  169. <xsl:choose>
  170. <xsl:when test="/root/customs/param[@name='title']/value[@xml:lang=$useLocale]">
  171. <xsl:value-of select="/root/customs/param[@name='title']/value[@xml:lang=$useLocale]"/>
  172. </xsl:when>
  173. <xsl:when test="/root/customs/param[@name='title']/value[1]">
  174. <xsl:value-of select="/root/customs/param[@name='title']/value[1]"/>
  175. </xsl:when>
  176. <xsl:otherwise>
  177. <xsl:value-of select="/root/fragment/meta/customProperties[@name='title']/default/value"/>
  178. </xsl:otherwise>
  179. </xsl:choose>
  180. </layout:value>
  181. </layout:field>
  182. <xsl:choose>
  183. <xsl:when test="string(/root/init/canEditHTML)='true'">
  184. <layout:field id="HTMLMarkup" type="textarea" rows="20" cols="100" onblur="javascript:savelangitem('_THIS_','HTMLForm','Selector',this)" >
  185. <xsl:attribute name="message" namespace="http://developer.cognos.com/validation/errrormessages/1/" ><xts:string id="IDS_PROP_VALIDATE_DESCRIPTION" encode="xml"/></xsl:attribute>
  186. <layout:label>
  187. <layout:text><xsl:value-of select="$meta/customProperties[@name='HTMLMarkup']/label"/></layout:text>
  188. <layout:hint><xsl:value-of select="$meta/customProperties[@name='HTMLMarkup']/hint"/></layout:hint>
  189. </layout:label>
  190. <layout:value>
  191. <xsl:choose>
  192. <xsl:when test="/root/customs/param[@name='HTMLMarkup']/value[@xml:lang=$useLocale]">
  193. <xsl:value-of select="/root/customs/param[@name='HTMLMarkup']/value[@xml:lang=$useLocale]"/>
  194. </xsl:when>
  195. <xsl:when test="/root/customs/param[@name='HTMLMarkup']/value[1]">
  196. <xsl:value-of select="/root/customs/param[@name='HTMLMarkup']/value[1]"/>
  197. </xsl:when>
  198. <xsl:otherwise>
  199. <xsl:value-of select="/root/fragment/meta/customProperties[@name='HTMLMarkup']/default/value"/>
  200. </xsl:otherwise>
  201. </xsl:choose>
  202. </layout:value>
  203. </layout:field>
  204. </xsl:when>
  205. <xsl:otherwise>
  206. <layout:section>
  207. <layout:label>
  208. <layout:text><xsl:value-of select="$meta/customProperties[@name='HTMLMarkup']/label"/></layout:text>
  209. <layout:hint><xsl:value-of select="$meta/customProperties[@name='HTMLMarkup']/hint"/></layout:hint>
  210. </layout:label>
  211. </layout:section>
  212. <layout:section class="cogstyle-layout-textmsg">
  213. <layout:text><xts:string id="IDS_PROP_HTML_CAPABILITY_TEXT"/></layout:text>
  214. </layout:section>
  215. </xsl:otherwise>
  216. </xsl:choose>
  217. <layout:section format="footer" divider="true">
  218. <layout:row>
  219. <layout:button onclick="_THIS_processModeHTML('save','_THIS_','HTMLForm','HTMLMarkup','Selector');">
  220. <layout:value><xts:string id="IDS_PROP_OK_BUTTON_TEXT"/></layout:value>
  221. </layout:button>
  222. <layout:button onclick="_THIS_cancelEdit()">
  223. <layout:value><xts:string id="IDS_PROP_CANCEL_BUTTON_TEXT"/></layout:value>
  224. </layout:button>
  225. </layout:row>
  226. </layout:section>
  227. </layout:form>
  228. </div>
  229. </xsl:template>
  230. </xsl:stylesheet>