jspnode.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,836 行 · 第 1/4 页
JAVA
1,836 行
if (! XmlChar.isWhitespace(ch)) throw error(L.l("Text is not allowed in <{0}> at '{1}'.", _name.getName(), text)); } return null; } /** * Adds a child node. */ public void addChild(JspNode node) throws JspParseException { node.setParent(this); if (node instanceof JspAttribute) { } else if (node instanceof StaticText && ((StaticText) node).isWhitespace()) { } else throw node.error(L.l("<{0}> does not allow any child elements at {1}", getTagName(), node.getTagName())); } /** * Adds a child node after its completely initialized.. */ public void addChildEnd(JspNode node) throws JspParseException { if (node instanceof JspAttribute) { JspAttribute attr = (JspAttribute) node; QName name = attr.getName(); addAttribute(name, attr); } } /** * Called when the tag closes. */ public void endElement() throws Exception { } /** * Returns the children. */ public ArrayList<JspNode> getChildren() { return null; } /** * Returns the TagInstance of the enclosing parent. */ public TagInstance getTag() { JspNode parent = getParent(); if (parent != null) return parent.getTag(); else { return _gen.getRootTag(); } } /** * Return true for pre-21 taglib. */ public boolean isPre21Taglib() { return false; } /** * Generates the XML text representation for the tag validation. * * @param os write stream to the generated XML. */ abstract public void printXml(WriteStream os) throws IOException; /** * Prints the jsp:id */ public void printJspId(WriteStream os) throws IOException { os.print(" jsp:id=\"" + _gen.generateJspId() + "\""); } /** * Generates the XML text representation for the tag validation. * * @param os write stream to the generated XML. */ public void printXmlText(WriteStream os, String text) throws IOException { os.print(xmlText(text)); } /** * Generates the XML text representation for the tag validation. * * @param os write stream to the generated XML. */ public void printXmlAttribute(WriteStream os, String name, String text) throws IOException { os.print(" "); os.print(name); os.print("=\""); if (text.startsWith("<%=") && text.endsWith("%>")) { os.print("%="); os.print(xmlAttrText(text.substring(3, text.length() - 2))); os.print("%"); } else os.print(xmlAttrText(text)); os.print("\""); } /** * Generates the XML text. */ public String xmlText(String text) { if (text == null) return ""; CharBuffer cb = new CharBuffer(); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); switch (ch) { case '<': cb.append("<"); break; case '>': cb.append(">"); break; case '&': cb.append("&"); break; case '"': cb.append("""); break; default: cb.append(ch); break; } } return cb.toString(); } /** * Generates the XML text. */ public String xmlAttrText(String text) { if (text == null) return ""; CharBuffer cb = new CharBuffer(); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); switch (ch) { case '&': cb.append("&"); break; case '<': cb.append("<"); break; case '>': cb.append(">"); break; case '"': cb.append("""); break; case '\'': cb.append("'"); break; default: cb.append(ch); break; } } return cb.toString(); } /** * Generates the start location. */ public void generateStartLocation(JspJavaWriter out) throws IOException { out.setLocation(_filename, _startLine); } /** * Generates the start location. */ public void generateEndLocation(JspJavaWriter out) throws IOException { out.setLocation(_filename, _endLine); } /** * generates prologue data. */ public void generatePrologue(JspJavaWriter out) throws Exception { generatePrologueChildren(out); } /** * generates prologue data. */ public void generatePrologueDeclare(JspJavaWriter out) throws Exception { } /** * generates data for prologue children. */ public void generatePrologueChildren(JspJavaWriter out) throws Exception { } /** * generates declaration data. */ public void generateDeclaration(JspJavaWriter out) throws IOException { generateDeclarationChildren(out); } /** * generates data for declaration children. */ public void generateDeclarationChildren(JspJavaWriter out) throws IOException { } /** * generates tag state */ public void generateTagState(JspJavaWriter out) throws Exception { generateTagStateChildren(out); } /** * generates tag state */ public void generateTagStateChildren(JspJavaWriter out) throws Exception { } /** * generates tag state release */ public void generateTagRelease(JspJavaWriter out) throws Exception { generateTagReleaseChildren(out); } /** * generates tag state */ public void generateTagReleaseChildren(JspJavaWriter out) throws Exception { } /** * Generates the code for the tag * * @param out the output writer for the generated java. */ abstract public void generate(JspJavaWriter out) throws Exception; /** * Generates the code for the children. * * @param out the output writer for the generated java. */ public void generateChildren(JspJavaWriter out) throws Exception { } /** * Generates the code for the tag * * @param out the output writer for the generated java. */ public void generateStatic(JspJavaWriter out) throws Exception { } /** * Generates the code for the tag * * @param out the output writer for the generated java. */ public void generateEmpty() throws Exception { generateChildrenEmpty(); } /** * Generates the code for the children. * * @param out the output writer for the generated java. */ public void generateChildrenEmpty() throws Exception { } /** * Converts the string to a boolean. */ protected boolean attributeToBoolean(String attr, String value) throws JspParseException { if (value.equals("yes") || value.equals("true")) return true; else if (value.equals("no") || value.equals("false")) return false; else throw error(L.l("'{0}' is an unknown value for {1}. 'true' or 'false' are the expected values.", value, attr)); } /** * Returns true if in a fragment */ public boolean isInFragment() { for (JspNode node = getParent(); node != null; node = node.getParent()) { if (node instanceof JspAttribute || node instanceof CustomSimpleTag) return true; } return false; } void generateSetParameter(JspJavaWriter out, String obj, Object objValue, Method method, boolean allowRtexpr, String contextVar, boolean isFragment, TagAttributeInfo attrInfo) throws Exception { Class type = method.getParameterTypes()[0]; if (isFragment || JspFragment.class.equals(type)) { generateFragmentParameter(out, obj, objValue, method, allowRtexpr, contextVar); return; } if (objValue instanceof JspAttribute) { JspAttribute attr = (JspAttribute) objValue; if (attr.isStatic()) objValue = attr.getStaticText(); else { String str = "_jsp_str_" + _gen.uniqueId(); out.println("String " + str + " = " + attr.generateValue() + ";"); out.println(obj + "." + method.getName() + "(" + stringToValue(type, str) + ");"); return; } } else if (objValue instanceof JspNode) throw error(L.l("jsp:attribute may not set this attribute.")); String strValue = (String) objValue; String convValue = generateParameterValue(type, strValue, allowRtexpr, attrInfo, _parseState.isELIgnored()); PropertyEditor editor; if (convValue != null) out.println(obj + "." + method.getName() + "(" + convValue + ");"); else if ((editor = PropertyEditorManager.findEditor(type)) != null) { generateSetParameter(out, obj, strValue, method, editor.getClass()); } else throw error(L.l("expected '<%= ... %>' at '{0}' for tag attribute setter '{1}'. Tag attributes which can't be converted from strings must use a runtime attribute expression.", strValue, method.getName() + "(" + type.getName() + ")")); } void generateSetParameter(JspJavaWriter out, String obj, String value, Method method, Class editorClass) throws Exception { Class type = method.getParameterTypes()[0]; String name = "_jsp_editor" + _gen.uniqueId(); out.print("java.beans.PropertyEditor " + name + " = new " + editorClass.getName() + "();"); out.println(name + ".setAsText(\"" + escapeJavaString(value) + "\");"); out.println(obj + "." + method.getName() + "((" + type.getName() + ") " + name + ".getValue());"); } void generateFragmentParameter(JspJavaWriter out, Object obj, Object objValue, Method method, boolean allowRtexpr, String contextVar) throws Exception { out.print(obj + "." + method.getName() + "("); if (objValue instanceof JspFragmentNode) generateFragment(out, (JspFragmentNode) objValue, contextVar); else if (objValue instanceof String) { String string = (String) objValue; int index = _gen.addExpr(string); out.print("new com.caucho.jsp.ELExprFragment(pageContext, _caucho_expr_" + index + ")"); } else { throw error(L.l("can't handle fragment '{0}' of type {1}", objValue, objValue.getClass())); } out.println(");"); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?