Commit 484ce70e authored by gmantele's avatar gmantele
Browse files

[TAP] Allow setting an XSLT stylesheet for /capabilities and /tables.

parent 6ba9bffb
Loading
Loading
Loading
Loading
+29 −5
Original line number Diff line number Diff line
@@ -16,14 +16,16 @@ package tap.config;
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright 2015 - Astronomisches Rechen Institut (ARI)
 * Copyright 2015-2016 - Astronomisches Rechen Institut (ARI)
 */

import static tap.config.TAPConfiguration.DEFAULT_TAP_CONF_FILE;
import static tap.config.TAPConfiguration.KEY_ADD_TAP_RESOURCES;
import static tap.config.TAPConfiguration.KEY_CAPABILITIES_STYLESHEET;
import static tap.config.TAPConfiguration.KEY_EXAMPLES;
import static tap.config.TAPConfiguration.KEY_HOME_PAGE;
import static tap.config.TAPConfiguration.KEY_HOME_PAGE_MIME_TYPE;
import static tap.config.TAPConfiguration.KEY_TABLES_STYLESHEET;
import static tap.config.TAPConfiguration.TAP_CONF_PARAMETER;
import static tap.config.TAPConfiguration.getProperty;
import static tap.config.TAPConfiguration.isClassName;
@@ -58,7 +60,7 @@ import tap.resource.TAPResource;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 2.1 (11/2015)
 * @version 2.1 (07/2016)
 * @since 2.0
 */
public class ConfigurableTAPServlet extends HttpServlet {
@@ -151,7 +153,10 @@ public class ConfigurableTAPServlet extends HttpServlet {
			}
		}

		/* 4Ter. SET THE EXAMPLES ENDPOINT (if any) */
		/* 4Ter. SET THE XSLT for /capabilities and /tables */
		initXSLTStylesheet(tapConf);

		/* 4Quater. SET THE EXAMPLES ENDPOINT (if any) */
		propValue = getProperty(tapConf, KEY_EXAMPLES);
		if (propValue != null)
			tap.addResource(new Examples(tap, propValue));
