001: /*---------------- FILE HEADER ------------------------------------------
002:
003: This file is part of deegree.
004: Copyright (C) 2001 by:
005: EXSE, Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/exse/
007: lat/lon Fitzke/Fretter/Poth GbR
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014:
015: This library is distributed in the hope that it will be useful,
016: but WITHOUT ANY WARRANTY; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: Lesser General Public License for more details.
019:
020: You should have received a copy of the GNU Lesser General Public
021: License along with this library; if not, write to the Free Software
022: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023:
024: Contact:
025:
026: Andreas Poth
027: lat/lon Fitzke/Fretter/Poth GbR
028: Meckenheimer Allee 176
029: 53115 Bonn
030: Germany
031: E-Mail: poth@lat-lon.de
032:
033: Jens Fitzke
034: Department of Geography
035: University of Bonn
036: Meckenheimer Allee 166
037: 53115 Bonn
038: Germany
039: E-Mail: jens.fitzke@uni-bonn.de
040:
041:
042: ---------------------------------------------------------------------------*/
043: package de.latlon.deejump.plugin.style;
044:
045: import java.io.File;
046: import java.net.MalformedURLException;
047:
048: import org.w3c.dom.NamedNodeMap;
049: import org.w3c.dom.Node;
050:
051: /**
052: * ...
053: *
054: * @author <a href="mailto:taddei@lat-lon.de">Ugo Taddei </a>
055: *
056: */
057: public class XSLUtility {
058:
059: static {
060:
061: //FIXME there is a problem when this class is added as an extension
062: // jump cannot find it (not in class path, because it's dynamically loaded)
063: // System.out.println( "never called" );
064: // System.out.println( System.getProperty( "java.class.path" ) );
065: }
066:
067: public static String toHexColor(Node colorNode) {
068: String value = "#000000";
069: if (colorNode == null)
070: return value;
071:
072: try {//FIXME no good to grab 1st child and then node val
073: if (colorNode.getFirstChild() == null)
074: return value;
075: String nodeVal = colorNode.getFirstChild().getNodeValue();
076: String[] components = nodeVal.split(", ");
077: StringBuffer sb = new StringBuffer(100);
078: sb.append("#");
079: for (int i = 0; i < components.length - 1; i++) {
080:
081: String uglyHack = Integer.toHexString(Integer
082: .parseInt(components[i]));
083: uglyHack = uglyHack.length() == 1 ? "0" + uglyHack
084: : uglyHack;
085: sb.append(uglyHack);
086:
087: }
088:
089: value = sb.toString();
090:
091: } catch (Exception e) {
092: e.printStackTrace();
093: }
094:
095: return value;
096: }
097:
098: public static String toAlphaValue(Node colorNode) {
099: String value = "1";
100:
101: try {//FIXME no good to grab 1st child than node val
102: String nodeVal = colorNode.getFirstChild().getNodeValue();
103: String[] components = nodeVal.split(", ");
104:
105: value = String
106: .valueOf(Double.parseDouble(components[3]) / 255d);
107: } catch (Exception e) {
108: e.printStackTrace();
109: }
110: // don't care about number formating, just trim the string
111: if (value.length() > 6) {
112: value = value.substring(0, 5);
113: }
114: return value;
115: }
116:
117: public static String toFontFamily(Node colorNode) {
118: String value = "Dialog";
119:
120: try {//FIXME no good to grab 1st child than node val
121: String nodeVal = colorNode.getFirstChild().getNodeValue();
122: String[] components = nodeVal.split(", ");
123: value = components[0];
124: } catch (Exception e) {
125: e.printStackTrace();
126: }
127: return value;
128: }
129:
130: public static String toFontStyle(Node fontNode) {
131: // bold not supported in SLD?
132: final String[] styles = { "normal", "normal", "italic" };
133:
134: String value = styles[0];
135: try {//FIXME no good to grab 1st child than node val
136: String nodeVal = fontNode.getFirstChild().getNodeValue();
137: String[] components = nodeVal.split(", ");
138:
139: //cheap, cheap, cheap
140: value = styles[Integer.parseInt(components[1])];
141: } catch (Exception e) {
142: e.printStackTrace();
143: }
144: return value;
145: }
146:
147: public static boolean _toWellKnowName(Node vertexStyleNode) {
148: String value = "square";
149: try {//FIXME no good to grab 1st child than node val
150: String nodeVal = vertexStyleNode.getFirstChild()
151: .getNodeValue();
152: String[] components = nodeVal.split(", ");
153:
154: } catch (Exception e) {
155: e.printStackTrace();
156: }
157: return true;
158: }
159:
160: public static String toWellKnowName(Node vertexStyleNode) {
161: if (vertexStyleNode == null) {
162: return "";
163: }
164:
165: String value = "square";
166: try {
167:
168: NamedNodeMap atts = vertexStyleNode.getAttributes();
169: String nodeVal = atts.getNamedItem("class").getNodeValue();
170:
171: if (nodeVal.indexOf("Square") > -1) {
172: //already there
173: } else if (nodeVal.indexOf("Circle") > -1) {
174: value = "circle";
175: } else if (nodeVal.indexOf("Cross") > -1) {
176: value = "cross";
177: } else if (nodeVal.indexOf("Star") > -1) {
178: value = "star";
179: } else if (nodeVal.indexOf("Triangle") > -1) {
180: value = "triangle";
181: }
182:
183: } catch (Exception e) {
184: e.printStackTrace();
185: }
186: return value;
187: }
188:
189: public static String fileToURL(String filename) {
190: File f = new File(filename);
191: f.deleteOnExit();
192:
193: try {
194: return f.toURL().toString();
195: } catch (MalformedURLException e) {
196: return filename;
197: }
198: }
199: }
|