KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > web > renderers > DialogRenderer


1 package com.genimen.djeneric.web.renderers;
2
3 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
4 import javax.xml.parsers.ParserConfigurationException JavaDoc;
5
6 import org.w3c.dom.CDATASection JavaDoc;
7 import org.w3c.dom.Document JavaDoc;
8 import org.w3c.dom.Element JavaDoc;
9
10 import com.genimen.djeneric.language.Messages;
11 import com.genimen.djeneric.repository.exceptions.DjenericException;
12
13 public class DialogRenderer extends AbstractRenderer
14 {
15   public static int _uidcounter = 1;
16
17   public DialogRenderer()
18   {
19   }
20
21   public Document JavaDoc asXml(String JavaDoc title, String JavaDoc text, String JavaDoc buttons, int width, int height, boolean escape) throws FactoryConfigurationError JavaDoc,
22       ParserConfigurationException JavaDoc, DjenericException
23   {
24     Document JavaDoc doc = createDocument();
25     Element JavaDoc dialog = doc.createElement("dialog");
26     if (title != null) dialog.setAttribute("title", title);
27     if (text != null)
28     {
29       CDATASection JavaDoc descr = doc.createCDATASection(text);
30       dialog.appendChild(descr);
31     }
32     dialog.setAttribute("id", "dlg." + String.valueOf(_uidcounter++));
33     if (width > 0) dialog.setAttribute("width", String.valueOf(width));
34     if (height > 0) dialog.setAttribute("height", String.valueOf(height));
35     dialog.setAttribute("escape", String.valueOf(escape));
36
37     doc.appendChild(dialog);
38
39     if (buttons != null)
40     {
41       buttons = buttons.toLowerCase();
42       for (int i = 0; i < buttons.length(); i++)
43       {
44         if (buttons.charAt(i) == 'y') dialog.appendChild(createButton(doc, "yes", "global.Yes", true));
45         if (buttons.charAt(i) == 'n') dialog.appendChild(createButton(doc, "no", "global.No", false));
46         if (buttons.charAt(i) == 'o') dialog.appendChild(createButton(doc, "ok", "global.Ok", true));
47         if (buttons.charAt(i) == 'c') dialog.appendChild(createButton(doc, "cancel", "global.Cancel", false));
48         if (buttons.charAt(i) == '.') dialog.appendChild(createButton(doc, "close", "global.Close", false));
49       }
50     }
51     else
52     {
53       dialog.appendChild(createButton(doc, "ok", "global.Ok", true));
54     }
55
56     return doc;
57   }
58
59   private Element JavaDoc createButton(Document JavaDoc doc, String JavaDoc type, String JavaDoc titleid, boolean doesApply)
60   {
61     Element JavaDoc button = doc.createElement("button");
62     button.setAttribute("type", type);
63     button.setAttribute("title", Messages.getString(titleid));
64     button.setAttribute("apply", String.valueOf(doesApply));
65
66     return button;
67   }
68 }
69
Popular Tags