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
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import uws.service.UWSUrl;
 * Useful conversion functions from UWS to JSON.
 *
 * @author Grégory Mantelet (CDS;ARI)
 * @version 4.2 (06/2017)
 * @version 4.2 (09/2017)
 */
public final class Json4Uws {

@@ -242,7 +242,8 @@ public final class Json4Uws {
			resultJson.put("id", r.getId());
			resultJson.put("type", r.getType());
			resultJson.put("href", r.getHref());
			resultJson.put("mime", r.getMimeType());
			if (r.getMimeType() != null)
				resultJson.put("mime-type", r.getMimeType());
			if (r.getSize() >= 0)
				resultJson.put("size", r.getSize());
			resultJson.put("redirection", r.isRedirectionRequired());
+25 −13
Original line number Diff line number Diff line
@@ -393,10 +393,21 @@ public class XMLSerializer extends UWSSerializer {
				}
				// otherwise, just return the XML parameter description:
				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)
						buf.append("\" byReference=\"true");
					buf.append("\">").append(escapeXMLData(paramValue.toString())).append("</parameter>");
						buf.append(" byReference=\"true");

					/*
					 * 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();
			}
@@ -423,20 +434,21 @@ public class XMLSerializer extends UWSSerializer {
	public String getResult(final Result result, final boolean root){
		StringBuffer xml = new StringBuffer(root ? getHeader() : "");
		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.getType() != null)
				xml.append(" xlink:type=\"").append(escapeXMLAttribute(result.getType())).append('"');
			xml.append(" xlink:type=\"").append((result.getType() == null) ? "simple" : escapeXMLAttribute(result.getType())).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.
		 *       HOWEVER, IF, ONE DAY, THEY ARE, THE FOLLOWING LINES SHOULD BE UNCOMNENTED.
		 *
		 * if (result.getMimeType() != null)
		 * 	xml.append(" mime=\"").append(escapeXMLAttribute(result.getMimeType())).append("\"");
		 * if (result.getSize() >= 0)
		 * 	xml.append(" size=\"").append(result.getSize()).append("\"");
		 */
		// Append the MIME type, if any:
		if (result.getMimeType() != null)
			xml.append(" mime-type=\"").append(escapeXMLAttribute(result.getMimeType())).append('"');

		// Append the result size (in bytes), if any:
		if (result.getSize() >= 0)
			xml.append(" size=\"").append(result.getSize()).append('"');

		return xml.append(" />").toString();
	}