![JAR search and dependency download from the Maven repository](/logo.png)
org.semanticwb.portal.resources.SWBSparQL Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SWBPortal Show documentation
Show all versions of SWBPortal Show documentation
SemanticWebBuilder Portal API components and utilities
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 java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.semanticwb.Logger;
import org.semanticwb.SWBUtils;
import org.semanticwb.model.Resource;
import org.semanticwb.portal.api.GenericResource;
import org.semanticwb.portal.api.SWBParamRequest;
import org.semanticwb.portal.api.SWBResourceException;
import com.hp.hpl.jena.query.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeSet;
import org.semanticwb.SWBPlatform;
import org.semanticwb.base.util.SFBase64;
import org.semanticwb.platform.SemanticModel;
// TODO: Auto-generated Javadoc
/**
* The Class SWBSparQL.
*
* @author juan.fernandez
*/
public class SWBSparQL extends GenericResource {
/** The log. */
private static Logger log=SWBUtils.getLogger(SWBSparQL.class);
/** The encryptor. */
private org.semanticwb.util.Encryptor encryptor = null;
/** The Constant NL. */
static public final String NL = System.getProperty("line.separator") ;
/** The Constant PRM_QUERY. */
public static final String PRM_QUERY="query";
/** The Constant PRM_ONTTYPE. */
public static final String PRM_ONTTYPE="onttype";
/** The Constant PRM_MODELS. */
public static final String PRM_MODELS="models";
/** The Constant OT_RDF. */
public static final String OT_RDF="rdf";
/** The Constant OT_ONTOLOGY. */
public static final String OT_ONTOLOGY="ontology";
/** The Constant OT_ONTRDFINF. */
public static final String OT_ONTRDFINF="ontrdfinf";
/** The Constant DPL_HEAD. */
public static final String DPL_HEAD="dplheader";
/** The Constant DPL_ITERATOR. */
public static final String DPL_ITERATOR="dpliterator";
/** The Constant DPL_FOOT. */
public static final String DPL_FOOT="dplfoot";
/** The model. */
private SemanticModel model=null;
/**
* Creates a new instance of WBADBQuery.
*/
public SWBSparQL()
{
//pedir llave en la administracion
// byte key[] = new java.math.BigInteger("05fe858d86df4b909a8c87cb8d9ad596", 16).toByteArray();
// encryptor = new org.semanticwb.util.Encryptor(key);
}
/**
* Creates the semantic model.
*/
public void createSemanticModel()
{
model=null;
String onttype=getResourceBase().getAttribute(PRM_ONTTYPE);
String smodels=getResourceBase().getAttribute(PRM_MODELS);
ArrayList amodels=new ArrayList();
if(smodels!=null)
{
StringTokenizer st=new StringTokenizer(smodels,"|");
while(st.hasMoreTokens())
{
String tk=st.nextToken();
amodels.add(tk);
}
}
if(amodels.size()==1)
{
if(onttype.equals(OT_RDF))
{
model=SWBPlatform.getSemanticMgr().getModel(amodels.get(0));
}
}else if(amodels.size()>1)
{
}
}
/**
* Gets the semantic model.
*
* @return the semantic model
*/
public SemanticModel getSemanticModel()
{
return model;
}
/* (non-Javadoc)
* @see org.semanticwb.portal.api.GenericResource#setResourceBase(org.semanticwb.model.Resource)
*/
@Override
public void setResourceBase(Resource base) throws SWBResourceException
{
super.setResourceBase(base);
createSemanticModel();
}
/* (non-Javadoc)
* @see org.semanticwb.portal.api.GenericResource#doAdmin(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.semanticwb.portal.api.SWBParamRequest)
*/
@Override
public void doAdmin(HttpServletRequest request, HttpServletResponse response, SWBParamRequest paramRequest) throws SWBResourceException, IOException
{
PrintWriter out=response.getWriter();
String query=getResourceBase().getAttribute(PRM_QUERY);
String onttype=getResourceBase().getAttribute(PRM_ONTTYPE);
String smodels=getResourceBase().getAttribute(PRM_MODELS);
String dplhead=getResourceBase().getAttribute(DPL_HEAD);
String dpliterator=getResourceBase().getAttribute(DPL_ITERATOR);
String dplfoot=getResourceBase().getAttribute(DPL_FOOT);
if(null==dplhead)
{
dplhead="\n" +
"\n" +
"Título Descripción \n" +
"\n";
}
if(null==dplfoot)
{
dplfoot="\n"+
"Registros encontrados: {rows.number} \n"+
"Tiempo de ejecución: {exec.time} milisegundos \n"+
"\n";
}
if(null==dpliterator)
{
dpliterator="{?title} {?desc} ";
}
if(null==query)
{
query = "PREFIX swb: \n"+
"PREFIX rdfs: \n"+
"PREFIX rdf: \n\n"+
"SELECT ?title ?desc WHERE {?x swb:title ?title. ?x rdf:type swb:WebPage. ?x swb:description ?desc}";
}
ArrayList amodels=new ArrayList();
if(smodels!=null)
{
StringTokenizer st=new StringTokenizer(smodels,"|");
while(st.hasMoreTokens())
{
String tk=st.nextToken();
amodels.add(tk);
}
}
String act=request.getParameter("act");
if(act!=null)
{
query=request.getParameter(PRM_QUERY);
getResourceBase().setAttribute(PRM_QUERY, query);
onttype=request.getParameter(PRM_ONTTYPE);
getResourceBase().setAttribute(PRM_ONTTYPE, onttype);
String models[]=request.getParameterValues(PRM_MODELS);
smodels="";
amodels=new ArrayList();
for(int x=0;x");
out.println(" dojo.require(\"dijit.form.Form\");");
out.println(" dojo.require(\"dijit.form.Button\");");
out.println("");
out.println("");
out.println("");
out.println("");
}
/**
* Do view.
*
* @param request the request
* @param response the response
* @param paramRequest the param request
* @throws IOException Signals that an I/O exception has occurred.
* @throws SWBResourceException the sWB resource exception
*/
@Override
public void doView(HttpServletRequest request, HttpServletResponse response, SWBParamRequest paramRequest) throws SWBResourceException, IOException {
PrintWriter out=response.getWriter();
String queryString=getResourceBase().getAttribute("query");
long time=System.currentTimeMillis();
long extime = 0;
try
{
if(queryString!=null && queryString.length()>0)
{
out.println("