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.document;
20
21 import javax.faces.component.UIComponentBase;
22 import javax.faces.context.FacesContext;
23
24 /**
25 * Base class to handle the document family
26 *
27 * @JSFComponent
28 * tagClass = "org.apache.myfaces.custom.document.AbstractDocumentTag"
29 * configExcluded = "true"
30 *
31 * @author Mario Ivankovits (latest modification by $Author: skitching $)
32 * @version $Revision: 673833 $ $Date: 2008-07-03 16:58:05 -0500 (Thu, 03 Jul 2008) $
33 */
34 public class AbstractDocument extends UIComponentBase
35 {
36 private String _state = null;
37
38 public static final String COMPONENT_FAMILY = "javax.faces.Data";
39
40 public AbstractDocument(String renderType)
41 {
42 setRendererType(renderType);
43 }
44
45 public String getFamily()
46 {
47 return COMPONENT_FAMILY;
48 }
49
50 public void setState(String state)
51 {
52 _state = state;
53 }
54
55 /**
56 * state="start|end". Used to demarkate the document boundaries
57 *
58 * @JSFProperty
59 * literalOnly = "true"
60 */
61 public String getState()
62 {
63 return _state;
64 }
65
66 public boolean hasState()
67 {
68 return isStartState() || isEndState();
69 }
70
71 public boolean isStartState()
72 {
73 return "start".equals(getState());
74 }
75
76 public boolean isEndState()
77 {
78 return "end".equals(getState());
79 }
80
81 public Object saveState(FacesContext context)
82 {
83 Object values[] = new Object[2];
84 values[0] = super.saveState(context);
85 values[1] = _state;
86 return values;
87 }
88
89 public void restoreState(FacesContext context, Object state)
90 {
91 Object values[] = (Object[]) state;
92 super.restoreState(context, values[0]);
93 _state = (String) values[1];
94 }
95 }