1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.parser.stylemapper;
24 
25 import com.sun.star.report.pentaho.parser.StyleMapper;
26 
27 import java.util.HashMap;
28 import java.util.Map;
29 
30 import org.jfree.layouting.input.style.CSSDeclarationRule;
31 import org.jfree.layouting.input.style.StyleKey;
32 import org.jfree.layouting.input.style.values.CSSValue;
33 
34 
35 public abstract class OneOfConstantsMapper implements StyleMapper
36 {
37 
38     private final StyleKey styleKey;
39     private final Map mappings;
40 
OneOfConstantsMapper(final StyleKey styleKey)41     protected OneOfConstantsMapper(final StyleKey styleKey)
42     {
43         this.styleKey = styleKey;
44         this.mappings = new HashMap();
45     }
46 
addMapping(final String value, final CSSValue target)47     public void addMapping(final String value, final CSSValue target)
48     {
49         mappings.put(value, target);
50     }
51 
updateStyle(final String uri, final String attrName, final String attrValue, final CSSDeclarationRule targetRule)52     public void updateStyle(final String uri,
53             final String attrName,
54             final String attrValue,
55             final CSSDeclarationRule targetRule)
56     {
57         final CSSValue value = lookupMapping(attrValue);
58         if (value != null)
59         {
60             targetRule.setPropertyValue(styleKey, value);
61         }
62     }
63 
getStyleKey()64     public StyleKey getStyleKey()
65     {
66         return styleKey;
67     }
68 
lookupMapping(final String attrValue)69     protected CSSValue lookupMapping(final String attrValue)
70     {
71         return (CSSValue) mappings.get(attrValue);
72     }
73 }
74