use of org.eclipse.wst.xml.core.internal.commentelement.impl.CommentElementRegistry in project webtools.sourceediting by eclipse.
the class XMLGeneratorImpl method generateStartTag.
/**
* 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())
// JSP container
return buffer.toString();
} 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();
}
use of org.eclipse.wst.xml.core.internal.commentelement.impl.CommentElementRegistry in project webtools.sourceediting by eclipse.
the class DocumentImpl method createCommentElement.
public Element createCommentElement(String tagName, boolean isJSPTag) throws DOMException {
Element result = null;
if (!isJSPType() && isJSPTag) {
throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, DOMMessages.INVALID_MODIFICATION_ERR);
}
ElementImpl element = (ElementImpl) createElement(tagName);
element.setJSPTag(isJSPTag);
CommentElementRegistry registry = CommentElementRegistry.getInstance();
if (registry.setupCommentElement(element)) {
result = element;
} else {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, DOMMessages.INVALID_CHARACTER_ERR);
}
return result;
}
Aggregations