1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.restlet.ext.wadl;
20
21 import fr.cnes.doi.utils.spec.Requirement;
22 import java.io.IOException;
23 import java.net.URL;
24 import java.util.logging.Level;
25 import org.restlet.Context;
26 import org.restlet.data.MediaType;
27 import org.restlet.engine.Engine;
28 import org.restlet.ext.xml.TransformRepresentation;
29 import org.restlet.ext.xml.XmlRepresentation;
30 import org.restlet.representation.EmptyRepresentation;
31 import org.restlet.representation.InputRepresentation;
32 import org.restlet.representation.Representation;
33
34
35
36
37
38
39 @Requirement(reqId = Requirement.DOI_DOC_010, reqName = Requirement.DOI_DOC_010_NAME)
40 public class WadlCnesRepresentation extends WadlRepresentation {
41
42
43
44
45
46
47 public WadlCnesRepresentation(final ApplicationInfo application) {
48 super(application);
49 }
50
51
52
53
54
55
56 @Override
57 public Representation getHtmlRepresentation() {
58 Representation representation;
59 final URL wadl2htmlXsltUrl = Engine
60 .getResource("org/restlet/ext/wadl/wadlcnes2html.xslt");
61
62 if (wadl2htmlXsltUrl == null) {
63 representation = new EmptyRepresentation();
64 } else {
65 try {
66 setSaxSource(XmlRepresentation.getSaxSource(this));
67 final InputRepresentation xslRep = new InputRepresentation(
68 wadl2htmlXsltUrl.openStream(),
69 MediaType.APPLICATION_W3C_XSLT);
70 representation = new TransformRepresentation(
71 Context.getCurrent(), this, xslRep);
72 representation.setMediaType(MediaType.TEXT_HTML);
73 } catch (IOException e) {
74 Context.getCurrentLogger().log(Level.WARNING,
75 "Unable to generate the WADL HTML representation",
76 e);
77 representation = new EmptyRepresentation();
78 }
79 }
80
81 return representation;
82 }
83
84 }