1 22 23 package org.meshcms.core; 24 25 import java.util.*; 26 import org.meshcms.util.*; 27 28 31 public final class PageAssembler { 32 35 public static final String EMPTY = "(none)"; 36 37 40 public static final String MODULES_PARAM = "meshcmsmodules"; 41 42 45 public static final String EMAIL_PARAM = "meshcmsmail"; 46 47 private String title; 48 private String head; 49 private String body; 50 private String email; 51 private StringBuffer bodyTag = new StringBuffer (); 53 private Properties mod_templates, mod_args, mod_params; 54 55 public PageAssembler() { 56 mod_templates = new Properties(); 57 mod_args = new Properties(); 58 mod_params = new Properties(); 59 } 60 61 64 public void addProperty(String name, String value) { 65 value = Utils.noNull(value).trim(); 66 67 if (name.equals("pagetitle")) { 68 title = value; 69 } else if (name.equals("meshcmshead")) { 70 head = value; 71 } else if (name.equals("meshcmsbody")) { 72 body = value; 73 } else if (name.equals(EMAIL_PARAM)) { 74 email = value; 75 } else if (name.startsWith(ModuleDescriptor.TEMPLATE_ID)) { 76 if (!value.equals(EMPTY)) { mod_templates.setProperty(name.substring(ModuleDescriptor.TEMPLATE_ID.length()), value); 80 } 81 } else if (name.startsWith(ModuleDescriptor.ARGUMENT_ID)) { 82 if (!Utils.isNullOrEmpty(value)) { 83 mod_args.setProperty(name.substring(ModuleDescriptor.ARGUMENT_ID.length()), value); 86 } 87 } else if (name.startsWith(ModuleDescriptor.PARAMETERS_ID)) { 88 mod_params.setProperty(name.substring(ModuleDescriptor.PARAMETERS_ID.length()), value); 89 } else if (name.startsWith("body.")) { 90 bodyTag.append(' ').append(name.substring(5)).append("=\"").append(value).append('\"'); 91 101 } 102 } 103 104 107 public String getPage() { 108 StringBuffer sb = new StringBuffer ("<html"); 109 111 Enumeration locations = mod_templates.keys(); 112 List modules = new ArrayList(); 113 114 while (locations.hasMoreElements()) { 116 String loc = locations.nextElement().toString(); 117 String template = mod_templates.getProperty(loc); 118 119 if (!Utils.isNullOrEmpty(template)) { 120 String argument = mod_args.getProperty(loc); 121 122 if (Utils.isNullOrEmpty(argument)) { 123 argument = EMPTY; 124 } 125 126 String params = mod_params.getProperty(loc); 127 modules.add( 128 ModuleDescriptor.LOCATION_ID + '=' + loc + ',' + 129 ModuleDescriptor.TEMPLATE_ID + '=' + template + ',' + 130 ModuleDescriptor.ARGUMENT_ID + '=' + argument + 131 (Utils.isNullOrEmpty(params) ? "" : ',' + params) 132 ); 133 } 134 } 135 136 if (modules.size() > 0) { sb.append(' ').append(MODULES_PARAM).append("=\"").append 138 (Utils.generateList(modules, ";")).append('"'); 139 } 140 141 if (Utils.checkAddress(email)) { sb.append(' ').append(EMAIL_PARAM).append("=\"").append(email).append('"'); 143 } 144 145 sb.append(">\n<head>\n<title>"); 146 sb.append(Utils.noNull(title)); 147 sb.append("</title>\n"); 148 sb.append(Utils.noNull(head)); 149 sb.append("\n</head>\n<body"); 150 sb.append(bodyTag); 151 sb.append(">\n"); 152 sb.append(Utils.noNull(body)); 153 sb.append("\n</body>\n</html>\n"); 154 155 return sb.toString(); 156 } 157 } 158 | Popular Tags |