1 17 package org.apache.forrest.conf; 18 19 import java.awt.Color ; 20 import java.io.IOException ; 21 import java.util.Map ; 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 ; 28 import org.xml.sax.SAXException ; 29 import org.xml.sax.helpers.AttributesImpl ; 30 31 public class SkinconfTransformer 32 extends AbstractTransformer { 33 34 37 public void setup(SourceResolver resolver, Map objectModel, 38 String src, Parameters parameters) 39 throws ProcessingException, SAXException , IOException { 40 42 } 43 44 47 public void startElement(String uri, String loc, String raw, Attributes a) 48 throws SAXException { 49 60 Attributes outAttributes = a; 61 62 if("color".equals(loc)) { 63 64 AttributesImpl newAttributes = new AttributesImpl (a); 65 66 String value=null; 67 String highlight=null; 68 String lowlight=null; 69 String font=null; 70 String link=null; 71 String vlink=null; 72 String 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"; newAttributes.addAttribute("","value","value","",value); 95 } 96 97 Color 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 |