use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class AttributeContextInformationProvider method getInfoForElement.
/**
* @param node
*/
private IContextInformation[] getInfoForElement(IDOMNode node) {
IContextInformation[] results = EMPTY_CONTEXT_INFO;
CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) node);
if (decl != null) {
CMNamedNodeMap attributes = decl.getAttributes();
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, decl, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
attributes = allAttributes;
String attrContextString = node.getNodeName();
// $NON-NLS-1$
StringBuffer attrInfo = new StringBuffer(" ");
// $NON-NLS-1$
String name = "";
HashMap attrPosMap = new HashMap();
int pos = 0;
int length = 0;
int numPerLine = 8;
CMAttributeDeclaration[] sortedAttrs = getSortedAttributes(attributes);
for (int i = 0; i < sortedAttrs.length; i++) {
name = sortedAttrs[i].getAttrName();
length = name.length();
pos = attrInfo.length();
attrInfo.append(name);
if (sortedAttrs[i].getUsage() == CMAttributeDeclaration.REQUIRED) {
// $NON-NLS-1$
attrInfo.append("*");
length++;
}
if (i < attributes.getLength() - 1) {
// $NON-NLS-1$
attrInfo.append(" ");
if ((i != 0) && (i % numPerLine == 0)) {
// $NON-NLS-1$
attrInfo.append("\n ");
}
}
attrPosMap.put(name, new Position(pos, length));
}
if (!attrInfo.toString().trim().equals("")) {
return new IContextInformation[] { new AttributeContextInformation(attrContextString, attrInfo.toString(), attrPosMap) };
}
}
return results;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class AttributeContextInformationProvider method getInfoForText.
/**
* @param node
*/
IContextInformation[] getInfoForText(IDOMNode node) {
Node parent = node.getParentNode();
String contextString = node.getNodeName();
// $NON-NLS-1$
StringBuffer info = new StringBuffer(" ");
if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)) {
CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) parent);
CMContent content = decl.getContent();
if (content instanceof CMGroup) {
CMGroup cmGroup = (CMGroup) content;
CMNodeList children = cmGroup.getChildNodes();
CMNode cmNode = null;
for (int i = 0; i < children.getLength(); i++) {
cmNode = children.item(i);
contextString = cmNode.getNodeName();
if (contextString != null) {
// $NON-NLS-1$ //$NON-NLS-2$
info.append("<" + cmNode.getNodeName() + ">");
if (i < children.getLength() - 1) {
// $NON-NLS-1$
info.append(" ");
}
}
}
}
}
if (!info.toString().trim().equals("")) {
return new IContextInformation[] { new ContextInformation(contextString, info.toString()) };
} else {
return EMPTY_CONTEXT_INFO;
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLHyperlinkDetector method getCMElementDeclaration.
/**
* Get the CMElementDeclaration for an element
*
* @param element
* @return CMElementDeclaration
*/
private CMElementDeclaration getCMElementDeclaration(Element element) {
CMElementDeclaration ed = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if (mq != null) {
ed = mq.getCMElementDeclaration(element);
}
return ed;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class JSPModelQueryCMProvider method getCorrespondingCMDocument.
/**
* Returns the CMDocument that corresponds to the DOM Node. or null if no
* CMDocument is appropriate for the DOM Node.
*/
public CMDocument getCorrespondingCMDocument(Node node) {
CMDocument jcmdoc = null;
if (node instanceof IDOMNode) {
IDOMModel model = ((IDOMNode) node).getModel();
String modelPath = model.getBaseLocation();
if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
jcmdoc = JSPCMDocumentFactory.getCMDocument(version);
}
}
if (jcmdoc == null) {
jcmdoc = JSPCMDocumentFactory.getCMDocument();
}
CMDocument result = null;
try {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String elementName = node.getNodeName();
// test to see if this node belongs to JSP's CMDocument (case
// sensitive)
CMElementDeclaration dec = (CMElementDeclaration) jcmdoc.getElements().getNamedItem(elementName);
if (dec != null) {
result = jcmdoc;
}
}
String prefix = node.getPrefix();
if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) {
// check position dependent
IDOMNode xmlNode = (IDOMNode) node;
TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument());
if (tldmgr != null) {
List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
// there shouldn't be more than one cmdocument returned
if (documents != null && documents.size() > 0)
result = (CMDocument) documents.get(0);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class TagModelQueryCMProvider method getCorrespondingCMDocument.
/**
* Returns the CMDocument that corresponds to the DOM Node. or null if no
* CMDocument is appropriate for the DOM Node.
*/
public CMDocument getCorrespondingCMDocument(Node node) {
CMDocument tagdoc = null;
if (node instanceof IDOMNode) {
IDOMModel model = ((IDOMNode) node).getModel();
String modelPath = model.getBaseLocation();
if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
tagdoc = TAGCMDocumentFactory.getCMDocument(version);
}
}
CMDocument result = null;
try {
if (node.getNodeType() == Node.ELEMENT_NODE && tagdoc != null) {
String elementName = node.getNodeName();
// test to see if this node belongs to JSP's CMDocument (case
// sensitive)
CMElementDeclaration dec = (CMElementDeclaration) tagdoc.getElements().getNamedItem(elementName);
if (dec != null) {
result = tagdoc;
}
}
String prefix = node.getPrefix();
if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) {
// check position dependent
IDOMNode xmlNode = (IDOMNode) node;
TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument());
if (tldmgr != null) {
List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
// there shouldn't be more than one cmdocument returned
if (documents != null && !documents.isEmpty())
result = (CMDocument) documents.get(0);
}
}
} catch (Exception e) {
e.printStackTrace();
}
// }
return result;
}
Aggregations