details: https://code.openbravo.com/erp/devel/pi/rev/34641a1a0c78 changeset: 26890:34641a1a0c78 user: Naroa Iriarte <naroa.iriarte <at> openbravo.com> date: Wed Jun 10 15:51:06 2015 +0200 summary: Fixed issue 30092: the bo.xslt template is working wrong.
The problem was that it was not possible to get the correct url by clicking in the links. For example, if you went to the url: https://livebuilds.openbravo.com/erp_main_pgsql/ws/dal/ADUser?template=bo.xslt And you click in some link, the obtained url was: https://livebuilds.openbravo.com/erp_main_pgsql/ws/ADUser/100?template=bo.xslt instead of: https://livebuilds.openbravo.com/erp_main_pgsql/ws/dal/ADUser/100?template=bo.xslt The problem was in the bo.xslt template, in the href variable. It was being set wrong in some cases, it removed one extra level from the url. This is OK when the url has the id after the entity name, like: https://livebuilds.openbravo.com/erp_main_pgsql/ws/dal/ADUser/100?template=bo.xslt But in the case of not having the id after the entity name in the url, it is wrong to substract a level from the url. In this case, that does not have the id after the entity name, didn't work well: https://livebuilds.openbravo.com/erp_main_pgsql/ws/dal/ADUser?template=bo.xslt The substraction of the level retuned a bad url, the "/dal" is missing: https://livebuilds.openbravo.com/erp_main_pgsql/ws/ADUser/100?template=bo.xslt To fix this the bo.xslt has been changed, now it takes into account if the url contains the id after the entity name. If it does, a level is substracted. If not, no. The WebServiceUtil.applyTemplate method has been changed too. Now the parameter hasId is set here and is passed to the bo.xslt. This boolean parameter is true if the url has the id after the entity name, and false if not. diffstat: src/org/openbravo/service/rest/bo.xslt | 30 ++++++++++++++++------ src/org/openbravo/service/web/WebServiceUtil.java | 13 +++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diffs (89 lines): diff -r f7a872ac28de -r 34641a1a0c78 src/org/openbravo/service/rest/bo.xslt --- a/src/org/openbravo/service/rest/bo.xslt Wed Jun 10 13:12:40 2015 +0000 +++ b/src/org/openbravo/service/rest/bo.xslt Wed Jun 10 15:51:06 2015 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2008-2010 Openbravo SLU + * All portions are Copyright (C) 2008-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -23,6 +23,7 @@ Note if the namespace of openbravo changes then the namespace declaration above has to be changed --> + <xsl:param name="hasId"></xsl:param> <xsl:template match="ob:Openbravo"> <xsl:for-each select="*"> <xsl:call-template name="handleEntity" /> @@ -113,12 +114,25 @@ / <xsl:value-of select="@id" /> </xsl:variable> - <a href="../{$href}?template=bo.xslt"> - <xsl:value-of select="@identifier" /> - ( - <xsl:value-of select="@id" /> - ) - </a> - <a href="../{$href}"> (xml)</a> + <xsl:choose> + <xsl:when test="$hasId = 'true'"> + <a href="../{$href}?template=bo.xslt"> + <xsl:value-of select="@identifier" /> + ( + <xsl:value-of select="@id" /> + ) + </a> + <a href="../{$href}"> (xml)</a> + </xsl:when> + <xsl:otherwise> + <a href="{$href}?template=bo.xslt"> + <xsl:value-of select="@identifier" /> + ( + <xsl:value-of select="@id" /> + ) + </a> + <a href="{$href}"> (xml)</a> + </xsl:otherwise> + </xsl:choose> </xsl:template> </xsl:stylesheet> \ No newline at end of file diff -r f7a872ac28de -r 34641a1a0c78 src/org/openbravo/service/web/WebServiceUtil.java --- a/src/org/openbravo/service/web/WebServiceUtil.java Wed Jun 10 13:12:40 2015 +0000 +++ b/src/org/openbravo/service/web/WebServiceUtil.java Wed Jun 10 15:51:06 2015 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2008-2010 Openbravo SLU + * All portions are Copyright (C) 2008-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -230,11 +230,22 @@ */ public String applyTemplate(String xml, InputStream template, String url) { try { + boolean hasId; + // This regular expression has been created to find out if there is an id after + // the entity name in the url. For example: + // https://livebuilds.openbravo.com/erp_main_pgsql/ws/dal/ADUser/100 + String regExp = "^(.*)[dal]+[\\/][A-Za-z0-9]+[\\/][A-Za-z0-9]+"; final TransformerFactory factory = TransformerFactory.newInstance(); final Transformer transformer = factory.newTransformer(new StreamSource(template)); final DocumentSource source = new DocumentSource(DocumentHelper.parseText(xml)); final StringWriter sw = new StringWriter(); final StreamResult response = new StreamResult(sw); + if (url.matches(regExp)) { + hasId = true; + } else { + hasId = false; + } + transformer.setParameter("hasId", hasId); transformer.setParameter("url", url); transformer.transform(source, response); ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits