use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class JSPModelQueryExtension method getAvailableElementContent.
/**
* Originally taken from JSPContentAssistProcessor
*
* @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 IDOMNode) {
IDOMNode node = (IDOMNode) parentElement;
// get position dependent CMDocuments and insert their tags as
// proposals
ModelQueryAdapter mqAdapter = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
mqAdapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class);
} else {
mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
}
if (mqAdapter != null) {
CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node);
if (doc != null) {
CMDocument jcmdoc = getDefaultJSPCMDocument(node);
CMNamedNodeMap jspelements = jcmdoc.getElements();
/* For a built-in JSP action the content model is properly
* set up, so don't just blindly add the rest--unless this
* will be a direct child of the document
*/
if (jspelements != null && (!(doc instanceof JSPCMDocument) || node.getNodeType() == Node.DOCUMENT_NODE)) {
List rejectElements = new ArrayList();
// determine if the document is in XML form
Document domDoc = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
domDoc = (Document) node;
} else {
domDoc = node.getOwnerDocument();
}
// Show XML tag forms of JSP markers if jsp:root is
// the document element OR it's HTML but
// isn't really in the text.
// If the document isn't strictly XML, pull out the
// XML tag forms it is xml format
rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET);
rejectElements.add(JSP12Namespace.ElementName.EXPRESSION);
rejectElements.add(JSP12Namespace.ElementName.DECLARATION);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE);
rejectElements.add(JSP12Namespace.ElementName.TEXT);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_TAG);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_ATTRIBUTE);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_VARIABLE);
if (isXMLFormat(domDoc)) {
// jsp actions
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.USEBEAN);
rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.FORWARD);
rejectElements.add(JSP12Namespace.ElementName.PLUGIN);
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.PARAM);
rejectElements.add(JSP12Namespace.ElementName.PARAMS);
}
// don't show jsp:root if a document element already
// exists
Element docElement = domDoc.getDocumentElement();
if (docElement != null && ((docElement.getNodeName().equals(TAG_JSP_ROOT)) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null)))) {
rejectElements.add(JSP12Namespace.ElementName.ROOT);
}
for (int j = 0; j < jspelements.getLength(); j++) {
CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j);
if (!rejectElements.contains(ed.getNodeName())) {
nodeList.add(ed);
}
}
}
} else // No cm document (such as for the Document (a non-Element) node itself)
{
CMNamedNodeMap jspElements = getDefaultJSPCMDocument(node).getElements();
int length = jspElements.getLength();
for (int i = 0; i < length; i++) {
nodeList.add(jspElements.item(i));
}
}
}
nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument 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.CMDocument 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.CMDocument in project webtools.sourceediting by eclipse.
the class HTML5ContentModelTest method checkDocument.
private void checkDocument(Object documentKey) {
CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey.toString());
assertNotNull("missing doc:" + documentKey.toString(), document);
CMNamedNodeMap elements = document.getElements();
for (int i = 0; i < elements.getLength(); i++) {
CMNode item = elements.item(i);
verifyElementDeclarationHasName(item);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testDynamicAttributes.
public void testDynamicAttributes() throws Exception {
final String testName = "testDynamicAttributes";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
if (!project.exists()) {
project = BundleResourceUtil.createSimpleProject(testName, null, null);
BundleResourceUtil.copyBundleEntriesIntoWorkspace(TESTFILES_PATHSTRING + "testDynamicAttributes", "/testDynamicAttributes");
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
CMDocumentFactoryTLD factory = new CMDocumentFactoryTLD();
ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/" + testName + "/"));
assertEquals("There should only be one taglib record", 1, records.length);
CMDocument document = factory.createCMDocument(records[0]);
CMNamedNodeMap elements = document.getElements();
assertNotNull("No elements for the CM Document", elements);
CMNode node = elements.getNamedItem("bar");
assertTrue("Node must be a CMElementDeclarationImpl", node instanceof CMElementDeclarationImpl);
assertEquals("Dynamic attributes must be set to 'true'", "true", ((CMElementDeclarationImpl) node).getDynamicAttributes());
}
Aggregations