KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > properties > StringProperty


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: StringProperty.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.fo.FObj;
23 import org.apache.fop.fo.PropertyList;
24
25 /**
26  * Exists primarily as a container for its Maker inner class, which is
27  * extended by many string-based FO property classes.
28  */

29 public class StringProperty extends Property {
30
31     /**
32      * Inner class for making instances of StringProperty
33      */

34     public static class Maker extends PropertyMaker {
35
36         /**
37          * @param propId the id of the property for which a Maker should be created
38          */

39         public Maker(int propId) {
40             super(propId);
41         }
42
43         /**
44          * Make a new StringProperty object
45          * @param propertyList not used
46          * @param value String value of the new object
47          * @param fo not used
48          * @return the StringProperty object
49          */

50         public Property make(PropertyList propertyList, String JavaDoc value,
51                              FObj fo) {
52             // Work around the fact that most String properties are not
53
// specified as actual String literals (with "" or '') since
54
// the attribute values themselves are Strings!
55
// If the value starts with ' or ", make sure it also ends with
56
// this character
57
// Otherwise, just take the whole value as the String
58
int vlen = value.length() - 1;
59             if (vlen > 0) {
60                 char q1 = value.charAt(0);
61                 if (q1 == '"' || q1 == '\'') {
62                     if (value.charAt(vlen) == q1) {
63                         return new StringProperty(value.substring(1, vlen));
64                     }
65                     log.warn("String-valued property starts with quote"
66                                        + " but doesn't end with quote: "
67                                        + value);
68                     // fall through and use the entire value, including first quote
69
}
70                 String JavaDoc str = checkValueKeywords(value);
71                 if (str != null) {
72                     value = str;
73                 }
74             }
75             return new StringProperty(value);
76         }
77
78     } // end String.Maker
79

80     private String JavaDoc str;
81
82     /**
83      * @param str String value to place in this object
84      */

85     public StringProperty(String JavaDoc str) {
86         this.str = str;
87         // log.debug("Set StringProperty: " + str);
88
}
89
90     /**
91      * @return the Object equivalent of this property
92      */

93     public Object JavaDoc getObject() {
94         return this.str;
95     }
96
97     /**
98      * @return the String equivalent of this property
99      */

100     public String JavaDoc getString() {
101         return this.str;
102     }
103
104 }
105
Popular Tags