<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ page import="com.k_int.oql.iface.*,com.k_int.oql.util.*,com.k_int.QueryDescriptor.*,net.sf.hibernate.*,net.sf.hibernate.type.*,java.util.*" %> <%! public static int recurseQueryTree(QueryNode qn, JspWriter out, org.apache.struts.util.PropertyMessageResources messages, java.util.Locale locale, HttpServletRequest request, net.sf.hibernate.Session sess) throws java.io.IOException { int count=0; if ( qn instanceof BooleanNode ) { BooleanNode bn = (BooleanNode)qn; for ( java.util.Iterator e = bn.getComponents().iterator(); e.hasNext(); ) { count += recurseQueryTree((QueryNode)e.next(), out, messages, locale, request,sess); } } else { ExpressionNode en = (ExpressionNode)qn; if ( en.getEditingInfo() != null ) { String value = request.getParameter(en.getId()); if ( value == null ) value=""; String name = messages.getMessage(locale,en.getName()); if ( name == null ) name = en.getName(); if ( ( en.getUIHint() == null ) ) { out.write("" + name + ":"); out.write("\n"); } else if ( en.getUIHint() instanceof com.k_int.QueryDescriptor.ui.Combo ) { com.k_int.QueryDescriptor.ui.Combo combo_info = (com.k_int.QueryDescriptor.ui.Combo) en.getUIHint(); out.write("" + name + ":"); out.write(""); out.write(""); out.write("\n"); } else if ( en.getUIHint() instanceof com.k_int.QueryDescriptor.ui.RadioButtons ) { com.k_int.QueryDescriptor.ui.RadioButtons radio_buttons = (com.k_int.QueryDescriptor.ui.RadioButtons)en.getUIHint(); out.write("" + name + ":"); out.write(""); if ( radio_buttons.getAllowNull() ) { out.write(" Any"); } if ( radio_buttons.getDataSource() != null ) { for ( java.util.Iterator i = radio_buttons.getDataSource().getValues(sess).iterator(); i.hasNext(); ) { com.k_int.QueryDescriptor.ui.StaticValue val = (com.k_int.QueryDescriptor.ui.StaticValue) i.next(); out.write("  "); out.write(val.getLabel()); } } out.write("\n"); } count++; } } return count; } %> <% long max_results = 500; long result_count = 0; String base_dir = request.getContextPath(); String action=""; String show_descriptor = (String) request.getAttribute("showDescriptor"); String sort_order = (String) request.getAttribute("sortOrder"); String title = (String) request.getAttribute("qm.title"); String sf = (String) request.getAttribute("sf"); if ( sf != null ) { // System.err.println("sf="+sf); int rec_no = 0; String record = (String) request.getAttribute("record"); if(record!=null){ rec_no = Integer.parseInt(record); } boolean sd = false; String change_sort = request.getParameter("ChangeSort"); if(change_sort==null) change_sort = (String) request.getAttribute("change_sort"); System.out.println("CHANGE SORT = "+change_sort); if ( change_sort != null ) { String[] sort_params = change_sort.split(":"); sort_order = sort_params[1]+":"+sort_params[2]+":"+sort_params[3]; } %>

<%=title%>

<% com.k_int.QueryDescriptor.QueryDescriptor qd = (com.k_int.QueryDescriptor.QueryDescriptor) request.getAttribute("QueryDescriptor"); if ( request.isUserInRole("SuperUser") ) { if ( ( show_descriptor != null ) && ( show_descriptor.equals("true") ) ) { %>


<% System.out.println("descriptorTxt "+request.getAttribute("descriptorTxt")); } else { sd = true; } } %> <% if ( qd != null ) { net.sf.hibernate.Session sess = null; String oql = null; try { org.springframework.web.context.WebApplicationContext ctx = org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(application); net.sf.hibernate.SessionFactory factory = (net.sf.hibernate.SessionFactory) ctx.getBean(sf); sess = factory.openSession(); String setname = (String) request.getAttribute("Setname"); org.apache.struts.util.PropertyMessageResources messages = (org.apache.struts.util.PropertyMessageResources)request.getAttribute("org.apache.struts.action.MESSAGE"); java.util.Locale locale = (java.util.Locale)session.getAttribute("org.apache.struts.action.LOCALE"); // String message = (String)myMessages.getMessage(myLocale, key); if ( recurseQueryTree(qd.getQuery(), out, messages, locale, request,sess) > 0 ) { %>
<% } %>
<% if ( sd ) { %> <% } %>
<% try { %> <% ElementSet es = qd.lookupElementSet(setname); for ( Iterator i = es.iterator(); i.hasNext(); ) { ResultElement re = (ResultElement) i.next(); if ( re.getVisibility() ) { String col_head = messages.getMessage(locale,re.getName()); if ( col_head == null ) col_head = re.getName(); %> <% } else { } } %> <% Vector bind_vars = new Vector(); Vector bind_types = new Vector(); List sort_criteria = new ArrayList(); if ( sort_order != null ) { sort_criteria.add(sort_order); } bind_vars.clear(); bind_types.clear(); OQLSelectStatement count_sql = com.k_int.oql.util.OQLSelectFactory.createStatement(qd, bind_vars, bind_types, request.getParameterMap(), "Count"); oql = count_sql.toString(); String error = ""; List qry_count_result = sess.find(oql, bind_vars.toArray(), (Type[])bind_types.toArray(new Type[0])); Object res = qry_count_result.get(0); System.out.println("OQL = " + oql); System.out.println("Result Size = " + res.toString()); try{ result_count = Long.parseLong(res.toString().trim()); } catch(RuntimeException re){ re.printStackTrace(); error = re.getStackTrace().toString(); result_count = -1; } oql = null; List qry_result = null; if(result_count >= 1 && result_count <= max_results){ bind_vars.clear(); bind_types.clear(); OQLSelectStatement result_rows = com.k_int.oql.util.OQLSelectFactory.createStatement(qd, bind_vars, bind_types, request.getParameterMap(), setname, sort_criteria); oql = result_rows.toString(); qry_result = sess.find(oql, bind_vars.toArray(), (Type[])bind_types.toArray(new Type[0])); } else if(result_count == 0){ %>

This query produced no results.

<% } else if(result_count == -1){ %>

Exception! <%=error%>

<% } else{ %>

This query will produce a result set that is too large to be displayed. Please refine your search terms.

<% } if ( qry_result!=null && qry_result.size() > 0 ) { // Found qry_result.size() Rows boolean highlight = true; for ( Iterator i=qry_result.iterator(); i.hasNext(); ) { String rowformat = ""; if(highlight){ rowformat = ""; } %><%=rowformat%><% Object row = i.next(); if ( row instanceof Object[] ) { // Multiple Select Elements Object[] row_values = (Object[]) row; for ( int ri=0; ri < row_values.length; ri++ ) { // Only display the column entry if it's marked as being visible. ResultElement re = (ResultElement) es.getElementAt(ri); if ( re.getVisibility() == true ) { if ( re.getUserData() != null ) { // We need to parse out href and stuff.... String href = base_dir+(re.getUserData().toString()); // ToDo: Now we use Split to Split the String down into components so we // can parse out each ${n} and replace each of those tokens with the // value from column n in the result set. String[] components = href.split("[$}]"); java.io.StringWriter sw = new java.io.StringWriter(); for ( int ci=0; ci<% } else { if ( re.getActionCode() != null) { // System.err.println("action code "+re.getActionCode()); String[] action_components = re.getActionCode().split(":"); if ( ( action_components.length > 0 ) && ( action_components[0].equalsIgnoreCase("EDIT") ) ) { Object object_to_edit = row_values[0]; String layout_code = null; if ( action_components.length > 1 ) { // EDIT:ObjectCol // System.err.println("ID "+action_components[1].toString()+" "+Integer.parseInt(action_components[1].toString())); object_to_edit = row_values[Integer.parseInt(action_components[1].toString())]; } if ( action_components.length > 2 ) // EDIT:ObjectCol:Layout layout_code = action_components[2].toString(); String class_name = object_to_edit.getClass().getName(); Object key = sess.getIdentifier(object_to_edit); String url = "edit.do?oid="+class_name+":"+java.net.URLEncoder.encode(key.toString())+"&sf="+sf+"&bct=add"; if ( layout_code != null ) { url = url+"&layout_code="+layout_code; } %><% } else { %><% } } else { %><% } } } else { } } %> <% } else { // A single object or col, just dump it %><% } %><% highlight = !highlight; } } else { } } catch ( net.sf.hibernate.QueryException qe) { %>Problem executing query : <%=oql%>
<%=qe%>
<%=request.getAttribute("descriptorTxt")%><% } catch ( Exception e ) { e.printStackTrace(); %>Problem executing query : <%=oql%>
<%=e%>
<%=request.getAttribute("descriptorTxt")%><% } } finally { if ( sess != null ) { try { sess.close(); } catch ( Exception e) {} } } %>
<%=col_head%> <% if ( re instanceof ScopedElement ) { ScopedElement se = (ScopedElement) re; if ( se.getSortable() ) { %> Sort Ascending Sort Descending <% } } %>
<%=row_values[ri]%><%=row_values[ri]%>(Unknown Action <%=re.getActionCode()%>)<%=row_values[ri]%><%=row_values[ri]%> <% for ( java.util.Iterator row_action_iterator = qd.getRowActions(); row_action_iterator.hasNext(); ) { com.k_int.QueryDescriptor.RowAction ra = (com.k_int.QueryDescriptor.RowAction)row_action_iterator.next(); if ( ra instanceof com.k_int.QueryDescriptor.SecSearchAction ) { com.k_int.QueryDescriptor.SecSearchAction ssa = (com.k_int.QueryDescriptor.SecSearchAction) ra; Object prop_val = row_values[ssa.getValueCol()]; if ( prop_val != null ) { %> <%=ssa.getName()%><% } } else if ( ra instanceof com.k_int.QueryDescriptor.DeleteRowAction ) { Object object_to_edit = row_values[0]; String class_name = object_to_edit.getClass().getName(); Object key = sess.getIdentifier(object_to_edit); %> DELETE<% } else if ( ra instanceof com.k_int.QueryDescriptor.EditRowAction ) { Object object_to_edit = row_values[0]; String class_name = object_to_edit.getClass().getName(); Object key = sess.getIdentifier(object_to_edit); %> EDIT<% } else if ( ra instanceof com.k_int.QueryDescriptor.LocalFunction ) { com.k_int.QueryDescriptor.LocalFunction la = (com.k_int.QueryDescriptor.LocalFunction) ra; String action_code = la.getActionCode(); String param_name = la.getParamName(); Object prop_val = row_values[la.getParamValueCol()]; if ( prop_val != null ) { %> <%=la.getName()%><% } } else { %>Unknown Action<% } } %><%=row%>
<% } else { %>

Sorry, there was an error parsing the search descriptor for this page

<% } } else { %>

Sorry, no sf passed to the action. Please contact the system administrator

<% } %>