/* * (c) Copyright 2010 Epimorphics Ltd. * All rights reserved. * [See end of file] */ package org.openjena.fuseki.mgt; import java.util.Iterator ; import javax.servlet.http.HttpServletRequest ; import javax.servlet.http.HttpSession ; import org.openjena.atlas.io.IndentedLineBuffer ; import org.openjena.fuseki.server.DatasetRegistry ; import com.hp.hpl.jena.shared.PrefixMapping ; import com.hp.hpl.jena.sparql.core.DatasetGraph ; import com.hp.hpl.jena.sparql.core.Prologue ; import com.hp.hpl.jena.sparql.serializer.PrologueSerializer ; import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ; /** Avoid code in JSPs */ public class Functions { /** Return the name of the current dataset */ public static String dataset(HttpServletRequest request, String dftValue) { String ds = dataset(request) ; if ( ds == null ) return dftValue ; return ds ; } /** Return the name of the current dataset */ public static String dataset(HttpServletRequest request) { HttpSession session = request.getSession(false) ; if ( session == null ) return "No session"; String ds = (String)session.getAttribute("dataset") ; return ds ; } /** Return lists of datasets */ public static String datasetsAsSelectOptions(HttpServletRequest request) { StringBuilder buff = new StringBuilder() ; Iterator iter = DatasetRegistry.get().keys() ; for ( ; iter.hasNext() ; ) { String name = iter.next() ; buff.append("") ; } return buff.toString() ; } /** Return lists of datasets */ public static String datasetsAsListItems(HttpServletRequest request) { StringBuilder buff = new StringBuilder() ; Iterator iter = DatasetRegistry.get().keys() ; for ( ; iter.hasNext() ; ) { String name = iter.next() ; buff.append("
  • "+name+"
  • ") ; } return buff.toString() ; } /** Return prefixes for the datasets, SPARQL syntax. */ public static String prefixes(HttpServletRequest request) { String dsName = dataset(request) ; DatasetGraph dsg = DatasetRegistry.get().get(dsName) ; if ( dsg instanceof DatasetGraphTDB ) { PrefixMapping pmap = ((DatasetGraphTDB)dsg).getPrefixes().getPrefixMapping() ; Prologue prologue = new Prologue(pmap) ; IndentedLineBuffer buff = new IndentedLineBuffer() ; PrologueSerializer.output(buff, prologue) ; buff.append("\n") ; return buff.asString() ; } return "" ; } } /* * (c) Copyright 2010 Epimorphics Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */