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  package org.apache.myfaces.view.facelets.compiler;
20  
21  import java.io.IOException;
22  
23  import javax.el.ELException;
24  import javax.faces.FacesException;
25  import javax.faces.component.UIComponent;
26  import javax.faces.component.UniqueIdVendor;
27  import javax.faces.view.facelets.FaceletContext;
28  import javax.faces.view.facelets.FaceletException;
29  
30  import org.apache.myfaces.view.facelets.FaceletCompositionContext;
31  import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
32  
33  final class UILiteralTextHandler extends AbstractUIHandler
34  {
35  
36      protected final String txtString;
37  
38      public UILiteralTextHandler(String txtString)
39      {
40          this.txtString = txtString;
41      }
42  
43      public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
44              ELException
45      {
46          if (parent != null)
47          {
48              UIComponent c = new UILiteralText(this.txtString);
49              UniqueIdVendor uniqueIdVendor
50                      = FaceletCompositionContext.getCurrentInstance(ctx).getUniqueIdVendorFromStack();
51              if (uniqueIdVendor == null)
52              {
53                  uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
54              }
55              if (uniqueIdVendor != null)
56              {
57                  // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
58                  // and call createUniqueId()
59                  String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null);
60                  c.setId(uid);
61              }
62              this.addComponent(ctx, parent, c);
63          }
64      }
65  
66      public String getText()
67      {
68          return this.txtString;
69      }
70  
71      public String getText(FaceletContext ctx)
72      {
73          return this.txtString;
74      }
75  }