All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.semanticwb.portal.resources.CollectionResource Maven / Gradle / Ivy

The newest version!
/*
 * SemanticWebBuilder es una plataforma para el desarrollo de portales y aplicaciones de integración,
 * colaboración y conocimiento, que gracias al uso de tecnología semántica puede generar contextos de
 * información alrededor de algún tema de interés o bien integrar información y aplicaciones de diferentes
 * fuentes, donde a la información se le asigna un significado, de forma que pueda ser interpretada y
 * procesada por personas y/o sistemas, es una creación original del Fondo de Información y Documentación
 * para la Industria INFOTEC, cuyo registro se encuentra actualmente en trámite.
 *
 * INFOTEC pone a su disposición la herramienta SemanticWebBuilder a través de su licenciamiento abierto al público (‘open source’),
 * en virtud del cual, usted podrá usarlo en las mismas condiciones con que INFOTEC lo ha diseñado y puesto a su disposición;
 * aprender de él; distribuirlo a terceros; acceder a su código fuente y modificarlo, y combinarlo o enlazarlo con otro software,
 * todo ello de conformidad con los términos y condiciones de la LICENCIA ABIERTA AL PÚBLICO que otorga INFOTEC para la utilización
 * del SemanticWebBuilder 4.0.
 *
 * INFOTEC no otorga garantía sobre SemanticWebBuilder, de ninguna especie y naturaleza, ni implícita ni explícita,
 * siendo usted completamente responsable de la utilización que le dé y asumiendo la totalidad de los riesgos que puedan derivar
 * de la misma.
 *
 * Si usted tiene cualquier duda o comentario sobre SemanticWebBuilder, INFOTEC pone a su disposición la siguiente
 * dirección electrónica:
 *  http://www.semanticwebbuilder.org
 */
package org.semanticwb.portal.resources;

import org.semanticwb.model.User;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.semanticwb.Logger;
import org.semanticwb.SWBPlatform;
import org.semanticwb.SWBUtils;
import org.semanticwb.model.Collection;
import org.semanticwb.model.FormElement;
import org.semanticwb.model.FormValidateException;
import org.semanticwb.model.GenericObject;
import org.semanticwb.model.PropertyGroup;
import org.semanticwb.model.Resource;
import org.semanticwb.model.SWBComparator;
import org.semanticwb.model.SWBModel;
import org.semanticwb.model.Traceable;
import org.semanticwb.platform.SemanticClass;
import org.semanticwb.platform.SemanticModel;
import org.semanticwb.platform.SemanticObject;
import org.semanticwb.platform.SemanticOntology;
import org.semanticwb.platform.SemanticProperty;
import org.semanticwb.platform.SemanticVocabulary;
import org.semanticwb.portal.SWBFormButton;
import org.semanticwb.portal.SWBFormMgr;
import org.semanticwb.portal.api.GenericResource;
import org.semanticwb.portal.api.SWBActionResponse;
import org.semanticwb.portal.api.SWBParamRequest;
import org.semanticwb.portal.api.SWBResourceException;
import org.semanticwb.portal.api.SWBResourceURL;

/**
 *
 * @author juan.fernandez
 */
public class CollectionResource extends GenericResource {

    /** The log. */
    private Logger log = SWBUtils.getLogger(CollectionResource.class);
    /** The MOD e_ form. */
    private String MODE_FORM = "FORM";
    /** The hm form ele. */
    private HashMap hmFormEle = null;
    private Resource base = null;
    private static String COLL_ID = "collid";

