/** * generateStartTag method * * @return java.lang.String * @param element Element */ public String generateStartTag(Element element) { if (element == null) return null; ElementImpl impl = (ElementImpl) element; if (impl.isJSPTag()) { // check if JSP content type and JSP Document IDOMDocument document = (IDOMDocument) element.getOwnerDocument(); if (document != null && document.isJSPType()) { if (document.isJSPDocument() && !impl.hasChildNodes()) { impl.setJSPTag(false); } } else { impl.setJSPTag(false); } } if (impl.isCommentTag() && impl.getExistingAdapter(TagAdapter.class) == null) { CommentElementRegistry registry = CommentElementRegistry.getInstance(); registry.setupCommentElement(impl); } // first check if tag adapter exists TagAdapter adapter = (TagAdapter) impl.getExistingAdapter(TagAdapter.class); if (adapter != null) { String startTag = adapter.getStartTag(impl); if (startTag != null) return startTag; } StringBuffer buffer = new StringBuffer(); if (impl.isCommentTag()) { if (impl.isJSPTag()) buffer.append(JSPTag.COMMENT_OPEN); else buffer.append(COMMENT_OPEN); String tagName = generateTagName(element); if (tagName != null) buffer.append(tagName); } else if (impl.isJSPTag()) { buffer.append(JSPTag.TAG_OPEN); String tagName = generateTagName(element); if (tagName != null) buffer.append(tagName); if (impl.isContainer()) return buffer.toString(); // JSP container } else { buffer.append('<'); String tagName = generateTagName(element); if (tagName != null) buffer.append(tagName); } NamedNodeMap attributes = element.getAttributes(); int length = attributes.getLength(); for (int i = 0; i < length; i++) { AttrImpl attr = (AttrImpl) attributes.item(i); if (attr == null) continue; buffer.append(' '); String attrName = generateAttrName(attr); if (attrName != null) buffer.append(attrName); String attrValue = generateAttrValue(attr); if (attrValue != null) { // attr name only for HTML boolean and JSP buffer.append('='); buffer.append(attrValue); } } String closeTag = generateCloseTag(element); if (closeTag != null) buffer.append(closeTag); return buffer.toString(); }