KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > util > JRStyledTextParser


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.util;
29
30 import java.awt.Color JavaDoc;
31 import java.awt.GraphicsEnvironment JavaDoc;
32 import java.awt.font.TextAttribute JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.StringReader JavaDoc;
35 import java.text.AttributedCharacterIterator JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Map JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40
41 import javax.xml.parsers.DocumentBuilder JavaDoc;
42 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
43 import javax.xml.parsers.ParserConfigurationException JavaDoc;
44
45 import net.sf.jasperreports.engine.JRRuntimeException;
46 import net.sf.jasperreports.engine.xml.JRXmlConstants;
47
48 import org.w3c.dom.Document JavaDoc;
49 import org.w3c.dom.NamedNodeMap JavaDoc;
50 import org.w3c.dom.Node JavaDoc;
51 import org.w3c.dom.NodeList JavaDoc;
52 import org.xml.sax.InputSource JavaDoc;
53 import org.xml.sax.SAXException JavaDoc;
54
55
56 /**
57  * @author Teodor Danciu (teodord@users.sourceforge.net)
58  * @version $Id: JRStyledTextParser.java 1354 2006-08-04 12:26:03 +0300 (Fri, 04 Aug 2006) teodord $
59  */

60 public class JRStyledTextParser
61 {
62
63     /**
64      *
65      */

66     private static final String JavaDoc ROOT_START = "<st>";
67     private static final String JavaDoc ROOT_END = "</st>";
68     private static final String JavaDoc NODE_style = "style";
69     private static final String JavaDoc NODE_bold = "b";
70     private static final String JavaDoc NODE_italic = "i";
71     private static final String JavaDoc NODE_underline = "u";
72     private static final String JavaDoc NODE_sup = "sup";
73     private static final String JavaDoc NODE_sub = "sub";
74     private static final String JavaDoc NODE_font = "font";
75     private static final String JavaDoc NODE_br = "br";
76     private static final String JavaDoc NODE_li = "li";
77     private static final String JavaDoc ATTRIBUTE_fontName = "fontName";
78     private static final String JavaDoc ATTRIBUTE_fontFace = "face";
79     private static final String JavaDoc ATTRIBUTE_color = "color";
80     private static final String JavaDoc ATTRIBUTE_size = "size";
81     private static final String JavaDoc ATTRIBUTE_isBold = "isBold";
82     private static final String JavaDoc ATTRIBUTE_isItalic = "isItalic";
83     private static final String JavaDoc ATTRIBUTE_isUnderline = "isUnderline";
84     private static final String JavaDoc ATTRIBUTE_isStrikeThrough = "isStrikeThrough";
85     private static final String JavaDoc ATTRIBUTE_forecolor = "forecolor";
86     private static final String JavaDoc ATTRIBUTE_backcolor = "backcolor";
87     private static final String JavaDoc ATTRIBUTE_pdfFontName = "pdfFontName";
88     private static final String JavaDoc ATTRIBUTE_pdfEncoding = "pdfEncoding";
89     private static final String JavaDoc ATTRIBUTE_isPdfEmbedded = "isPdfEmbedded";
90
91     private static final String JavaDoc SPACE = " ";
92     private static final String JavaDoc EQUAL_QUOTE = "=\"";
93     private static final String JavaDoc QUOTE = "\"";
94     private static final String JavaDoc SHARP = "#";
95     private static final String JavaDoc LESS = "<";
96     private static final String JavaDoc LESS_SLASH = "</";
97     private static final String JavaDoc GREATER = ">";
98     private static final String JavaDoc SIX_ZEROS = "000000";
99     private static final int colorMask = Integer.parseInt("FFFFFF", 16);
100
101     /**
102      *
103      */

104     private DocumentBuilder JavaDoc documentBuilder = null;
105
106
107     /**
108      *
109      */

110     public JRStyledTextParser()
111     {
112         try
113         {
114             DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
115             documentBuilder = factory.newDocumentBuilder();
116         }
117         catch (ParserConfigurationException JavaDoc e)
118         {
119             throw new JRRuntimeException(e);
120         }
121     }
122
123
124     /**
125      *
126      */

127     public JRStyledText parse(Map JavaDoc attributes, String JavaDoc text) throws SAXException JavaDoc
128     {
129         JRStyledText styledText = new JRStyledText();
130         
131         Document JavaDoc document = null;
132
133         try
134         {
135             document = documentBuilder.parse(new InputSource JavaDoc(new StringReader JavaDoc(ROOT_START + text + ROOT_END)));
136         }
137         catch (IOException JavaDoc e)
138         {
139             throw new JRRuntimeException(e);
140         }
141         
142         parseStyle(styledText, document.getDocumentElement());
143         
144         styledText.addRun(new JRStyledText.Run(attributes, 0, styledText.length()));
145         
146         return styledText;
147     }
148
149     /**
150      *
151      */

152     public String JavaDoc write(Map JavaDoc parentAttrs, AttributedCharacterIterator JavaDoc iterator, String JavaDoc text)
153     {
154         StringBuffer JavaDoc sbuffer = new StringBuffer JavaDoc();
155         
156         int runLimit = 0;
157
158         while(runLimit < iterator.getEndIndex() && (runLimit = iterator.getRunLimit()) <= iterator.getEndIndex())
159         {
160             String JavaDoc chunk = text.substring(iterator.getIndex(), runLimit);
161             Map JavaDoc attrs = iterator.getAttributes();
162             
163             StringBuffer JavaDoc styleBuffer = writeStyleAttributes(parentAttrs, attrs);
164             if (styleBuffer.length() > 0)
165             {
166                 sbuffer.append(LESS);
167                 sbuffer.append(NODE_style);
168                 sbuffer.append(styleBuffer.toString());
169                 sbuffer.append(GREATER);
170                 writeChunk(sbuffer, parentAttrs, attrs, chunk);
171                 sbuffer.append(LESS_SLASH);
172                 sbuffer.append(NODE_style);
173                 sbuffer.append(GREATER);
174             }
175             else
176             {
177                 writeChunk(sbuffer, parentAttrs, attrs, chunk);
178             }
179
180             iterator.setIndex(runLimit);
181         }
182         
183         return sbuffer.toString();
184     }
185
186     /**
187      *
188      */

189     public void writeChunk(StringBuffer JavaDoc sbuffer, Map JavaDoc parentAttrs, Map JavaDoc attrs, String JavaDoc chunk)
190     {
191         Object JavaDoc value = attrs.get(TextAttribute.SUPERSCRIPT);
192         Object JavaDoc oldValue = parentAttrs.get(TextAttribute.SUPERSCRIPT);
193
194         boolean isSuper = false;
195         boolean isSub = false;
196         
197         if (value != null && !value.equals(oldValue))
198         {
199             isSuper=TextAttribute.SUPERSCRIPT_SUPER.equals(value);
200             isSub=TextAttribute.SUPERSCRIPT_SUB.equals(value);
201         }
202
203
204         if (isSuper || isSub)
205         {
206             String JavaDoc node = isSuper?NODE_sup:NODE_sub;
207             sbuffer.append(LESS);
208             sbuffer.append(node);
209             sbuffer.append(GREATER);
210             sbuffer.append(chunk);
211             sbuffer.append(LESS_SLASH);
212             sbuffer.append(node);
213             sbuffer.append(GREATER);
214         }
215         else
216         {
217             sbuffer.append(chunk);
218         }
219     }
220
221     /**
222      *
223      */

224     private void parseStyle(JRStyledText styledText, Node JavaDoc parentNode) throws SAXException JavaDoc
225     {
226         NodeList JavaDoc nodeList = parentNode.getChildNodes();
227         for(int i = 0; i < nodeList.getLength(); i++)
228         {
229             Node JavaDoc node = nodeList.item(i);
230             if (node.getNodeType() == Node.TEXT_NODE)
231             {
232                 styledText.append(node.getNodeValue());
233             }
234             else if (
235                 node.getNodeType() == Node.ELEMENT_NODE
236                 && NODE_style.equals(node.getNodeName())
237                 )
238             {
239                 NamedNodeMap JavaDoc nodeAttrs = node.getAttributes();
240
241                 Map JavaDoc styleAttrs = new HashMap JavaDoc();
242
243                 if (nodeAttrs.getNamedItem(ATTRIBUTE_fontName) != null)
244                 {
245                     styleAttrs.put(
246                         TextAttribute.FAMILY,
247                         nodeAttrs.getNamedItem(ATTRIBUTE_fontName).getNodeValue()
248                         );
249                 }
250
251                 if (nodeAttrs.getNamedItem(ATTRIBUTE_isBold) != null)
252                 {
253                     styleAttrs.put(
254                         TextAttribute.WEIGHT,
255                         Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isBold).getNodeValue()).booleanValue()
256                         ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR
257                         );
258                 }
259
260                 if (nodeAttrs.getNamedItem(ATTRIBUTE_isItalic) != null)
261                 {
262                     styleAttrs.put(
263                         TextAttribute.POSTURE,
264                         Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isItalic).getNodeValue()).booleanValue()
265                         ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR
266                         );
267                 }
268
269                 if (nodeAttrs.getNamedItem(ATTRIBUTE_isUnderline) != null)
270                 {
271                     styleAttrs.put(
272                         TextAttribute.UNDERLINE,
273                         Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isUnderline).getNodeValue()).booleanValue()
274                         ? TextAttribute.UNDERLINE_ON : null
275                         );
276                 }
277
278                 if (nodeAttrs.getNamedItem(ATTRIBUTE_isStrikeThrough) != null)
279                 {
280                     styleAttrs.put(
281                         TextAttribute.STRIKETHROUGH,
282                         Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isStrikeThrough).getNodeValue()).booleanValue()
283                         ? TextAttribute.STRIKETHROUGH_ON : null
284                         );
285                 }
286
287                 if (nodeAttrs.getNamedItem(ATTRIBUTE_size) != null)
288                 {
289                     styleAttrs.put(
290                         TextAttribute.SIZE,
291                         new Float JavaDoc(nodeAttrs.getNamedItem(ATTRIBUTE_size).getNodeValue())
292                         );
293                 }
294
295                 if (nodeAttrs.getNamedItem(ATTRIBUTE_pdfFontName) != null)
296                 {
297                     styleAttrs.put(
298                         JRTextAttribute.PDF_FONT_NAME,
299                         nodeAttrs.getNamedItem(ATTRIBUTE_pdfFontName).getNodeValue()
300                         );
301                 }
302
303                 if (nodeAttrs.getNamedItem(ATTRIBUTE_pdfEncoding) != null)
304                 {
305                     styleAttrs.put(
306                         JRTextAttribute.PDF_ENCODING,
307                         nodeAttrs.getNamedItem(ATTRIBUTE_pdfEncoding).getNodeValue()
308                         );
309                 }
310
311                 if (nodeAttrs.getNamedItem(ATTRIBUTE_isPdfEmbedded) != null)
312                 {
313                     styleAttrs.put(
314                         JRTextAttribute.IS_PDF_EMBEDDED,
315                         Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isPdfEmbedded).getNodeValue())
316                         );
317                 }
318
319                 if (nodeAttrs.getNamedItem(ATTRIBUTE_forecolor) != null)
320                 {
321                     Color JavaDoc color =
322                         JRXmlConstants.getColor(
323                             nodeAttrs.getNamedItem(ATTRIBUTE_forecolor).getNodeValue(),
324                             Color.black
325                             );
326                     styleAttrs.put(
327                         TextAttribute.FOREGROUND,
328                         color
329                         );
330                 }
331
332                 if (nodeAttrs.getNamedItem(ATTRIBUTE_backcolor) != null)
333                 {
334                     Color JavaDoc color =
335                         JRXmlConstants.getColor(
336                             nodeAttrs.getNamedItem(ATTRIBUTE_backcolor).getNodeValue(),
337                             Color.black
338                             );
339                     styleAttrs.put(
340                         TextAttribute.BACKGROUND,
341                         color
342                         );
343                 }
344
345                 int startIndex = styledText.length();
346
347                 parseStyle(styledText, node);
348
349                 styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
350             }
351             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_bold.equalsIgnoreCase(node.getNodeName()))
352             {
353                 Map JavaDoc styleAttrs = new HashMap JavaDoc();
354                 styleAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
355
356                 int startIndex = styledText.length();
357
358                 parseStyle(styledText, node);
359
360                 styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
361             }
362             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_italic.equalsIgnoreCase(node.getNodeName()))
363             {
364                 Map JavaDoc styleAttrs = new HashMap JavaDoc();
365                 styleAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
366
367                 int startIndex = styledText.length();
368
369                 parseStyle(styledText, node);
370
371                 styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
372             }
373             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_underline.equalsIgnoreCase(node.getNodeName()))
374             {
375                 Map JavaDoc styleAttrs = new HashMap JavaDoc();
376                 styleAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
377
378                 int startIndex = styledText.length();
379
380                 parseStyle(styledText, node);
381
382                 styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
383             }
384             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_sup.equalsIgnoreCase(node.getNodeName()))
385             {
386                 Map JavaDoc styleAttrs = new HashMap JavaDoc();
387                 styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
388
389                 int startIndex = styledText.length();
390
391                 parseStyle(styledText, node);
392
393                 styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
394             }
395             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_sub.equalsIgnoreCase(node.getNodeName()))
396             {
397                 Map JavaDoc styleAttrs = new HashMap JavaDoc();
398                 styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
399
400                 int startIndex = styledText.length();
401
402                 parseStyle(styledText, node);
403
404                 styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
405             }
406             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_font.equalsIgnoreCase(node.getNodeName()))
407             {
408                 NamedNodeMap JavaDoc nodeAttrs = node.getAttributes();
409
410                 Map JavaDoc styleAttrs = new HashMap JavaDoc();
411
412                 if (nodeAttrs.getNamedItem(ATTRIBUTE_fontFace) != null)
413                 {
414                     styleAttrs.put(
415                         JRTextAttribute.HTML_FONT_FACE,
416                         nodeAttrs.getNamedItem(ATTRIBUTE_fontFace).getNodeValue()
417                         );
418                 }
419                 if (nodeAttrs.getNamedItem(ATTRIBUTE_size) != null)
420                 {
421                     styleAttrs.put(
422                         TextAttribute.SIZE,
423                         new Float JavaDoc(nodeAttrs.getNamedItem(ATTRIBUTE_size).getNodeValue())
424                         );
425                 }
426
427                 if (nodeAttrs.getNamedItem(ATTRIBUTE_color) != null)
428                 {
429                     Color JavaDoc color =
430                         JRXmlConstants.getColor(
431                             nodeAttrs.getNamedItem(ATTRIBUTE_color).getNodeValue(),
432                             Color.black
433                             );
434                     styleAttrs.put(
435                         TextAttribute.FOREGROUND,
436                         color
437                         );
438                 }
439
440                 if (nodeAttrs.getNamedItem(ATTRIBUTE_fontFace) != null) {
441                     String JavaDoc[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
442                     String JavaDoc fontFaces = nodeAttrs.getNamedItem(ATTRIBUTE_fontFace).getNodeValue();
443
444                     StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(fontFaces, ",");
445                     label:while (t.hasMoreTokens()) {
446                         String JavaDoc face = t.nextToken().trim();
447                         for (int j = 0; j < fontList.length; j++)
448                             if (fontList[j].equals(face)) {
449                                 styleAttrs.put(TextAttribute.FAMILY, face);
450                                 break label;
451                             }
452                     }
453                 }
454                 int startIndex = styledText.length();
455
456                 parseStyle(styledText, node);
457
458                 styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
459
460             }
461             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_br.equalsIgnoreCase(node.getNodeName()))
462             {
463                 styledText.append("\n");
464
465                 int startIndex = styledText.length();
466                 resizeRuns(styledText.getRuns(), startIndex, 1);
467
468                 parseStyle(styledText, node);
469                 styledText.addRun(new JRStyledText.Run(new HashMap JavaDoc(), startIndex, styledText.length()));
470
471                 if (startIndex < styledText.length()) {
472                     styledText.append("\n");
473                     resizeRuns(styledText.getRuns(), startIndex, 1);
474                 }
475             }
476             else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_li.equalsIgnoreCase(node.getNodeName()))
477             {
478                 styledText.append("\n \u2022 ");
479
480                 int startIndex = styledText.length();
481                 resizeRuns(styledText.getRuns(), startIndex, 1);
482
483                 parseStyle(styledText, node);
484                 styledText.addRun(new JRStyledText.Run(new HashMap JavaDoc(), startIndex, styledText.length()));
485
486                 styledText.append("\n");
487                 resizeRuns(styledText.getRuns(), startIndex, 1);
488             }
489             else if (node.getNodeType() == Node.ELEMENT_NODE)
490             {
491                 String JavaDoc nodeName = "<" + node.getNodeName() + ">";
492                 throw new SAXException JavaDoc("Tag " + nodeName + " is not a valid styled text tag.");
493             }
494         }
495     }
496
497     /**
498      *
499      */

