KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > conf > SkinconfTransformer


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation or its licensors,
3  * as applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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 package org.apache.forrest.conf;
18
19 import java.awt.Color JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.avalon.framework.parameters.Parameters;
24 import org.apache.cocoon.ProcessingException;
25 import org.apache.cocoon.environment.SourceResolver;
26 import org.apache.cocoon.transformation.AbstractTransformer;
27 import org.xml.sax.Attributes JavaDoc;
28 import org.xml.sax.SAXException JavaDoc;
29 import org.xml.sax.helpers.AttributesImpl JavaDoc;
30
31 public class SkinconfTransformer
32   extends AbstractTransformer {
33
34           /**
35      * Setup
36      */

37     public void setup(SourceResolver resolver, Map JavaDoc objectModel,
38                       String JavaDoc src, Parameters parameters)
39     throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
40         /*final boolean append = parameters.getParameterAsBoolean("append", false);
41         final String logfilename = parameters.getParameter("logfile", null);*/

42     }
43     
44    /**
45      * Receive notification of the beginning of an element.
46      */

47     public void startElement(String JavaDoc uri, String JavaDoc loc, String JavaDoc raw, Attributes JavaDoc a)
48     throws SAXException JavaDoc {
49         /*
50         this.log ("startElement", "uri="+uri+",local="+loc+",raw="+raw);
51         for (int i = 0; i < a.getLength(); i++) {
52             this.log (" ", new Integer(i+1).toString()
53                  +". uri="+a.getURI(i)
54                  +",local="+a.getLocalName(i)
55                  +",qname="+a.getQName(i)
56                  +",type="+a.getType(i)
57                  +",value="+a.getValue(i));
58         }
59         */

60         Attributes JavaDoc outAttributes = a;
61         
62         if("color".equals(loc)) {
63             
64             AttributesImpl JavaDoc newAttributes = new AttributesImpl JavaDoc(a);
65             
66             String JavaDoc value=null;
67             String JavaDoc highlight=null;
68             String JavaDoc lowlight=null;
69             String JavaDoc font=null;
70             String JavaDoc link=null;
71             String JavaDoc vlink=null;
72             String JavaDoc hlink=null;
73             
74             for (int i = 0; i < a.getLength(); i++) {
75                 if("value".equals(a.getLocalName(i))){
76                    value=a.getValue(i);
77                 }else if("highlight".equals(a.getLocalName(i))){
78                    highlight=a.getValue(i);
79                 }else if("lowlight".equals(a.getLocalName(i))){
80                    lowlight=a.getValue(i);
81                 }else if("font".equals(a.getLocalName(i))){
82                    font=a.getValue(i);
83                 }else if("link".equals(a.getLocalName(i))){
84                    link=a.getValue(i);
85                 }else if("vlink".equals(a.getLocalName(i))){
86                    vlink=a.getValue(i);
87                 }else if("hlink".equals(a.getLocalName(i))){
88                    hlink=a.getValue(i);
89                 }
90             }
91             
92             if(value==null){
93               value="#dd0000";// a default "visible" color
94
newAttributes.addAttribute("","value","value","",value);
95             }
96             
97             Color JavaDoc valueColor = Color.decode(value);
98             float brightness = Color.RGBtoHSB(valueColor.getRed(),
99                                               valueColor.getGreen(),
100                                               valueColor.getBlue(),
101                                               null)[2];
102             
103             if(highlight==null){
104                 highlight = "#"+Integer.toHexString(valueColor.brighter().getRGB()).substring(2);
105                 newAttributes.addAttribute("","highlight","highlight","",highlight);
106             }
107
108             if(lowlight==null){
109                 lowlight = "#"+Integer.toHexString(valueColor.darker().getRGB()).substring(2);
110                 newAttributes.addAttribute("","lowlight","lowlight","",lowlight);
111             }
112             
113             if(font==null){
114                 if(brightness<0.5) {
115                     font="#ffffff";
116                 }
117                 else{
118                     font="#000000";
119                 }
120                 newAttributes.addAttribute("","font","font","",font);
121             }
122
123             if(link==null){
124                 if(brightness<0.5) {
125                      link="#7f7fff";
126                 }
127                 else{
128                     link="#0000ff";
129                 }
130                 newAttributes.addAttribute("","link","link","",link);
131             }
132
133             if(vlink==null){
134                 if(brightness<0.5) {
135                     vlink="#4242a5";
136                 }
137                 else{
138                     vlink="#ffffff";
139                 }
140                 newAttributes.addAttribute("","vlink","vlink","",link);
141             }
142             
143             if(hlink==null){
144                 if(brightness<0.5) {
145                     hlink="#0037ff";
146                 }
147                 else{
148                     hlink="#6587ff";
149                 }
150                 newAttributes.addAttribute("","hlink","hlink","",link);
151             }
152             
153             outAttributes = newAttributes;
154         }
155         
156         if (super.contentHandler!=null) {
157             super.contentHandler.startElement(uri,loc,raw,outAttributes);
158         }
159     }
160 }
161
Popular Tags