1 22 23 package org.meshcms.taglib; 24 25 import java.io.*; 26 import java.text.*; 27 import java.util.*; 28 import javax.servlet.*; 29 import javax.servlet.jsp.*; 30 import org.meshcms.core.*; 31 import org.meshcms.util.*; 32 import org.meshcms.webui.*; 33 34 37 public final class Module extends AbstractTag { 38 public static final String DATE_NONE = "none"; 39 public static final String DATE_NORMAL = "normal"; 40 public static final String DATE_FULL = "full"; 41 42 private String name; 43 private String date; 44 private String style; 45 private String location = ""; 46 private String alt = " "; 47 private String parameters; 48 49 public void setName(String name) { 50 this.name = name; 51 } 52 53 public void setDate(String date) { 54 this.date = date; 55 } 56 57 public void setStyle(String style) { 58 this.style = style; 59 } 60 61 public void setLocation(String location) { 62 this.location = location; 63 } 64 65 public void setAlt(String alt) { 66 this.alt = alt; 67 } 68 69 public void writeTag() throws IOException, JspException { 70 if (date == null) { 71 date = DATE_NONE; 72 } 73 74 ModuleDescriptor md = getModuleDescriptor(location, name); 75 76 if (md != null) { 77 if (parameters != null) { 78 md.parseParameters(parameters); 79 } 80 81 Path modulePath = webSite.getModulePath(md.getTemplate()); 82 83 if (modulePath != null) { 84 md.setPagePath(pagePath); 85 md.setModulePath(modulePath); 86 md.setDateFormat(date); 87 md.setStyle(style); 88 89 String moduleCode = "meshcmsmodule_" + location; 90 request.setAttribute(moduleCode, md); 91 92 try { 93 pageContext.include("/" + webSite.getServedPath(modulePath) + "/" + 94 SiteMap.MODULE_INCLUDE_FILE + "?modulecode=" + moduleCode); 95 } catch (ServletException ex) { 96 WebUtils.setBlockCache(request); 97 webSite.log("Exception while including module " + modulePath, ex); 98 99 if (!webSite.getConfiguration().isHideExceptions()) { 100 Writer w = getOut(); 101 PrintWriter pw = new PrintWriter(w); 102 w.write("<pre class='meshcmserror'>\n"); 103 ex.printStackTrace(pw); 104 105 if (ex instanceof ServletException) { 106 Throwable t = ((ServletException) ex).getRootCause(); 107 108 if (t != null) { 109 t.printStackTrace(pw); 110 } 111 } 112 113 w.write("</pre>"); 114 } 115 } 116 } 117 } else { 118 getOut().write(alt); 119 } 120 } 121 122 public void writeEditTag() throws IOException, JspException { 123 String uniqueHash = Integer.toString(new Object ().hashCode()); 124 String tagIdPrefix = "meshcmsmodule_"+ location +"_"+ uniqueHash +"_"; 125 String idCont = tagIdPrefix +"cont"; 126 String idElem = tagIdPrefix +"elem"; 127 String idIcon = tagIdPrefix +"icon"; 128 boolean isEditorModulesCollapsed = webSite.getConfiguration().isEditorModulesCollapsed(); 129 130 String template = null; 131 String argPath = null; 132 String advParms = null; 133 134 ModuleDescriptor md = getModuleDescriptor(location, name); 135 136 if (md != null) { 137 template = md.getTemplate(); 138 argPath = md.getArgument(); 139 advParms = Utils.listProperties(md.getAdvancedParams(), ", "); 140 } 141 142 Locale locale = WebUtils.getPageLocale(pageContext); 143 ResourceBundle bundle = ResourceBundle.getBundle("org/meshcms/webui/Locales", locale); 144 MessageFormat formatter = new MessageFormat("", locale); 145 146 Writer w = getOut(); 147 148 Object [] args = { 149 location, 150 template != null ? Utils.beautify(template,true) : bundle.getString("editorNoTemplate"), 151 Utils.noNull(argPath), 152 Utils.noNull(advParms) 153 }; 154 155 if (isEditorModulesCollapsed) { 156 w.write("<div id=\"" + idCont + "\" class='meshcmsfieldlabel' " + 157 " style=\"cursor:pointer;position:relative;\" onclick=\"javascript:editor_moduleShow('" + 158 idCont + "','" + idElem + "','" + idIcon + "');\">" + 159 "<img alt=\"\" SRC=\"" + afp + "/images/tree_plus.gif\" id=\"" + idIcon + "\" />\n"); 160 formatter.applyPattern(bundle.getString("editorModuleLocExt")); 161 w.write("<label for=\"" + idElem + "\">" + formatter.format(args) + "</label>"); 162 w.write("</div>"); 163 } 164 165 w.write("<fieldset "+ (isEditorModulesCollapsed ? "style=\"display:none;\"" : "") + 166 " id=\""+ idElem +"\" class='meshcmseditor' >\n"); 167 formatter.applyPattern(bundle.getString("editorModuleLoc")); 168 w.write(" <legend>" + formatter.format(args) + "</legend>\n"); 169 170 if (name != null) { 171 w.write(bundle.getString("editorFixedModule")); 172 173 if (argPath != null) { 174 w.write("<img alt=\"\" SRC='" + afp + "/images/small_browse.gif' title='" + 175 bundle.getString("editorBrowseModule") + 176 "' onclick=\"javascript:window.open('" + 177 afp + "/filemanager/index.jsp?folder=" + 178 Utils.escapeSingleQuotes(argPath) + 179 "', '_blank').focus();\" style='vertical-align:middle;' />\n"); 180 } 181 } else { 182 w.write(" <div class='meshcmsfieldlabel'><label for='" + 183 ModuleDescriptor.TEMPLATE_ID + location + "'>" + 184 bundle.getString("editorModuleTemplate") + "</label></div>\n"); 185 w.write(" <div class='meshcmsfield'>\n <select name='" + 186 ModuleDescriptor.TEMPLATE_ID + location + "' id='" + 187 ModuleDescriptor.TEMPLATE_ID + location + "'>\n"); 188 w.write(" <option value='" + PageAssembler.EMPTY + "'>" + 189 bundle.getString("editorNoTemplate") + "</option>\n"); 190 191 String [] mtNames = webSite.getSiteMap().getModuleNames(); 192 193 for (int i = 0; i < mtNames.length; i++) { 194 w.write(" <option value='" + mtNames[i] + "'"); 195 196 if (md != null && mtNames[i].equals(template)) { 197 w.write(" selected='selected'"); 198 } 199 200 w.write(">" + Utils.beautify(Utils.removeExtension(mtNames[i]), true) + "</option>\n"); 201 } 202 203 w.write(" </select> "); 204 w.write(Help.icon(webSite, cp, Help.MODULES, userInfo, "module_'+document.getElementById('" + 205 ModuleDescriptor.TEMPLATE_ID + location + "').value+'", true)); 206 w.write("\n </div>\n"); 207 w.write(" <div class='meshcmsfieldlabel'><label for='" + 208 ModuleDescriptor.ARGUMENT_ID + location + "'>" + 209 bundle.getString("editorModuleArgument") + "</label></div>\n"); 210 w.write(" <div class='meshcmsfield'><img alt=\"\" SRC='" + afp + 211 "/images/clear_field.gif' onclick=\"javascript:editor_clr('" + 212 ModuleDescriptor.ARGUMENT_ID + location + "');\" style='vertical-align:middle;' /><input type='text' id='" + 213 ModuleDescriptor.ARGUMENT_ID + location + "' name='" + 214 ModuleDescriptor.ARGUMENT_ID + location + "' value=\"" + 215 (md == null || argPath == null ? "" : argPath) + 216 "\" style='width: 80%;' /><img alt=\"\" SRC='" + afp + 217 "/images/small_browse.gif' title='" + bundle.getString("genericBrowse") + 218 "' onclick=\"javascript:editor_openFileManager('" + 219 ModuleDescriptor.ARGUMENT_ID + location + "');\" style='vertical-align:middle;' /></div>\n"); 220 221 w.write(" <div class='meshcmsfieldlabel'><label for='" + 222 ModuleDescriptor.PARAMETERS_ID + location + "'>" + 223 bundle.getString("editorModuleParameters") + "</label></div>\n"); 224 w.write(" <div class='meshcmsfield'><img alt=\"\" SRC='" + afp + 225 "/images/clear_field.gif' onclick=\"javascript:editor_clr('" + 226 ModuleDescriptor.PARAMETERS_ID + location + "');\" style='vertical-align:middle;' /><input type='text' id='" + 227 ModuleDescriptor.PARAMETERS_ID + location + "' name='" + 228 ModuleDescriptor.PARAMETERS_ID + location + "' value=\"" + 229 (md == null || md.getAdvancedParams() == null ? "" : 230 Utils.listProperties(md.getAdvancedParams(), ", ")) + 231 "\" style='width: 80%;' /></div>\n"); 232 } 233 234 w.write("</fieldset>"); 235 } 236 237 public String getName() { 238 return name; 239 } 240 241 public String getDate() { 242 return date; 243 } 244 245 public String getStyle() { 246 return style; 247 } 248 249 public String getLocation() { 250 return location; 251 } 252 253 public String getAlt() { 254 return alt; 255 } 256 257 public String getParameters() { 258 return parameters; 259 } 260 261 public void setParameters(String parameters) { 262 this.parameters = parameters; 263 } 264 } 265 | Popular Tags |