View Javadoc

1   /*
2    * Copyright 2000-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 at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * 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 and
14   * limitations under the License.
15   */
16  
17  package org.apache.jetspeed.modules.layouts;
18  
19  //jetspeed stuff
20  import org.apache.jetspeed.capability.CapabilityMap;
21  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
22  import org.apache.jetspeed.services.logging.JetspeedLogger;
23  import org.apache.jetspeed.services.rundata.JetspeedRunData;
24  import org.apache.jetspeed.services.resources.JetspeedResources;
25  import org.apache.jetspeed.util.MimeType;
26  
27  // Turbine
28  import org.apache.turbine.modules.Layout;
29  import org.apache.turbine.modules.NavigationLoader;
30  import org.apache.turbine.modules.ScreenLoader;
31  import org.apache.turbine.util.RunData;
32  
33  // ECS Classes
34  import org.apache.ecs.*;
35  import org.apache.ecs.wml.*;
36  import org.apache.ecs.xml.*;
37  
38  /***
39   * Legacy jetspeed Layout used when handling ECS-only content.
40   * You should not use it if you want to use Velocity or JSPs.
41   *
42   * @deprecated This layout is not used anymore in Jetspeed
43   * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
44   * @author <a href="mailto:raphael@apache.org">Raphaël Lute</a>
45   * @version $Id: JetspeedLayout.java,v 1.13 2004/02/23 02:59:30 jford Exp $
46   */
47  public class JetspeedLayout extends Layout
48  {
49  
50      public static final String TOP =
51          JetspeedResources.getString( JetspeedResources.NAVIGATIONS_TOP_KEY );
52  
53      public static final String BOTTOM =
54          JetspeedResources.getString( JetspeedResources.NAVIGATIONS_BOTTOM_KEY );
55  
56      /***
57          The Doctype of WML
58      */
59      public static final Doctype WML_DOCTYPE =
60          new Doctype( "wml",
61                       "PUBLIC",
62                       "\"-//WAPFORUM//DTD WML 1.1//EN\"",
63                       "\"http://www.wapforum.org/DTD/wml_1.1.xml\"" );
64  
65  
66      /***
67       * Static initialization of the logger for this class
68       */    
69      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedLayout.class.getName());     
70      
71      /***
72       * 
73       */        
74      public void doBuild( RunData data ) throws Exception
75      {
76  
77          CapabilityMap cm = ((JetspeedRunData)data).getCapability();
78  
79          MimeType mt = cm.getPreferredType();
80          data.setContentType( mt.getContentType() );
81          data.setCharSet( mt.getCharSet() );
82  
83          if ( logger.isDebugEnabled() )
84          {
85              logger.debug( "Layout: Setting type to: " + mt );
86          }
87  
88          if ( mt.equals( MimeType.WML ) ) {
89              // we should output WML code, use raw output
90              // don"t use navigations for WML
91  
92              ElementContainer ec = new ElementContainer();
93              WML wml = new WML();
94              ec.addElement( new PI().setVersion( 1.0 ) );
95              ec.addElement( WML_DOCTYPE );
96              ec.addElement( wml );
97              wml.addElement( new Template().addElement( new Do( DoType.ACCEPT, "Back" ).addElement( new Prev() ) ) );
98  
99              // Now execute the Screen portion of the page
100             ConcreteElement screen = ScreenLoader.getInstance().eval ( data, data.getScreen() );
101             if (screen != null)
102                 wml.addElement( screen );
103 
104             // output everything on stdout
105             try {
106                 ec.output( data.getOut() );
107             } catch ( java.io.IOException e ) {
108                 logger.error("Exception",  e);
109             } finally {
110                 ec = null;
111             }
112 
113         } else {
114 
115             // Execute the Top Navigation portion for this Layout
116             ConcreteElement topNav =
117                 NavigationLoader.getInstance().eval ( data, TOP );
118             if ( topNav != null)
119                 data.getPage().getBody().addElement( topNav );
120 
121             // Now execute the Screen portion of the page
122             ConcreteElement screen = ScreenLoader.getInstance().eval ( data, data.getScreen() );
123             if (screen != null)
124                 data.getPage().getBody().addElement( screen );
125 
126             // The screen should have attempted to set a Title
127             // for itself, otherwise, a default title is set
128             data.getPage().getTitle()
129                 .addElement( data.getTitle() );
130 
131             // The screen should have attempted to set a Body bgcolor
132             // for itself, otherwise, a default body bgcolor is set
133             data.getPage().getBody()
134                 .setBgColor(HtmlColor.white);
135 
136             // Execute the Bottom Navigation portion for this Layout
137             ConcreteElement bottomNav =
138             NavigationLoader.getInstance().eval ( data, BOTTOM );
139             if ( bottomNav != null)
140                 data.getPage().getBody().addElement( bottomNav );
141         }
142     }
143 
144 }