1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portal.portlets;
18
19 import java.io.ByteArrayOutputStream;
20 import java.io.PrintWriter;
21
22 import org.apache.ecs.html.Comment;
23 import org.apache.ecs.ConcreteElement;
24 import org.apache.ecs.StringElement;
25 import org.apache.ecs.ElementContainer;
26
27 import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29 import org.apache.jetspeed.services.logging.JetspeedLogger;
30 import org.apache.jetspeed.util.SAXPIFilter;
31
32 import org.apache.turbine.util.RunData;
33
34
35 /***
36 Portlet to output an XML well-formed document without any rendering.
37 Strips all PIs and XML declaration before outputting content to allow
38 for inclusion in a wider XML document.
39
40 @author <A HREF="mailto:raphael@apache.org">Raphaël Luta</A>
41 @version $Id: XMLPortlet.java,v 1.21 2004/02/23 04:03:34 jford Exp $
42 */
43 public class XMLPortlet extends AbstractPortlet
44 {
45 /***
46 * Static initialization of the logger for this class
47 */
48 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(XMLPortlet.class.getName());
49
50 /***
51 Return the PI-stripped XML document wrapped in an ECS ElementContainer
52 */
53 public ConcreteElement getContent( RunData rundata ) {
54
55 String myContent = null;
56
57 ElementContainer content = new ElementContainer();
58
59
60 try {
61
62 ByteArrayOutputStream bos= new ByteArrayOutputStream();
63
64 String url = JetspeedDiskCache.getInstance().getEntry( getPortletConfig().getURL() ).getURL();
65
66 new SAXPIFilter(new PrintWriter(bos),true).print( url );
67 myContent = bos.toString();
68
69 } catch (Exception e) {
70
71
72 logger.error( "Could not parse the following URL: " + this.getPortletConfig().getURL(), e );
73 return content;
74 }
75
76
77 if (myContent!=null) {
78 content = new ElementContainer();
79
80 content.addElement( new Comment( "BEGIN PORTLET" ) );
81 content.addElement( new StringElement( myContent ) );
82 content.addElement( new Comment( "END PORTLET" ) );
83 }
84
85 return content;
86 }
87
88 /***
89 Return the PI-stripped XML document wrapped in an ECS ElementContainer.
90 Currently same as getContent()
91 */
92 public ConcreteElement getContent(Object params, RunData rundata) {
93 return getContent( rundata );
94 }
95
96
97 }