@@ -219,6 +224,25 @@ public class ConfigurableTAPServlet extends HttpServlet {
		return input;
	}

	/**
	 * Initialize the XSLT for /capabilities and /tables.
	 * 
	 * @param tapConfig	The content of the TAP configuration file.
	 * 
	 * @since 2.1
	 */
	protected void initXSLTStylesheet(final Properties tapConfig){
		// Set the XSLT of /capabilities:
		String propValue = getProperty(tapConfig, KEY_CAPABILITIES_STYLESHEET);
		if (propValue != null)
			tap.getCapabilities().setXSLTPath(propValue);

		// Set the XSLT of /tables:
		propValue = getProperty(tapConfig, KEY_TABLES_STYLESHEET);
		if (propValue != null)
			tap.getTAPMetadata().setXSLTPath(propValue);
	}

	@Override
	public void destroy(){
		// Free all resources used by TAP:
+7 −3
Original line number Diff line number Diff line
@@ -272,6 +272,10 @@ public final class TAPConfiguration {
	public final static String VALUE_ANY = "ANY";

	/* ADDITIONAL TAP RESOURCES */
	/** Name/Key of the property specifying the XSLT stylesheet to use for /capabilities. */
	public final static String KEY_CAPABILITIES_STYLESHEET = "capabilities_stylesheet";
	/** Name/Key of the property specifying the XSLT stylesheet to use for /tables. */
	public final static String KEY_TABLES_STYLESHEET = "tables_stylesheet";
	/** Name/Key of the property specifying a list of resources to add to the TAP service (e.g. a ADQL query validator).
	 * By default, this list if empty ; only the default TAP resources exist. */
	public final static String KEY_ADD_TAP_RESOURCES = "additional_resources";
+20 −0
Original line number Diff line number Diff line
@@ -670,6 +670,26 @@
			</tr>
			
			<tr><td colspan="5">Additional TAP Resources</td></tr>
			<tr class="optional">
				<td class="done">capabilities_stylesheet</td>
				<td></td>
				<td>text</td>
				<td>
					<p>URL of the XSLT stylesheet to link with the XML output of /capabilities.</p>
					<p><em>By default, no XSLT stylesheet is defined.</em></p>
				</td>
				<td><ul><li>http://mytap.com/myCapabilities.xslt</li></ul></td>
			</tr>
			<tr class="optional">
				<td class="done">tables_stylesheet</td>
				<td></td>
				<td>text</td>
				<td>
					<p>URL of the XSLT stylesheet to link with the XML output of /tables.</p>
					<p><em>By default, no XSLT stylesheet is defined.</em></p>
				</td>
				<td><ul><li>http://mytap.com/myTables.xslt</li></ul></td>
			</tr>
			<tr class="optional">
				<td class="done">examples</td>
				<td></td>
+13 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#             FULL TAP CONFIGURATION FILE                #
#                                                        #
# TAP Version: 2.1                                       #
# Date: 18 Nov. 2015                                     #
# Date: 18 July 2016                                     #
# Author: Gregory Mantelet (ARI)                         #
#                                                        #
########################################################## 
@@ -507,6 +507,18 @@ udfs =
# ADDITIONAL RESOURCES #
########################

# [OPTIONAL]
# URL of the XSLT stylesheet to link with the XML output of /capabilities.
# 
# By default, no XSLT stylesheet is defined.
capabilities_stylesheet = 

# [OPTIONAL]
# URL of the XSLT stylesheet to link with the XML output of /tables.
# 
# By default, no XSLT stylesheet is defined.
tables_stylesheet = 

# [OPTIONAL]
# This property lets add an <code>/examples</code> endpoint by specifying an XHTML-RDFa
# document listing TAP query examples using the syntax specified by TAPNotes 1.0 DALI 1.0.
+38 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour
	 * By default, it is the resource name ; so here, the corresponding TAP URI would be: "/tables". */
	protected String accessURL = getName();

	/** The path of the XSLT style-sheet to apply.
	 * @version 2.1 */
	protected String xsltPath = null;

	/**
	 * <p>Build an empty list of metadata.</p>
	 * 
@@ -105,6 +109,34 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour
		schemas = new LinkedHashMap<String,TAPSchema>();
	}

	/**
	 * Gets the path/URL of the XSLT style-sheet to use.
	 * 
	 * @return	XSLT path/url.
	 * 
	 * @version 2.1
	 */
	public final String getXSLTPath(){
		return xsltPath;
	}

	/**
	 * Sets the path/URL of the XSLT style-sheet to use.
	 * 
	 * @param path	The new XSLT path/URL.
	 * 
	 * @version 2.1
	 */
	public final void setXSLTPath(final String path){
		if (path == null)
			xsltPath = null;
		else{
			xsltPath = path.trim();
			if (xsltPath.isEmpty())
				xsltPath = null;
		}
	}

	/**
	 * <p>Add the given schema inside this TAP metadata set.</p>
	 * 
@@ -476,6 +508,12 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour
	public void write(final PrintWriter writer) throws IOException{
		writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

		if (xsltPath != null){
			writer.print("<?xml-stylesheet type=\"text/xsl\" ");
			writer.print(VOSerializer.formatAttribute("href", xsltPath));
			writer.println("?>");
		}

		/* TODO The XSD schema for VOSITables should be fixed soon! This schema should be changed here before the library is released!
		 * Note: the XSD schema at http://www.ivoa.net/xml/VOSITables/v1.0 contains an incorrect targetNamespace ("http://www.ivoa.net/xml/VOSICapabilities/v1.0").
		 *       In order to make this XML document valid, a custom location toward a correct XSD schema is used: http://vo.ari.uni-heidelberg.de/docs/schemata/VOSITables-v1.0.xsd */
Loading