use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class TaglibModelQueryExtension method getAvailableElementContent.
/**
* @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
*/
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
CMNode[] nodes = EMPTY_CMNODE_ARRAY;
ArrayList nodeList = new ArrayList();
// only returns anything if looking for child nodes
if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMElement) {
// get the trackers
IDOMElement elem = (IDOMElement) parentElement;
IStructuredDocument structDoc = elem.getModel().getStructuredDocument();
TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(structDoc);
if (manager != null) {
List trackers = new ArrayList(manager.getTaglibTrackers());
Set prefixes = new HashSet();
// for each tracker add each of its elements to the node list
for (int trackerIndex = 0; trackerIndex < trackers.size(); ++trackerIndex) {
TaglibTracker tracker = ((TaglibTracker) trackers.get(trackerIndex));
CMNamedNodeMap elements = tracker.getElements();
for (int elementIndex = 0; elementIndex < elements.getLength(); ++elementIndex) {
nodeList.add(elements.item(elementIndex));
}
prefixes.add(tracker.getPrefix());
}
String prefix = parentElement.getPrefix();
if (prefixes.contains(prefix)) {
Node parent = parentElement;
while ((parent = parent.getParentNode()) != null && parent.getNodeType() == Node.ELEMENT_NODE) {
prefix = parent.getPrefix();
if (prefix == null || !prefixes.contains(prefix)) {
ModelQuery query = ModelQueryUtil.getModelQuery(parentElement.getOwnerDocument());
if (query != null) {
CMElementDeclaration decl = query.getCMElementDeclaration((Element) parent);
if (decl != null && !fExtensions.contains(this)) {
fExtensions.push(this);
nodeList.addAll(query.getAvailableContent((Element) parent, decl, includeOptions));
fExtensions.pop();
}
}
break;
}
}
}
nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
}
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class TaglibHelper method getModelQuery.
/**
* @return Returns the fModelQuery.
*/
public ModelQuery getModelQuery(IDocument doc) {
IStructuredModel model = null;
ModelQuery mq = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(doc);
mq = ModelQueryUtil.getModelQuery(model);
} finally {
if (model != null)
model.releaseFromRead();
}
return mq;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class TaglibHelper method getCustomTag.
public CustomTag getCustomTag(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) {
List results = new ArrayList();
boolean isIterationTag = false;
String tagClass = null;
String teiClass = null;
if (problems == null)
problems = new ArrayList();
ModelQuery mq = getModelQuery(structuredDoc);
if (mq != null) {
TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc);
if (mgr != null) {
List trackers = mgr.getCMDocumentTrackers(-1);
Iterator taglibs = trackers.iterator();
CMDocument doc = null;
CMNamedNodeMap elements = null;
while (taglibs.hasNext()) {
doc = (CMDocument) taglibs.next();
CMNode node = null;
if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
if (node instanceof CMNodeWrapper) {
node = ((CMNodeWrapper) node).getOriginNode();
}
TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node;
tagClass = tldElementDecl.getTagclass();
teiClass = tldElementDecl.getTeiclass();
isIterationTag = isIterationTag(tldElementDecl, structuredDoc, customTag, problems);
/*
* Although clearly not the right place to add validation
* design-wise, this is the first time we have the
* necessary information to validate the tag class.
*/
validateTagClass(structuredDoc, customTag, tldElementDecl, problems);
// 1.2+ taglib style
addVariables(results, node, customTag);
// for 1.1 need more info from taglib tracker
if (doc instanceof TaglibTracker) {
String uri = ((TaglibTracker) doc).getURI();
String prefix = ((TaglibTracker) doc).getPrefix();
// only for 1.1 taglibs
addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems);
}
break;
}
}
}
}
return new CustomTag(tagToAdd, tagClass, teiClass, (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]), isIterationTag);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class TaglibHelper method getTaglibVariables.
/**
* @param tagToAdd
* is the name of the tag whose variables we want
* @param structuredDoc
* is the IStructuredDocument where the tag is found
* @param customTag
* is the IStructuredDocumentRegion opening tag for the custom
* tag
* @param problems problems that are generated while creating variables are added to this collection
*/
public TaglibVariable[] getTaglibVariables(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) {
List results = new ArrayList();
if (problems == null)
problems = new ArrayList();
ModelQuery mq = getModelQuery(structuredDoc);
if (mq != null) {
TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc);
// mq).getTaglibSupport();
if (mgr == null)
return new TaglibVariable[0];
List trackers = mgr.getCMDocumentTrackers(-1);
Iterator taglibs = trackers.iterator();
// TaglibSupport support = ((TaglibModelQuery)
// mq).getTaglibSupport();
// if (support == null)
// return new TaglibVariable[0];
//
// Iterator taglibs =
// support.getCMDocuments(customTag.getStartOffset()).iterator();
CMDocument doc = null;
CMNamedNodeMap elements = null;
while (taglibs.hasNext()) {
doc = (CMDocument) taglibs.next();
CMNode node = null;
if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
if (node instanceof CMNodeWrapper) {
node = ((CMNodeWrapper) node).getOriginNode();
}
TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node;
/*
* Although clearly not the right place to add validation
* design-wise, this is the first time we have the
* necessary information to validate the tag class.
*/
boolean tagClassFound = validateTagClass(structuredDoc, customTag, tldElementDecl, problems);
// 1.2+ taglib style
addVariables(results, node, customTag);
// for 1.1 need more info from taglib tracker
if (tagClassFound && doc instanceof TaglibTracker) {
String uri = ((TaglibTracker) doc).getURI();
String prefix = ((TaglibTracker) doc).getPrefix();
// only for 1.1 taglibs
addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems);
}
}
}
}
return (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery 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;
}
Aggregations