    @Override
    public void doAdmin(HttpServletRequest request, HttpServletResponse response, SWBParamRequest paramRequest) throws SWBResourceException, IOException {

        base = getResourceBase();
        response.setContentType("text/html; charset=ISO-8859-1");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");

        PrintWriter out = response.getWriter();
        User user = paramRequest.getUser();
        String id = request.getParameter("suri");

        String coluri = base.getAttribute(COLL_ID, "");

        SWBResourceURL urlact = paramRequest.getActionUrl();
        urlact.setAction("updcfg");
        out.println("
"); out.println("
"); out.println(""); out.println("
"); out.println(""); out.println(paramRequest.getLocaleString("msgResourceConfig")); out.println(""); out.println("
    "); Iterator itcol = paramRequest.getWebPage().getWebSite().listCollections(); while (itcol.hasNext()) { Collection collection = itcol.next(); out.println("
  • "); out.println(""); out.println("
  • "); } out.println("
"); out.println("
"); out.println("
"); out.println(""); // out.println("
"); out.println("
"); out.println("
"); } @Override public void processAction(HttpServletRequest request, SWBActionResponse response) throws SWBResourceException, IOException { String id = request.getParameter("suri"); String sval = request.getParameter("sval"); //String ract = request.getParameter("ract"); String action = response.getAction(); if (action == null) { action = ""; } if (action.equals("")) { action = request.getParameter("act"); } if (action == null) { action = ""; } //System.out.println("Accion:"+action); SemanticOntology ont = SWBPlatform.getSemanticMgr().getOntology(); GenericObject obj = ont.getGenericObject(id); if (action.equals("updcfg")) { try { String bhtype = request.getParameter(COLL_ID); //System.out.println("Config resource:"+bhtype); if (bhtype != null) { base.setAttribute(COLL_ID, bhtype); base.updateAttributesToDB(); } } catch (Exception e) { log.error(e); } response.setMode(SWBActionResponse.Mode_ADMIN); } else if ("new".equals(action)) { log.debug("ProcessAction(new) "); id = request.getParameter("suri"); String clsuri = request.getParameter("clsuri"); SemanticObject so = ont.getSemanticObject(id); SemanticClass sclass = ont.getSemanticObject(clsuri).transformToSemanticClass(); log.debug("ProcessAction(new): sobj: " + id); SWBFormMgr fmgr = new SWBFormMgr(sclass, so.getModel().getModelObject(), SWBFormMgr.MODE_CREATE); try { SemanticObject nso = fmgr.processForm(request); if (clsuri != null) { response.setRenderParameter("clsuri", clsuri); } response.setRenderParameter("nsuri", nso.getURI()); } catch (FormValidateException e) { throw new SWBResourceException("Error to process form...", e); } //response.setRenderParameter("statmsg", response.getLocaleString("statmsg1")); response.setMode(SWBActionResponse.Mode_VIEW); } else if ("updateform".equals(action)) { log.debug("ProcessAction(new) "); id = request.getParameter("suri"); String clsuri = request.getParameter("clsuri"); sval = request.getParameter("sval"); SemanticObject so = ont.getSemanticObject(sval); //SemanticClass sclass = ont.getSemanticObject(clsuri).transformToSemanticClass(); log.debug("ProcessAction(updateform): sobj: " + sval); SWBFormMgr fmgr = new SWBFormMgr(so, null, SWBFormMgr.MODE_EDIT); try { SemanticObject nso = fmgr.processForm(request); if (clsuri != null) { response.setRenderParameter("clsuri", clsuri); } response.setRenderParameter("nsuri", nso.getURI()); } catch (FormValidateException e) { throw new SWBResourceException("Error to process form...", e); } //response.setRenderParameter("statmsg", response.getLocaleString("statmsg1")); response.setMode(SWBActionResponse.Mode_VIEW); } else if ("remove".equals(action)) { log.debug("processAction(remove)"); //System.out.println("sval:"+sval); if (obj instanceof Collection) { Collection col = (Collection) obj; String prop = request.getParameter("prop"); //System.out.println("Eliminando ... "+prop); if(prop!=null&&prop.equals("display")) { //System.out.println("quitando display"); col.removeListProperties(sval); } else if(prop!=null&&prop.equals("search")) { //System.out.println("quitando search"); col.removeSearchProperties(sval); } } } if(id!=null) response.setRenderParameter("suri", id); if(sval!=null) response.setRenderParameter("sval", sval); } /* (non-Javadoc) * @see org.semanticwb.portal.api.GenericResource#doEdit(HttpServletRequest, HttpServletResponse, SWBParamRequest) */ @Override public void doView(HttpServletRequest request, HttpServletResponse response, SWBParamRequest paramsRequest) throws SWBResourceException, IOException { base = getResourceBase(); response.setContentType("text/html; charset=ISO-8859-1"); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); PrintWriter out = response.getWriter(); User user = paramsRequest.getUser(); String id = null;//request.getParameter("suri"); id = base.getAttribute(COLL_ID); //System.out.println("Collection ID:"+id); String page = request.getParameter("page"); String collectiontype = "display"; SemanticOntology ont = SWBPlatform.getSemanticMgr().getOntology(); GenericObject gobj = ont.getGenericObject(id); if (hmFormEle == null) { //System.out.println("Cargando HM - Form Element"); hmFormEle = new HashMap(); SemanticOntology sont = SWBPlatform.getSemanticMgr().getSchema(); SemanticVocabulary sv = SWBPlatform.getSemanticMgr().getVocabulary(); Iterator itfe = sv.getSemanticClass(sv.SWB_FORMELEMENT).listInstances(false);//sont.listInstancesOfClass(sv.getSemanticClass(sv.SWB_FORMELEMENT)); while (itfe.hasNext()) { SemanticObject sofe = itfe.next(); hmFormEle.put(sofe.getURI(), sofe); //System.out.println("formElement: "+sofe.getId()); } } String action = request.getParameter("act"); if (action == null) { action = ""; } Collection col = null; if (collectiontype.equals("display")) { //("stpBusqueda".equals(action) || "".equals(action)) { //System.out.println("ID: "+id); String busqueda = request.getParameter("search"); if (null == busqueda) { busqueda = ""; } busqueda = busqueda.trim(); HashMap hmhasprop = new HashMap(); // uri property, uri form element asociado HashMap hmhasproporder = new HashMap(); // indice filtro, PROPIEDAD HashMap hmConfcol = new HashMap(); HashMap hmConfcolFE = new HashMap(); HashMap hmConfbus = new HashMap(); HashMap hmfiltro = new HashMap(); HashMap hmSearchParam = new HashMap(); if (gobj instanceof Collection) { col = (Collection) gobj; SemanticClass sccol = col.getCollectionClass().transformToSemanticClass(); //System.out.println("Coleccion: "+col.getTitle()); SWBModel colmodel = col.getCollectionModel(); if (colmodel == null) { colmodel = col.getWebSite().getSubModel(); } SemanticModel semmodel = colmodel.getSemanticObject().getModel(); SemanticProperty semProphm = null; Iterator its = col.listListPropertieses(); while (its.hasNext()) { String spropname = its.next(); StringTokenizer stoken = new StringTokenizer(spropname, "|"); //System.out.println("spropname: "+spropname); if (stoken != null) { String suri = stoken.nextToken(); String surife = stoken.nextToken(); String suriorder = stoken.nextToken(); semProphm = ont.getSemanticProperty(suri); if (semProphm != null) { hmConfcol.put(suriorder, semProphm); hmConfcolFE.put(suriorder, surife); } } else { semProphm = ont.getSemanticProperty(spropname); if (semProphm != null) { hmConfcol.put(spropname, semProphm); } } } ArrayList list = new ArrayList(hmConfcol.keySet()); Collections.sort(list); semProphm = null; its = col.listSearchPropertieses(); while (its.hasNext()) { String spropname = its.next(); StringTokenizer stoken = new StringTokenizer(spropname, "|"); //System.out.println("spropname: "+spropname); if (stoken != null) { String suri = stoken.nextToken(); String surife = stoken.nextToken(); String suriorder = stoken.nextToken(); semProphm = ont.getSemanticProperty(suri); //System.out.println("spropnameSearch: "+suri); if (semProphm != null) { hmConfbus.put(suri, semProphm); } if (semProphm.isObjectProperty()) { hmhasprop.put(suri, surife); hmhasproporder.put(suriorder, semProphm); } } } if (hmConfcol.size() > 0) { //Armado de tabla out.println("
"); //class=\"swbform\" out.println("
"); SWBResourceURL urls = paramsRequest.getRenderUrl(); urls.setParameter("act", "stpBusqueda"); urls.setParameter("act2", "ssearch"); out.println("
"); //onsubmit=\"submitForm('" + id + "/fsearch');return false;\" out.println(""); out.println("
"); out.println(""); out.println(""); out.println(""); HashMap hmFilterSearch = new HashMap(); // // REVISION DE OBJECT-PROPERTIES PARA OPCIONES DE FILTRADO // // TODO: Ordenarlo en de acuerdo con el orden de agregado en la configuración ArrayList listfilters = new ArrayList(hmhasproporder.keySet()); Collections.sort(listfilters); Iterator itsprop = listfilters.iterator(); while (itsprop.hasNext()) { //System.out.println("revisando object properties"); String urikey = itsprop.next(); SemanticProperty semanticProp = hmhasproporder.get(urikey); SemanticClass sc = semanticProp.getRangeClass(); if (sc != null) { out.println(""); String paramsearch = null; if (request.getParameter("search_" + sc.getClassId()) != null && request.getParameter("search_" + sc.getClassId()).trim().length() > 0) { paramsearch = request.getParameter("search_" + sc.getClassId()); hmSearchParam.put("search_" + sc.getClassId(), ont.getSemanticObject(paramsearch)); } if (request.getParameter(semanticProp.getName()) != null && request.getParameter(semanticProp.getName()).trim().length() > 0) { hmSearchParam.put("search_" + semanticProp.getName(), ont.getSemanticObject(request.getParameter(semanticProp.getName()))); } out.println(""); out.println(""); } } out.println(""); out.println("
 
"); out.println(""); out.println(""); out.println(""); out.println("
"); out.println(""); SWBFormMgr fmgr = new SWBFormMgr(gobj.getSemanticObject(), SWBFormMgr.MODE_EDIT, SWBFormMgr.MODE_EDIT); //TODO: Hacer el render de la propiedad y el FormElement configurado SemanticObject sofe = ont.getSemanticObject(hmhasprop.get(semanticProp.getURI())); FormElement fe = null; if (null != sofe) { if (sofe.transformToSemanticClass().isSWBFormElement()) { //System.out.println("Antes del FERender"); fe = fmgr.getFormElement(semanticProp);//FormElement) sofe; //out.println(fe.renderElement(request, gobj.getSemanticObject(), semProphm, SWBFormMgr.TYPE_XHTML, SWBFormMgr.MODE_EDIT, user.getLanguage())); out.println(fe.renderElement(request, gobj.getSemanticObject(), semanticProp, semanticProp.getName(), SWBFormMgr.TYPE_XHTML, SWBFormMgr.MODE_EDIT, user.getLanguage())); } } //if(null!=semanticProp) out.println(fmgr.renderElement(request, semanticProp, SWBFormMgr.MODE_EDIT)); out.println("
 
"); out.println("
"); out.println("
"); out.println(""); // out.println("
"); out.println("
"); out.println(" "); out.println("
"); out.println("
"); out.println(""); out.println(""); out.println(""); out.println(""); Iterator itcol = list.iterator(); //hmConfcol.keySet().iterator(); while (itcol.hasNext()) { String key = itcol.next(); SemanticProperty scol = hmConfcol.get(key); out.println(""); } out.println(""); out.println(""); out.println(""); SemanticObject semO = null; Iterator itso = semmodel.listInstancesOfClass(sccol); //gobj.getSemanticObject().getModel().listInstancesOfClass(sccol); //sccol.listInstances(); String urikey = null; SemanticProperty semOProp = null; if (!busqueda.equals("")) { while (itso.hasNext()) { semO = itso.next(); itcol = hmConfcol.keySet().iterator(); String occ = ""; while (itcol.hasNext()) { String sprop = itcol.next(); semOProp = hmConfcol.get(sprop); urikey = semOProp.getURI(); if (hmConfbus.get(urikey) != null) { occ = occ + reviewSemProp(hmConfbus.get(urikey), semO, paramsRequest); } } occ = occ.toLowerCase(); if (occ.indexOf(busqueda.toLowerCase()) > -1) { hmfiltro.put(semO.getURI(), semO); } } } //Llenado de la tabla if (!busqueda.equals("") || !hmSearchParam.isEmpty()) { HashMap hmResults = new HashMap(); HashMap hmRemove = new HashMap(); Iterator itsprop2 = null; if (!busqueda.equals("") || (!busqueda.equals("") && !hmSearchParam.isEmpty())) { itsprop2 = hmfiltro.values().iterator(); } else if (busqueda.equals("") && !hmSearchParam.isEmpty()) { itsprop2 = semmodel.listInstancesOfClass(sccol); //gobj.getSemanticObject().getModel().listInstancesOfClass(sccol); } if (!hmSearchParam.isEmpty()) { while (itsprop2.hasNext()) { //System.out.println("Filtrado por tipo de elementos"); SemanticObject sofil = itsprop2.next(); Iterator sempropit = hmConfbus.values().iterator(); while (sempropit.hasNext()) { SemanticProperty semanticProp = sempropit.next(); //System.out.println("Revisando propiedad: "+semanticProp.getName()); if (semanticProp.isObjectProperty()) { //System.out.println("Object property...."); SemanticClass semclass = semanticProp.getRangeClass(); if (semclass != null) { //System.out.println("class id: "+semclass.getClassId()); if (hmSearchParam.get("search_" + semclass.getClassId()) != null) { //System.out.println("Aplica Filtro encontrado..."); SemanticObject so = hmSearchParam.get("search_" + semclass.getClassId()); String URIfilter = so.getURI(); SemanticObject sotmp = sofil.getObjectProperty(semanticProp); //System.out.println("comparando "+URIfilter+ " con "+(sotmp!=null?sotmp.getURI():"nulo")); if (sotmp != null && sotmp.getURI().equals(URIfilter)) { //System.out.println("Conservando elemento."); hmResults.put(sofil.getURI(), sofil); } else { //System.out.println("Quitando elemento"); hmRemove.put(sofil.getURI(), sofil); } } if (hmSearchParam.get("search_" + semanticProp.getName()) != null) { //System.out.println("Aplica Filtro encontrado..."); SemanticObject so = hmSearchParam.get("search_" + semanticProp.getName()); String URIfilter = so.getURI(); SemanticObject sotmp = sofil.getObjectProperty(semanticProp); //System.out.println("propName comparando "+URIfilter+ " con "+(sotmp!=null?sotmp.getURI():"nulo")); if (sotmp != null && sotmp.getURI().equals(URIfilter)) { //System.out.println("Conservando elemento."); hmResults.put(sofil.getURI(), sofil); } else { //System.out.println("Quitando elemento"); hmRemove.put(sofil.getURI(), sofil); } } } } } } //limpiando el filtro hmfiltro = new HashMap(); Iterator itresults = hmResults.values().iterator(); while (itresults.hasNext()) { SemanticObject semObject = itresults.next(); if (hmRemove.get(semObject.getURI()) == null) { //pasando elementos válidos hmfiltro.put(semObject.getURI(), semObject); } } } itso = hmfiltro.values().iterator(); } else { itso = semmodel.listInstancesOfClass(sccol); //gobj.getSemanticObject().getModel().listInstancesOfClass(sccol); //sccol.listInstances(); } //PAGINACION List cplist = SWBUtils.Collections.copyIterator(itso); Set setso = null; if (sccol.isSubClass(Traceable.swb_Traceable)) { if (cplist.size() > 1) { setso = SWBComparator.sortByCreatedSet(cplist.iterator(), false); itso = setso.iterator(); } else { itso = cplist.iterator(); } } else { itso = cplist.iterator(); } int ps = 20; int l = cplist.size(); int p = 0; if (page != null) { p = Integer.parseInt(page); } int x = 0; //itso=setso.iterator(); ///////////////////////////////// while (itso.hasNext()) { semO = itso.next(); //PAGINACION //////////////////// if (x < p * ps) { x++; continue; } if (x == (p * ps + ps) || x == l) { break; } x++; ///////////////////////////////// out.println(""); out.println(""); //itcol = hmConfcol.keySet().iterator(); itcol = list.iterator(); while (itcol.hasNext()) { String scol = itcol.next(); if (hmConfcol.get(scol) != null) { out.println(""); } } out.println(""); } out.println(""); //boton para agregar instancia out.println("
"); out.println(" "); out.println(""); out.println(scol.getDisplayName(user.getLanguage())); out.println("
"); SWBResourceURL urlr = paramsRequest.getActionUrl(); urlr.setParameter("suri", id); urlr.setParameter("sval", semO.getURI()); urlr.setParameter("ract", action); //urlr.setParameter("page", ""+p); urlr.setAction("remove"); out.println("\"""); SWBResourceURL urlform = paramsRequest.getRenderUrl(); urlform.setMode(MODE_FORM); urlform.setParameter("suri", id); urlform.setParameter("clsuri", col.getCollectionClass().transformToSemanticClass().getURI()); urlform.setParameter("sval", semO.getURI()); urlform.setParameter("ract", action); urlform.setParameter("act", "edit"); out.println("\"""); out.println(""); out.println(reviewSemProp(hmConfcol.get(scol), semO, paramsRequest)); out.println("
"); out.println("
"); if (p > 0 || x < l) //Requiere paginacion { out.println("
"); out.println("
"); //int pages=(int)(l+ps/2)/ps; int pages = (int) (l / ps); if ((l % ps) > 0) { pages++; } for (int z = 0; z < pages; z++) { SWBResourceURL urlNew = paramsRequest.getRenderUrl(); urlNew.setParameter("suri", id); urlNew.setParameter("page", "" + z); urlNew.setParameter("act", "stpBusqueda"); urlNew.setParameter("search", busqueda); urlNew.setParameter("clsuri", sccol.getURI()); if (z != p) { out.println("" + (z + 1) + " "); } else { out.println((z + 1) + " "); } } out.println("
"); out.println("
"); } SWBResourceURL url = paramsRequest.getRenderUrl(); url.setParameter("act", "stpBusqueda"); url.setParameter("suri", id); url.setParameter("clsuri", sccol.getURI()); url.setMode(MODE_FORM); // SWBResourceURL urlback = paramsRequest.getRenderUrl(); // urlback.setParameter("act", "config"); // urlback.setParameter("suri", id); out.println("
"); out.println(""); // //out.println(""); // out.println("
"); out.println("
"); } else { out.println("
"); out.println("
"); out.println("" + paramsRequest.getLocaleString("errorMsgConfig") + " \"" + col.getDisplayTitle(user.getLanguage()) + "\" "); out.println("
    "); out.println("
  • "); out.println(paramsRequest.getLocaleString("msgMissingConfigProperties")); out.println("
  • "); out.println("
"); out.println("
"); SWBResourceURL urlreload = paramsRequest.getRenderUrl(); urlreload.setParameter("act", "config"); urlreload.setParameter("suri", id); out.println("
"); out.println(""); // out.println("
"); out.println("
"); } } } } /** * Gets the fE select. * * @param hmFE the hm fe * @param FEsel the f esel * @param user the user * @return the fE select */ public String getFESelect(HashMap hmFE, String FEsel, User user) { StringBuilder ret = new StringBuilder(); ret.append(""); Iterator itfe = hmFE.values().iterator(); while (itfe.hasNext()) { SemanticObject sofe = itfe.next(); ret.append(""); } return ret.toString(); } /** * Review sem prop. * * @param prop the prop * @param obj the obj * @param paramsRequest the params request * @return the string */ public String reviewSemProp(SemanticProperty prop, SemanticObject obj, SWBParamRequest paramsRequest) { String ret = null; try { SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss", new Locale(paramsRequest.getUser().getLanguage())); if (prop.isDataTypeProperty()) { if (prop.isBoolean()) { boolean bvalue = obj.getBooleanProperty(prop); if (bvalue) { ret = paramsRequest.getLocaleString("booleanYes"); } else { ret = paramsRequest.getLocaleString("booleanNo"); } } if (prop.isInt() || prop.isDouble() || prop.isLong()) { ret = Long.toString(obj.getLongProperty(prop)); } if (prop.isString()) { ret = obj.getProperty(prop); } if (prop.isFloat()) { ret = Float.toString(obj.getFloatProperty(prop)); } if (prop.isDate() || prop.isDateTime()) { ret = sdf.format(obj.getDateTimeProperty(prop)); } } else if (prop.isObjectProperty()) { SemanticObject so = obj.getObjectProperty(prop); if (null != so) { ret = so.getDisplayName(paramsRequest.getUser().getLanguage()); } } if (null == ret || (ret != null && ret.trim().equals("null"))) { ret = ""; } } catch (Exception e) { } if (ret == null || (ret != null && ret.trim().equals("null"))) { ret = ""; } return ret; } /** * Do form. * * @param request the request * @param response the response * @param paramRequest the param request * @throws SWBResourceException the sWB resource exception * @throws IOException Signals that an I/O exception has occurred. */ public void doForm(HttpServletRequest request, HttpServletResponse response, SWBParamRequest paramRequest) throws SWBResourceException, IOException { response.setContentType("text/html; charset=ISO-8859-1"); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); //System.out.println("doForm..."); PrintWriter out = response.getWriter(); User user = paramRequest.getUser(); String id = request.getParameter("suri"); String cid = request.getParameter("clsuri"); String act = request.getParameter("act"); String sval = request.getParameter("sval"); SemanticOntology ont = SWBPlatform.getSemanticMgr().getOntology(); SemanticObject obj = ont.getSemanticObject(sval); GenericObject go = ont.getGenericObject(sval); Collection col = null; if(go instanceof Collection) col = (Collection)go; SemanticClass sclass = null; if(col!=null) sclass = col.getCollectionClass().transformToSemanticClass(); else sclass = ont.getSemanticObject(cid).transformToSemanticClass(); SWBResourceURL urlPA = paramRequest.getActionUrl(); String modeform = null; if(act!=null&&act.equals("new")) { modeform = SWBFormMgr.MODE_CREATE; urlPA.setAction("new"); } else if(act!=null&&act.equals("edit")) { modeform = SWBFormMgr.MODE_EDIT; urlPA.setAction("updateform"); } //System.out.println("Modo: "+modeform); SWBFormMgr fmgr = new SWBFormMgr(obj,null,modeform); fmgr.setLang(user.getLanguage()); fmgr.setAction(urlPA.toString()); fmgr.setSubmitByAjax(false); fmgr.addButton(SWBFormButton.newSaveButton()); SWBResourceURL urlback = paramRequest.getRenderUrl(); urlback.setMode(SWBResourceURL.Mode_VIEW); urlback.setParameter("suri", id); if (null != cid) { urlback.setParameter("clsuri", cid); } if (null != act) { urlback.setParameter("act", act); } fmgr.addButton(SWBFormButton.newCancelButton().setAttribute("onclick", "window.location='" + urlback + "';")); fmgr.setType(SWBFormMgr.TYPE_DOJO); log.debug("new: suri: " + id); log.debug("new: clsuri: " + cid); log.debug("new: act: " + act); fmgr.addHiddenParameter("suri", id); fmgr.addHiddenParameter("clsuri", cid); fmgr.addHiddenParameter("ract", act); fmgr.addHiddenParameter("act", act!=null&&act.equals("new")?"new":"updateform"); fmgr.addHiddenParameter("sval", sval); out.println(fmgr.renderForm(request)); // Iterator it = fmgr.getProperties().iterator(); // while (it.hasNext()) { // SemanticProperty semProp = it.next(); // if(semProp.isDataTypeProperty()) // { // out.println(fmgr.getFormElement(semProp).renderElement(request, obj, semProp, act, modeform, null)); // out.println("
"); // out.println(fmgr.renderLabel(request, semProp, modeform)+": "+fmgr.renderElement(request, semProp.getName())); // out.println("
"); // } // else if(semProp.isObjectProperty()) // { // // // // } // // } // HashMap hmpg = fmgr.getGroups(); // out.println("
"); // Iterator itpg = hmpg.keySet().iterator(); // while (itpg.hasNext()) { // PropertyGroup pGroup = itpg.next(); // //out.println("groupid:"+pGroup.getId()); // //out.println("
"); // //out.println("indice"+pGroup.getIndex()); // //out.println("
"); // // //out.println("label:"+pGroup.getSemanticObject().getDisplayName(user.getLanguage())); // //out.println("
"); // out.println("
"); // out.println(""); // out.println(pGroup.getSemanticObject().getDisplayName(user.getLanguage())); // out.println(""); // out.println(""); // Iterator itsp = hmpg.get(pGroup).iterator(); // while (itsp.hasNext()) { // SemanticProperty semP = itsp.next(); // // out.println(""); // if(semP.isDataTypeProperty()) // { // out.println(""); // } // else if(semP.isObjectProperty()) // { // out.println(""); // SemanticClass sc = semP.getRangeClass(); // // Iterator so = sc.listProperties(); // while (so.hasNext()) { // SemanticProperty sp = so.next(); // if(sp.getName().equals("Estatus")||sp.getName().equals("comentario")) // { // out.println(fmgr.renderElement(request, sp.getName(), modeform)); // } // } // // out.println(""); // } // out.println(""); // // } // out.println("
" + semP.getLabel() + ":" + fmgr.renderElement(request, semP.getName(), modeform) + "" + semP.getLabel() + ":" + fmgr.renderElement(request, semP.getName(), modeform) + "
"); // out.println("
"); // } // out.println("
"); } /** * Process the mode request by the session user. * * @param request , this holds the parameters * @param response , an answer to the user request * @param paramRequest , a list of objects like user, webpage, Resource, ... * @throws SWBResourceException, a Resource Exception * @throws IOException, an In Out Exception * @throws SWBResourceException the sWB resource exception * @throws IOException Signals that an I/O exception has occurred. */ @Override public void processRequest(HttpServletRequest request, HttpServletResponse response, SWBParamRequest paramRequest) throws SWBResourceException, IOException { if (paramRequest.getMode().equals(MODE_FORM)) { doForm(request, response, paramRequest); } else { super.processRequest(request, response, paramRequest); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy