View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.orchestra.flow.components;
21  
22  import javax.el.ELContext;
23  import javax.faces.webapp.UIComponentELTag;
24  import javax.servlet.jsp.JspException;
25  import javax.servlet.jsp.PageContext;
26  import javax.servlet.jsp.tagext.BodyTag;
27  
28  /**
29   * Tag which creates a FlowCallComponent instance.
30   * <p>
31   * Note that JSP tag-handlers are invoked on every render of a view. 
32   */
33  public class FlowCallTag extends UIComponentELTag
34  {
35      private PageContext pageContext;
36  
37      private String outcome;
38      private String viewId;
39      private String service;
40  
41      @Override
42      public void setPageContext(PageContext pageContext)
43      {
44          super.setPageContext(pageContext);
45          this.pageContext = pageContext;
46      }
47  
48      @Override
49      public String getComponentType()
50      {
51          return FlowCallComponent.COMPONENT_TYPE;
52      }
53  
54      @Override
55      public String getRendererType()
56      {
57          return null;
58      }
59  
60      public void setOutcome(String outcome)
61      {
62          this.outcome = outcome;
63      }
64  
65      public void setViewId(String viewId)
66      {
67          this.viewId = viewId;
68      }
69  
70      public void setService(String service)
71      {
72          this.service = service;
73      }
74  
75      @Override
76      protected int getDoStartValue()
77      throws JspException
78      {
79          // Note that the .tld file is expected to declare this tag with
80          // body-content=tagdependent in order to avoid evaluating EL
81          // expressions within the body..
82          return BodyTag.EVAL_BODY_BUFFERED;
83      }
84  
85      @Override
86      public int doAfterBody() throws JspException
87      {
88          FlowCallComponent component = (FlowCallComponent) getComponentInstance();
89          if (!component.isInitialized())
90          {
91              ELContext elContext = pageContext.getELContext();
92  
93              component.setOutcome(outcome);
94              component.setViewId(viewId);
95              component.setService(service);
96  
97              String bodyText = bodyContent.getString();
98              
99              StringBuffer buf = new StringBuffer();
100             buf.append("<flowCall>\n");
101             buf.append(bodyText);
102             buf.append("</flowCall>");
103             String xml = buf.toString();
104             component.setBody(elContext, xml);
105         }
106 
107         return 0;
108     }
109 }