1 package com.genimen.djeneric.web.renderers; 2 3 import javax.xml.parsers.FactoryConfigurationError ; 4 import javax.xml.parsers.ParserConfigurationException ; 5 6 import org.w3c.dom.CDATASection ; 7 import org.w3c.dom.Document ; 8 import org.w3c.dom.Element ; 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 asXml(String title, String text, String buttons, int width, int height, boolean escape) throws FactoryConfigurationError , 22 ParserConfigurationException , DjenericException 23 { 24 Document doc = createDocument(); 25 Element dialog = doc.createElement("dialog"); 26 if (title != null) dialog.setAttribute("title", title); 27 if (text != null) 28 { 29 CDATASection 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 createButton(Document doc, String type, String titleid, boolean doesApply) 60 { 61 Element 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 |