1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.portal.portlets;
1819import java.io.ByteArrayOutputStream;
20import java.io.PrintWriter;
2122import org.apache.ecs.html.Comment;
23import org.apache.ecs.ConcreteElement;
24import org.apache.ecs.StringElement;
25import org.apache.ecs.ElementContainer;
2627import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
28import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29import org.apache.jetspeed.services.logging.JetspeedLogger;
30import org.apache.jetspeed.util.SAXPIFilter;
3132import org.apache.turbine.util.RunData;
333435/***36Portlet to output an XML well-formed document without any rendering.37Strips all PIs and XML declaration before outputting content to allow38for inclusion in a wider XML document.3940@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*/43publicclassXMLPortletextendsAbstractPortlet44 {
45/***46 * Static initialization of the logger for this class47 */48privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(XMLPortlet.class.getName());
4950/***51 Return the PI-stripped XML document wrapped in an ECS ElementContainer52 */53public ConcreteElement getContent( RunData rundata ) {
5455 String myContent = null;
5657 ElementContainer content = new ElementContainer();
5859// Strip all PIs and XML declaration from the input XML content URL60try {
6162 ByteArrayOutputStream bos= new ByteArrayOutputStream();
6364 String url = JetspeedDiskCache.getInstance().getEntry( getPortletConfig().getURL() ).getURL();
6566newSAXPIFilter(new PrintWriter(bos),true).print( url );
67 myContent = bos.toString();
6869 } catch (Exception e) {
707172 logger.error( "Could not parse the following URL: " + this.getPortletConfig().getURL(), e );
73return content;
74 }
7576// If parsing is OK, wraps content in ECS element77if (myContent!=null) {
78 content = new ElementContainer();
7980 content.addElement( new Comment( "BEGIN PORTLET" ) );
81 content.addElement( new StringElement( myContent ) );
82 content.addElement( new Comment( "END PORTLET" ) );
83 }
8485return content;
86 }
8788/***89 Return the PI-stripped XML document wrapped in an ECS ElementContainer.90 Currently same as getContent()91 */92public ConcreteElement getContent(Object params, RunData rundata) {
93return getContent( rundata );
94 }
959697 }