Extensions Wiki » Extensions » XWQL to HQL converter

XWQL to HQL converter

Last modified by Eduard Moraru on 2014/08/14 13:40
cogA snippet to debug how XWQL queries are converted to HQL
TypeSnippet
Developed by

Guillaume Delhumeau

LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Just take this code:

{{groovy}}
import org.xwiki.query.xwql.internal.hql.*;
import org.xwiki.query.xwql.internal.*;
import com.xpn.xwiki.web.*;

def query = request.getParameter('query') != null ? request.getParameter('query') : "";
def esc = new org.apache.velocity.tools.generic.EscapeTool();
query = esc.xml(query);
def url = doc.getURL();

println """
= Convert XWQL to HQL =
{{html}}
  <form class="
xform" action="$url" method="GET">
    <dl>
      <dt><label for="
query_id">Query:</label></dt>
      <dd><textarea name="
query" id="query_id">$query</textarea></dd>
    </dl>
    <p><span class="
buttonwrapper"><input type="submit" value="Convert !" class="button" /></span></p>
  </form>
{{/html}}
"""
;

if(request.getParameter('query')){
  def translator = null;
 if(services.component != null)
    translator = services.component.getInstance(QueryTranslator.class, "hql");
 else
    translator = Utils.getComponent(QueryTranslator.class, "hql");

  String output = translator.translate(request.getParameter('query'));
  println "= Results =";
  println "{{info}}$output{{/info}}";
}
{{/groovy}}

Example of use:
screenshot.png

Tags:
Created by Guillaume Delhumeau on 2012/11/13 18:31

Download XWiki

My Recent Modifications

Get Connected