500     private void resizeRuns(List JavaDoc runs, int startIndex, int count)
501     {
502         for (int j = 0; j < runs.size(); j++)
503         {
504             JRStyledText.Run run = (JRStyledText.Run) runs.get(j);
505             if (run.startIndex <= startIndex && run.endIndex > startIndex - count)
506                 run.endIndex += count;
507         }
508     }
509
510
511     /**
512      *
513      */

514     private StringBuffer JavaDoc writeStyleAttributes(Map JavaDoc parentAttrs, Map JavaDoc attrs)
515     {
516         StringBuffer JavaDoc sbuffer = new StringBuffer JavaDoc();
517         
518         Object JavaDoc value = attrs.get(TextAttribute.FAMILY);
519         Object JavaDoc oldValue = parentAttrs.get(TextAttribute.FAMILY);
520         
521         if (value != null && !value.equals(oldValue))
522         {
523             sbuffer.append(SPACE);
524             sbuffer.append(ATTRIBUTE_fontName);
525             sbuffer.append(EQUAL_QUOTE);
526             sbuffer.append(value);
527             sbuffer.append(QUOTE);
528         }
529
530         value = attrs.get(TextAttribute.WEIGHT);
531         oldValue = parentAttrs.get(TextAttribute.WEIGHT);
532
533         if (value != null && !value.equals(oldValue))
534         {
535             sbuffer.append(SPACE);
536             sbuffer.append(ATTRIBUTE_isBold);
537             sbuffer.append(EQUAL_QUOTE);
538             sbuffer.append(value.equals(TextAttribute.WEIGHT_BOLD));
539             sbuffer.append(QUOTE);
540         }
541
542         value = attrs.get(TextAttribute.POSTURE);
543         oldValue = parentAttrs.get(TextAttribute.POSTURE);
544
545         if (value != null && !value.equals(oldValue))
546         {
547             sbuffer.append(SPACE);
548             sbuffer.append(ATTRIBUTE_isItalic);
549             sbuffer.append(EQUAL_QUOTE);
550             sbuffer.append(value.equals(TextAttribute.POSTURE_OBLIQUE));
551             sbuffer.append(QUOTE);
552         }
553
554         value = attrs.get(TextAttribute.UNDERLINE);
555         oldValue = parentAttrs.get(TextAttribute.UNDERLINE);
556
557         if (
558             (value == null && oldValue != null)
559             || (value != null && !value.equals(oldValue))
560             )
561         {
562             sbuffer.append(SPACE);
563             sbuffer.append(ATTRIBUTE_isUnderline);
564             sbuffer.append(EQUAL_QUOTE);
565             sbuffer.append(value != null);
566             sbuffer.append(QUOTE);
567         }
568
569         value = attrs.get(TextAttribute.STRIKETHROUGH);
570         oldValue = parentAttrs.get(TextAttribute.STRIKETHROUGH);
571
572         if (
573             (value == null && oldValue != null)
574             || (value != null && !value.equals(oldValue))
575             )
576         {
577             sbuffer.append(SPACE);
578             sbuffer.append(ATTRIBUTE_isStrikeThrough);
579             sbuffer.append(EQUAL_QUOTE);
580             sbuffer.append(value != null);
581             sbuffer.append(QUOTE);
582         }
583
584         value = attrs.get(TextAttribute.SIZE);
585         oldValue = parentAttrs.get(TextAttribute.SIZE);
586
587         if (value != null && !value.equals(oldValue))
588         {
589             sbuffer.append(SPACE);
590             sbuffer.append(ATTRIBUTE_size);
591             sbuffer.append(EQUAL_QUOTE);
592             sbuffer.append(((Float JavaDoc)value).intValue());
593             sbuffer.append(QUOTE);
594         }
595
596         value = attrs.get(JRTextAttribute.PDF_FONT_NAME);
597         oldValue = parentAttrs.get(JRTextAttribute.PDF_FONT_NAME);
598
599         if (value != null && !value.equals(oldValue))
600         {
601             sbuffer.append(SPACE);
602             sbuffer.append(ATTRIBUTE_pdfFontName);
603             sbuffer.append(EQUAL_QUOTE);
604             sbuffer.append(value);
605             sbuffer.append(QUOTE);
606         }
607
608         value = attrs.get(JRTextAttribute.PDF_ENCODING);
609         oldValue = parentAttrs.get(JRTextAttribute.PDF_ENCODING);
610
611         if (value != null && !value.equals(oldValue))
612         {
613             sbuffer.append(SPACE);
614             sbuffer.append(ATTRIBUTE_pdfEncoding);
615             sbuffer.append(EQUAL_QUOTE);
616             sbuffer.append(value);
617             sbuffer.append(QUOTE);
618         }
619
620         value = attrs.get(JRTextAttribute.IS_PDF_EMBEDDED);
621         oldValue = parentAttrs.get(JRTextAttribute.IS_PDF_EMBEDDED);
622
623         if (value != null && !value.equals(oldValue))
624         {
625             sbuffer.append(SPACE);
626             sbuffer.append(ATTRIBUTE_isPdfEmbedded);
627             sbuffer.append(EQUAL_QUOTE);
628             sbuffer.append(value);
629             sbuffer.append(QUOTE);
630         }
631
632         value = attrs.get(TextAttribute.FOREGROUND);
633         oldValue = parentAttrs.get(TextAttribute.FOREGROUND);
634
635         if (value != null && !value.equals(oldValue))
636         {
637             sbuffer.append(SPACE);
638             sbuffer.append(ATTRIBUTE_forecolor);
639             sbuffer.append(EQUAL_QUOTE);
640             sbuffer.append(SHARP);
641             sbuffer.append(getHexaColor((Color JavaDoc)value));
642             sbuffer.append(QUOTE);
643         }
644
645         value = attrs.get(TextAttribute.BACKGROUND);
646         oldValue = parentAttrs.get(TextAttribute.BACKGROUND);
647
648         if (value != null && !value.equals(oldValue))
649         {
650             sbuffer.append(SPACE);
651             sbuffer.append(ATTRIBUTE_backcolor);
652             sbuffer.append(EQUAL_QUOTE);
653             sbuffer.append(SHARP);
654             sbuffer.append(getHexaColor((Color JavaDoc)value));
655             sbuffer.append(QUOTE);
656         }
657         
658         return sbuffer;
659     }
660
661     /**
662      *
663      */

664     private String JavaDoc getHexaColor(Color JavaDoc color)
665     {
666         String JavaDoc hexa = Integer.toHexString(color.getRGB() & colorMask).toUpperCase();
667         return (SIX_ZEROS + hexa).substring(hexa.length());
668     }
669
670 }
671
Popular Tags