use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class XMLGeneratorImpl method generateTagName.
/**
*/
public String generateTagName(Element element) {
if (element == null)
return null;
IDOMElement xe = (IDOMElement) element;
String tagName = element.getTagName();
if (tagName == null)
return null;
if (xe.isJSPTag()) {
if (tagName.equals(JSPTag.JSP_EXPRESSION))
return JSPTag.EXPRESSION_TOKEN;
if (tagName.equals(JSPTag.JSP_DECLARATION))
return JSPTag.DECLARATION_TOKEN;
if (tagName.equals(JSPTag.JSP_DIRECTIVE))
return JSPTag.DIRECTIVE_TOKEN;
if (tagName.startsWith(JSPTag.JSP_DIRECTIVE)) {
// after '.'
int offset = JSPTag.JSP_DIRECTIVE.length() + 1;
return (JSPTag.DIRECTIVE_TOKEN + tagName.substring(offset));
}
return (xe.isCommentTag()) ? tagName : null;
} else if (tagName.startsWith(JSPTag.TAG_OPEN)) {
if (!tagName.endsWith(JSPTag.TAG_CLOSE)) {
// close JSP
return (tagName + JSPTag.TAG_CLOSE);
}
} else if (xe.isCommentTag()) {
String prefix = element.getPrefix();
if (prefix.equals(SSI_PREFIX)) {
return (SSI_TOKEN + element.getLocalName());
}
} else {
if (// global tag
!xe.isJSPTag() && xe.isGlobalTag() && CMNodeUtil.getElementDeclaration(xe) != null) {
String newName = tagName;
switch(getTagNameCase(xe)) {
case DocumentTypeAdapter.UPPER_CASE:
newName = tagName.toUpperCase(Locale.ENGLISH);
break;
case DocumentTypeAdapter.LOWER_CASE:
newName = tagName.toLowerCase(Locale.ENGLISH);
break;
}
if (newName != tagName) {
tagName = newName;
setTagName(element, tagName);
}
}
}
return tagName;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class TestAttributesOrder method ensureDocumentHasGrammar.
/**
* Reusable test to make sure the XML model for the given file has a grammar.
*
* @param file
* the file containing the XML document.
*/
private void ensureDocumentHasGrammar(IFile file) throws IOException, CoreException {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", cmElementDeclaration);
assertNotNull("No content assist available for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", modelQuery.getAvailableContent(documentElement, cmElementDeclaration, ModelQuery.INCLUDE_CHILD_NODES));
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class TestCyclicGroupReferences method testCyclicGroupReferences.
/**
* Test CMVisitor for cyclic group references.
*/
public void testCyclicGroupReferences() {
// $NON-NLS-1$
IFile file = getFile("Test.xml");
CMVisitor cmVisitor = new CMVisitor();
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
cmElementDeclaration);
cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
} catch (Throwable th) {
fail("Test failed :" + th.getClass().getName());
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class TestOpenEditorXML method testBug151069.
/**
* Test structured document is reloaded on resource change
*/
public void testBug151069() {
IDocument doc = fEditor.getAdapter(IDocument.class);
doc.set("<html><body><h1>Title</h1></body></html>");
// set h1 to readonly
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMModel model = null;
try {
model = (IDOMModel) modelManager.getExistingModelForEdit(doc);
if (model != null) {
NodeList nl = model.getDocument().getElementsByTagName("h1");
IDOMElement h1 = (IDOMElement) nl.item(0);
h1.setEditable(false, true);
}
} finally {
if (model != null)
model.releaseFromEdit();
}
String newContent = "new content";
((IDocumentExtension4) doc).set(newContent, fFile.getModificationStamp());
assertEquals("Set contents in document with read only regions failed", newContent, doc.get());
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class EXSLTContentAssistRequestFactory method getContentAssistRequest.
/**
* Get the appropriate content assist request class for the XSL request.
* @return
*/
public IContentAssistProposalRequest getContentAssistRequest() {
NamedNodeMap nodeMap = xmlNode.getAttributes();
IDOMElement element = (IDOMElement) xmlNode;
IContentAssistProposalRequest proposal = commonAttributeProposals(nodeMap);
if (proposal instanceof NullContentAssistRequest) {
if (isElementProposal(element)) {
proposal = getNullProposal();
}
}
return proposal;
}
Aggregations