/** Returns true if the namespace decl has been printed. */ public boolean hasNamespace(String prefix, String uri) { QName name = getQName(); if (prefix == null || uri == null) return true; else if (prefix.equals(name.getPrefix()) && uri.equals(name.getNamespaceURI())) return true; else return _parent.hasNamespace(prefix, uri); }
/** Creates the child bean. */ @Override public Object create(Object parent, QName qName) throws ConfigException { Class<?> cl = TypeFactory.loadClass(qName); if (cl == null) { ConfigType<?> type = TypeFactory.getFactory().getEnvironmentType(qName); if (type != null) return type.create(parent, qName); throw new ConfigException( L.l( "'{0}.{1}' is an unknown class for element '{2}'", qName.getNamespaceURI(), qName.getLocalName(), qName)); } if (Annotation.class.isAssignableFrom(cl)) { return new AnnotationConfig(cl); } else { XmlBeanConfig<?> config = new XmlBeanConfig(qName, cl, parent); config.setInlineBean(true); // config.setScope("singleton"); return config; } }
/** Adds an attribute. */ @Override public void addAttribute(QName name, String value) throws JspParseException { if (NAME.equals(name)) { _name = value; if (hasRuntimeAttribute(value) || hasELAttribute(value)) throw error(L.l("'name' attribute may not have a runtime value at {0}", value)); } else if (VALUE.equals(name)) _value = value; else throw error(L.l("'{0}' is an invalid attribute in <jsp:param>", name.getName())); }
/** Sets the value of the attribute */ @Override public void setValue(Object bean, QName name, Object value) throws ConfigException { if ("#text".equals(name.getLocalName())) throw new ConfigException(L.l("text is not allowed in this context\n '{0}'", value)); try { _putMethod.invoke(bean, name.getLocalName(), value); } catch (Exception e) { throw ConfigException.create(_putMethod, e); } }
/** Sets the value of the attribute */ @Override public void setText(Object bean, QName name, String value) throws ConfigException { if ("#text".equals(name.getLocalName())) { if (value == null || value.trim().length() == 0) return; throw new ConfigException( L.l( "text is not allowed for bean {0}\n '{1}'", bean.getClass().getName(), value.trim())); } try { _putMethod.invoke(bean, name.getLocalName(), _type.valueOf(value)); } catch (Exception e) { throw ConfigException.create(_putMethod, e); } }
/** Returns the attribute with the given name. */ public Attribute getAttribute(QName qName) { String name = qName.getLocalName(); if ("#text".equals(name)) name = "value"; Attribute attr = _attributeMap.get(name); return attr; }
/** Adds an attribute. */ public void addAttribute(QName name, JspAttribute value) throws JspParseException { // jsp/10j0 if (_gen.isPrototype()) return; throw error( L.l( "jsp:attribute '{0}' is not allowed as a child of XML element <{1}>.", name.getName(), getTagName())); }
/** * Generates the XML text representation for the tag validation. * * @param os write stream to the generated XML. */ public void printXml(WriteStream os) throws IOException { os.print("<" + getTagName()); for (int i = 0; i < _attrNames.size(); i++) { QName name = _attrNames.get(i); String value = _attrValues.get(i); os.print(" " + name.getName() + "=\""); printXmlText(os, value); os.print("\""); } os.print(">"); printXmlChildren(os); os.print("</" + getTagName() + ">"); }
/** Adds an attribute. */ public void addAttribute(QName name, String value) throws XslParseException { if (name.getName().equals("test")) _test = _gen.addExpr(parseExpr(value)); else super.addAttribute(name, value); }
/** * Generates the code for the element. * * @param out the output writer for the generated java. */ public void generate(JspJavaWriter out) throws Exception { out.addText("<"); out.addText(getTagName()); QName qName = getQName(); HashSet<String> prefixes = new HashSet<String>(); if (qName.getNamespaceURI() != null && !_parent.hasNamespace(qName)) { prefixes.add(qName.getPrefix()); out.addText(" "); if (qName.getPrefix() == null || qName.getPrefix().equals("")) out.addText("xmlns=\""); else out.addText("xmlns:" + qName.getPrefix() + "=\""); out.addText(qName.getNamespaceURI()); out.addText("\""); } for (int i = 0; i < _attrNames.size(); i++) { QName name = _attrNames.get(i); String value = _attrValues.get(i); if (name.getNamespaceURI() != null && !prefixes.contains(name.getPrefix()) && !_parent.hasNamespace(name)) { prefixes.add(name.getPrefix()); out.addText(" "); if (name.getPrefix() == null || name.getPrefix().equals("")) out.addText("xmlns=\""); else out.addText("xmlns:" + name.getPrefix() + "=\""); out.addText(name.getNamespaceURI()); out.addText("\""); } out.addText(" "); out.addText(name.getName()); if (value == null || value.equals("")) { // XXX: possibly differ for html/text out.addText("=\"\""); } else { out.addText("=\""); if (value.indexOf("${") < 0 && !value.startsWith("<%") && !value.startsWith("%")) { out.addText(value); } else { String javaValue = generateParameterValue(String.class, value, true, null, _parseState.isELIgnored()); out.println("out.print(" + javaValue + ");"); } out.addText("\""); } } if (getChildren() != null && getChildren().size() > 0) { out.addText(">"); generateChildren(out); out.addText("</" + getTagName() + ">"); } else out.addText(" />"); }
/** Adds an attribute. */ public void addAttribute(QName name, String value) throws XslParseException { if (name.getName().equals("select")) _select = value; else if (name.getName().equals("disable-output-escaping")) _disableOutputEscaping = value; else if (name.getName().equals("separator")) _separator = value; else super.addAttribute(name, value); }
/** * Adds an attribute. * * @param name the attribute name * @param value the attribute value */ public void addAttribute(QName name, String value) throws JspParseException { if (IS_EL_IGNORED.equals(name)) { boolean isIgnored = value.equals("true"); if (_parseState.isELIgnoredPageSpecified() && isIgnored != _parseState.isELIgnored()) throw error(L.l("isELIgnored values conflict")); _parseState.setELIgnored(isIgnored); _parseState.setELIgnoredPageSpecified(true); } /* else if (name.equals("isScriptingInvalid")) _parseState.setScriptingInvalid(value.equals("true")); */ else if (IS_VELOCITY_ENABLED.equals(name)) _parseState.setVelocityEnabled(value.equals("true")); else if (INFO.equals(name)) { String oldInfo = _parseState.getInfo(); if (oldInfo != null && !value.equals(oldInfo)) throw error( L.l( "info '{0}' conflicts with previous value of info '{1}'. Check the .jsp and any included .jsp files for conflicts.", value, oldInfo)); _parseState.setInfo(value); } else if (CONTENT_TYPE.equals(name)) { String oldContentType = _parseState.getContentType(); if (oldContentType != null && !value.equals(oldContentType)) throw error( L.l( "contentType '{0}' conflicts with previous value of contentType '{1}'. Check the .jsp and any included .jsp files for conflicts.", value, oldContentType)); _parseState.setContentType(value); String charEncoding = parseCharEncoding(value); if (charEncoding != null) _parseState.setCharEncoding(charEncoding); } else if (PAGE_ENCODING.equals(name)) { String oldEncoding = _parseState.getPageEncoding(); /* // jsp/01f1 if (oldEncoding != null) { String oldCanonical = Encoding.getMimeName(oldEncoding); String newCanonical = Encoding.getMimeName(value); if (! newCanonical.equals(oldCanonical)) throw error(L.l("pageEncoding '{0}' conflicts with previous value of pageEncoding '{1}'. Check the .jsp and any included .jsp files for conflicts.", value, oldEncoding)); } */ try { _parseState.setPageEncoding(value); // _parseState.setCharEncoding(value); } catch (JspParseException e) { log.log(Level.FINER, e.toString(), e); throw error(e.getMessage()); } } else if (LANGUAGE.equals(name)) { if (!value.equals("java")) throw error(L.l("'{0}' is not supported as a JSP scripting language.", value)); } else if (IMPORT.equals(name)) { _parseState.addImport(value); } else if (SESSION.equals(name)) { boolean isValid = false; if (value.equals("true")) isValid = _parseState.setSession(true); else if (value.equals("false")) isValid = _parseState.setSession(false); else throw error(L.l("session expects 'true' or 'false' at '{0}'", value)); _parseState.markSessionSet(); if (!isValid) throw error(L.l("session is assigned different values.")); } else if (BUFFER.equals(name)) { boolean isValid = _parseState.setBuffer(processBufferSize(value)); _parseState.markBufferSet(); if (!isValid) throw error(L.l("buffer is assigned different values.")); if (_parseState.getBuffer() == 0 && !_parseState.isAutoFlush()) throw error(L.l("buffer must be non-zero when autoFlush is false.")); } else if (ERROR_PAGE.equals(name)) { String errorPage = _parseState.getErrorPage(); String newErrorPage = getRelativeUrl(value); _parseState.setErrorPage(newErrorPage); if (errorPage != null && !errorPage.equals(newErrorPage)) { _parseState.setErrorPage(null); throw error(L.l("errorPage is assigned different value '{0}'.", newErrorPage)); } } else if (IS_ERROR_PAGE.equals(name)) { boolean isValid = false; if (value.equals("true")) isValid = _parseState.setErrorPage(true); else if (value.equals("false")) isValid = _parseState.setErrorPage(false); else throw error(L.l("isErrorPage expects 'true' or 'false' at '{0}'", value)); _parseState.markErrorPage(); if (!isValid) throw error(L.l("isErrorPage is assigned different values.")); } else if (AUTO_FLUSH.equals(name)) { boolean isValid = false; if (value.equals("true")) isValid = _parseState.setAutoFlush(true); else if (value.equals("false")) isValid = _parseState.setAutoFlush(false); else throw error(L.l("autoFlush expects 'true' or 'false' at '{0}'", value)); if (!isValid) throw error(L.l("autoFlush is assigned different values.")); if (_parseState.getBuffer() == 0 && !_parseState.isAutoFlush()) throw error(L.l("buffer must be non-zero when autoFlush is false.")); _parseState.markAutoFlushSet(); } else if (IS_THREAD_SAFE.equals(name)) { boolean isValid = false; if (value.equals("true")) isValid = _parseState.setThreadSafe(true); else if (value.equals("false")) isValid = _parseState.setThreadSafe(false); else throw error(L.l("isThreadSafe expects 'true' or 'false' at '{0}'", value)); _parseState.markThreadSafeSet(); if (!isValid) throw error(L.l("isThreadSafe is assigned different values.")); } else if (EXTENDS.equals(name)) { Class cl = null; try { cl = CauchoSystem.loadClass(value); } catch (Exception e) { throw error(e); } if (!HttpJspPage.class.isAssignableFrom(cl)) throw error( L.l( "'{0}' must implement HttpJspPage. The class named by jsp:directive.page extends='...' must implement HttpJspPage.", value)); Class oldExtends = _parseState.getExtends(); if (oldExtends != null && !cl.equals(oldExtends)) throw error( L.l( "extends '{0}' conflicts with previous value of extends '{1}'. Check the .jsp and any included .jsp files for conflicts.", value, oldExtends.getName())); _parseState.setExtends(cl); } else if (TRIM_WS.equals(name)) { if (value.equals("true")) _parseState.setTrimWhitespace(true); else if (value.equals("false")) _parseState.setTrimWhitespace(false); else throw error(L.l("trimDirectiveWhitespaces expects 'true' or 'false' at '{0}'", value)); } else if (DEFER.equals(name)) { if (value.equals("true")) _parseState.setDeferredSyntaxAllowedAsLiteral(true); else if (value.equals("false")) _parseState.setDeferredSyntaxAllowedAsLiteral(false); else throw error( L.l("deferredSyntaxAllowedAsLiteral expects 'true' or 'false' at '{0}'", value)); } else { throw error( L.l( "'{0}' is an unknown JSP page directive attribute. See the JSP documentation for a complete list of page directive attributes.", name.getName())); } }
/** Adds an attribute. */ public void addAttribute(QName name, String value) throws XslParseException { if (name.getName().equals("name")) _name = value; else if (name.getName().equals("namespace")) _namespace = value; else super.addAttribute(name, value); }
/** Returns true if the name matches. */ public boolean matches(QName name) { if (!_ns.equals(name.getNamespaceURI())) return false; else if (_except != null && _except.matches(name)) return false; else return true; }
/** Adds an attribute. */ public void addAttribute(QName name, String value) throws XslParseException { if (name.getName().equals("href")) { _href = value; } else super.addAttribute(name, value); }