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.custom.stylesheet;
20  
21  import javax.faces.component.UIComponentBase;
22  
23  import org.apache.myfaces.component.UserRoleAware;
24  import org.apache.myfaces.component.UserRoleUtils;
25  
26  
27  /**
28   * Renders the path to a common CSS-file
29   * 
30   * @JSFComponent
31   *   name = "t:stylesheet"
32   *   class = "org.apache.myfaces.custom.stylesheet.Stylesheet"
33   *   tagClass = "org.apache.myfaces.custom.stylesheet.StylesheetTag"
34   * @since 1.1.7
35   * @author mwessendorf (latest modification by $Author: lu4242 $)
36   * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (Wed, 03 Sep 2008) $
37   */
38  public abstract class AbstractStylesheet extends UIComponentBase
39      implements UserRoleAware    
40  {
41      public static final String COMPONENT_TYPE = "org.apache.myfaces.Stylesheet";
42      public static final String COMPONENT_FAMILY = "javax.faces.Output";
43      private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Stylesheet";
44  
45      /**
46       * URL for CSS-file.
47       * <p>
48       * If this path starts with a slash, then the webapp context path will be prepended to it.
49       * This makes it simple to reference stylesheets at an absolute path within the webapp.
50       * A value like "/styles/style.css" becomes "/webappname/styles/style.css".
51       * </p>
52       * <p>
53       * If this path does not start with a slash, then it is output unaltered. This supports
54       * absolute urls ("http://host/path/style.css"). It also supports having css files relative
55       * to the current page ("style.css" or "styles/style.css") but this needs to be used with
56       * care as the standard JSF postback/internal-forward navigation style can cause browsers
57       * to use an inappropriate base url when resolving relative references.
58       * </p> 
59       * 
60       * @JSFProperty
61       *   required="true"
62       */
63      public abstract String getPath();
64  
65      /**
66       * Inline the stylesheet file content as in contrast to referencing it as a link.
67       * <p>
68       * The file referenced by the path attribute is loaded, and its content is written
69       * to the page wrapped in an &lt;script&gt; tag.
70       * </p>
71       * <p>
72       * When this option is enabled, the path property must contain an absolute path
73       * within the current webapp. External urls ("http://*") and paths relative to the
74       * current page are not supported.
75       * </p>
76       * 
77       * @JSFProperty
78       *   defaultValue = "false"
79       */
80      public abstract boolean isInline();
81  
82      /**
83       * Cause EL expressions in the stylesheet to be evaluated.
84       * <p>
85       * When true, any EL expression in the stylesheet will be evaluated and replaced
86       * by its string representation on the first access. The stylesheet will be
87       * processed only once. Every subsequent request will get a cached view.
88       * </p>
89       * 
90       * @JSFProperty
91       *   defaultValue = "false"
92       */
93      public abstract boolean isFiltered();
94  
95      /**
96       * Define the target media of the styles:
97       *     <dl>
98       *       <dt>screen</dt>
99       *       <dd>Intended for non-paged computer screens.</dd>
100      *       <dt>tty</dt>
101      *       <dd>Intended for media using a fixed-pitch character grid, such
102      *         as teletypes, terminals, or portable devices with limited
103      *         display capabilities.</dd>
104      *       <dt>tv</dt>
105      *       <dd>Intended for television-type devices (low resolution,
106      *         color, limited scrollability).</dd>
107      *       <dt>projection</dt>
108      *       <dd>Intended for projectors.</dd>
109      *       <dt>handheld</dt>
110      *       <dd>Intended for handheld devices (small screen, monochrome,
111      *         bitmapped graphics, limited bandwidth).</dd>
112      *       <dt>print</dt>
113      *       <dd>Intended for paged, opaque material and for documents
114      *         viewed on screen in print preview mode.</dd>
115      *       <dt>braille</dt>
116      *       <dd>Intended for braille tactile feedback devices.</dd>
117      *       <dt>aural</dt>
118      *       <dd>Intended for speech synthesizers.</dd>
119      *       <dt>all</dt>
120      *       <dd>Suitable for all devices.</dd>
121      *     </dl>
122      *     Could be a comma separated list.
123      *     See also http://www.w3.org/TR/REC-html40/types.html#type-media-descriptors
124      * 
125      * @JSFProperty
126      */
127     public abstract String getMedia();
128 
129     public boolean isRendered()
130     {
131         if (!UserRoleUtils.isVisibleOnUserRole(this))
132         {
133             return false;
134         }
135         return super.isRendered();
136     }
137 
138 }