Skip to content
Snippets Groups Projects
Commit 404db993 authored by gmantele's avatar gmantele
Browse files

[UWS] Ensure optional MIME-type and size are set in the XML and JSON

serialization of all results if such information are available.

This commit also fix few comments about the result's XML serialization.

The processing of xlink:type of a result reference is made similar as the one of
jobRef.
parent f6a089c1
No related branches found
No related tags found
No related merge requests found
...@@ -2,20 +2,20 @@ package org.json; ...@@ -2,20 +2,20 @@ package org.json;
/* /*
* This file is part of UWSLibrary. * This file is part of UWSLibrary.
* *
* UWSLibrary is free software: you can redistribute it and/or modify * UWSLibrary is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* UWSLibrary is distributed in the hope that it will be useful, * UWSLibrary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI) * Astronomisches Rechen Institut (ARI)
*/ */
...@@ -35,9 +35,9 @@ import uws.service.UWSUrl; ...@@ -35,9 +35,9 @@ import uws.service.UWSUrl;
/** /**
* Useful conversion functions from UWS to JSON. * Useful conversion functions from UWS to JSON.
* *
* @author Gr&eacute;gory Mantelet (CDS;ARI) * @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 4.2 (06/2017) * @version 4.2 (09/2017)
*/ */
public final class Json4Uws { public final class Json4Uws {
...@@ -150,24 +150,24 @@ public final class Json4Uws { ...@@ -150,24 +150,24 @@ public final class Json4Uws {
/** /**
* Gets the JSON representation of the jobInfo of the given job. * Gets the JSON representation of the jobInfo of the given job.
* *
* <p><b>Important note:</b> * <p><b>Important note:</b>
* This function transforms the XML returned by * This function transforms the XML returned by
* {@link JobInfo#getXML(String)} into a JSON object * {@link JobInfo#getXML(String)} into a JSON object
* (see {@link XML#toJSONObject(String)}). * (see {@link XML#toJSONObject(String)}).
* </p> * </p>
* *
* @param job The job whose the jobInfo must be represented * @param job The job whose the jobInfo must be represented
* in JSON. * in JSON.
* *
* @return The JSON representation of its jobInfo. * @return The JSON representation of its jobInfo.
* *
* @throws JSONException If there is an error while building the JSON * @throws JSONException If there is an error while building the JSON
* object. * object.
* *
* @see JobInfo#getXML(String) * @see JobInfo#getXML(String)
* @see XML#toJSONObject(String) * @see XML#toJSONObject(String)
* *
* @since 4.2 * @since 4.2
*/ */
public final static JSONObject getJobInfoJson(final UWSJob job) throws JSONException{ public final static JSONObject getJobInfoJson(final UWSJob job) throws JSONException{
...@@ -242,7 +242,8 @@ public final class Json4Uws { ...@@ -242,7 +242,8 @@ public final class Json4Uws {
resultJson.put("id", r.getId()); resultJson.put("id", r.getId());
resultJson.put("type", r.getType()); resultJson.put("type", r.getType());
resultJson.put("href", r.getHref()); resultJson.put("href", r.getHref());
resultJson.put("mime", r.getMimeType()); if (r.getMimeType() != null)
resultJson.put("mime-type", r.getMimeType());
if (r.getSize() >= 0) if (r.getSize() >= 0)
resultJson.put("size", r.getSize()); resultJson.put("size", r.getSize());
resultJson.put("redirection", r.isRedirectionRequired()); resultJson.put("redirection", r.isRedirectionRequired());
......
...@@ -393,10 +393,21 @@ public class XMLSerializer extends UWSSerializer { ...@@ -393,10 +393,21 @@ public class XMLSerializer extends UWSSerializer {
} }
// otherwise, just return the XML parameter description: // otherwise, just return the XML parameter description:
else{ else{
buf.append("<parameter").append(getUWSNamespace(root)).append(" id=\"").append(escapeXMLAttribute(paramName)); buf.append("<parameter").append(getUWSNamespace(root)).append(" id=\"").append(escapeXMLAttribute(paramName)).append('"');
// set if it is an uploaded file:
if (paramValue instanceof UploadFile) if (paramValue instanceof UploadFile)
buf.append("\" byReference=\"true"); buf.append(" byReference=\"true");
buf.append("\">").append(escapeXMLData(paramValue.toString())).append("</parameter>");
/*
* Note:
* The attribute isPost is not supported in this library.
* This information is not stored by the UWS Library and
* so is never reported in the XML serialization of the
* job. Besides, this attribute is optional.
*/
buf.append('>').append(escapeXMLData(paramValue.toString())).append("</parameter>");
} }
return buf.toString(); return buf.toString();
} }
...@@ -423,20 +434,21 @@ public class XMLSerializer extends UWSSerializer { ...@@ -423,20 +434,21 @@ public class XMLSerializer extends UWSSerializer {
public String getResult(final Result result, final boolean root){ public String getResult(final Result result, final boolean root){
StringBuffer xml = new StringBuffer(root ? getHeader() : ""); StringBuffer xml = new StringBuffer(root ? getHeader() : "");
xml.append("<result").append(getUWSNamespace(root)).append(" id=\"").append(escapeXMLAttribute(result.getId())).append('"'); xml.append("<result").append(getUWSNamespace(root)).append(" id=\"").append(escapeXMLAttribute(result.getId())).append('"');
/* The XLink attributes are optional. So if no URL is available, none
* will be written here: */
if (result.getHref() != null){ if (result.getHref() != null){
if (result.getType() != null) xml.append(" xlink:type=\"").append((result.getType() == null) ? "simple" : escapeXMLAttribute(result.getType())).append('"');
xml.append(" xlink:type=\"").append(escapeXMLAttribute(result.getType())).append('"');
xml.append(" xlink:href=\"").append(escapeXMLAttribute(result.getHref())).append('"'); xml.append(" xlink:href=\"").append(escapeXMLAttribute(result.getHref())).append('"');
} }
/* NOTE: THE FOLLOWING ATTRIBUTES MAY PROVIDE USEFUL INFORMATION TO USERS, BUT THEY ARE NOT ALLOWED BY THE CURRENT UWS STANDARD. // Append the MIME type, if any:
* HOWEVER, IF, ONE DAY, THEY ARE, THE FOLLOWING LINES SHOULD BE UNCOMNENTED. if (result.getMimeType() != null)
* xml.append(" mime-type=\"").append(escapeXMLAttribute(result.getMimeType())).append('"');
* if (result.getMimeType() != null)
* xml.append(" mime=\"").append(escapeXMLAttribute(result.getMimeType())).append("\""); // Append the result size (in bytes), if any:
* if (result.getSize() >= 0) if (result.getSize() >= 0)
* xml.append(" size=\"").append(result.getSize()).append("\""); xml.append(" size=\"").append(result.getSize()).append('"');
*/
return xml.append(" />").toString(); return xml.append(" />").toString();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment