use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class TestCatalogRetrivalAndModelCreation method doCM_directURITest_checkElementCount.
private void doCM_directURITest_checkElementCount(String EXPECTED_URI, int count) throws MalformedURLException, IOException {
ContentModelManager contentModelManager = ContentModelManager.getInstance();
CMDocument contentModel = contentModelManager.createCMDocument(EXPECTED_URI, null);
assertNotNull("expected to create content model for " + EXPECTED_URI, contentModel);
int actualCount = contentModel.getElements().getLength();
assertEquals("count of element declarations found for content model create from " + EXPECTED_URI, contentModel.getElements().getLength(), actualCount);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class TestCatalogRetrivalAndModelCreation method doURI_CMTest.
void doURI_CMTest(String EXPECTED_URI) throws MalformedURLException, IOException {
ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
String resolved = xmlCatalog.resolveURI(EXPECTED_URI);
assertNotNull("expected to find " + EXPECTED_URI, resolved);
ContentModelManager contentModelManager = ContentModelManager.getInstance();
CMDocument contentModel = contentModelManager.createCMDocument(resolved, null);
assertNotNull("expected to create content model for " + EXPECTED_URI, contentModel);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method getAvailableRootChildren.
// returns a list of CMElementDeclarations
protected List getAvailableRootChildren(Document document, int childIndex) {
List list = null;
// extract the valid 'root' node name from the DocumentType Node
DocumentType docType = document.getDoctype();
String rootName = null;
if (docType != null) {
rootName = docType.getNodeName();
}
if (rootName == null) {
return new ArrayList(0);
}
for (Node child = document.getFirstChild(); child != null; child = child.getNextSibling()) {
// is it required to be an Element?
if ((child.getNodeType() == Node.ELEMENT_NODE) && stringsEqual(child.getNodeName(), rootName)) {
// count it as present
if ((child instanceof IDOMNode) && ((((IDOMNode) child).getStartStructuredDocumentRegion() == null) || (((IDOMNode) child).getEndStructuredDocumentRegion() == null))) {
continue;
}
if (Debug.displayInfo) {
// $NON-NLS-1$
System.out.println(rootName + " already present!");
}
setErrorMessage(NLS.bind(XMLUIMessages.The_document_element__, (new Object[] { rootName })));
return new ArrayList(0);
}
}
list = new ArrayList(1);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
if (modelQuery != null) {
CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
if (cmdoc != null) {
if (rootName != null) {
CMElementDeclaration rootDecl = (CMElementDeclaration) cmdoc.getElements().getNamedItem(rootName);
if (rootDecl != null) {
list.add(rootDecl);
} else {
// supply the given document name anyway, even if it
// is an error
list.add(new SimpleCMElementDeclaration(rootName));
if (Debug.displayInfo || Debug.displayWarnings) {
// $NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
System.out.println("No definition found for " + rootName + " in " + docType.getPublicId() + "/" + docType.getSystemId());
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
// $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
if (location.length() > 0) {
setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for_in, (new Object[] { rootName, location })));
} else {
setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for, (new Object[] { rootName })));
}
}
}
} else {
if (Debug.displayInfo || Debug.displayWarnings) {
// $NON-NLS-1$
System.out.println("No content model found.");
}
// $NON-NLS-1$
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
// $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
if (location.length() > 0) {
setErrorMessage(NLS.bind(XMLUIMessages.No_content_model_for, (new Object[] { location })));
} else {
setErrorMessage(XMLUIMessages.No_content_model_found_UI_);
}
}
}
return list;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method computeEntityReferenceProposals.
/**
* return all possible EntityReferenceProposals (according to current
* position in doc)
*/
protected ICompletionProposal[] computeEntityReferenceProposals(int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) {
// only handle XML content for now
// ICompletionProposals
Vector proposals = new Vector();
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
if ((completionRegion != null) && (completionRegion.getType() == DOMRegionContext.XML_CONTENT)) {
int nodeOffset = documentPosition - sdRegion.getStartOffset(completionRegion);
String regionText = sdRegion.getFullText(completionRegion);
// the previous region...there might be a better way to do this
if ((regionText != null) && regionText.trim().equals("") && (documentPosition > 0)) {
// $NON-NLS-1$
IStructuredDocumentRegion prev = treeNode.getStructuredDocument().getRegionAtCharacterOffset(documentPosition - 1);
if ((prev != null) && prev.getText().equals("&")) {
// $NON-NLS-1$
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206680
// examine previous region
sdRegion = prev;
completionRegion = prev.getLastRegion();
regionText = prev.getFullText();
nodeOffset = 1;
}
}
// string must start w/ &
if ((regionText != null) && regionText.startsWith("&")) {
// $NON-NLS-1$
// $NON-NLS-1$
String key = (nodeOffset > 0) ? regionText.substring(1, nodeOffset) : "";
// get entity proposals, passing in the appropriate start
// string
ModelQuery mq = ModelQueryUtil.getModelQuery(((Node) treeNode).getOwnerDocument());
if (mq != null) {
CMDocument xmlDoc = mq.getCorrespondingCMDocument(treeNode);
CMNamedNodeMap cmmap = null;
Properties entities = null;
if (xmlDoc != null) {
cmmap = xmlDoc.getEntities();
}
if (cmmap != null) {
entities = mapToProperties(cmmap);
} else // 224787 in absence of content model, just use
// minimal 5 entities
{
entities = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("quot", "\"");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("apos", "'");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("amp", "&");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("lt", "<");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("gt", ">");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("nbsp", " ");
}
addEntityProposals(proposals, entities, key, nodeOffset, sdRegion, completionRegion);
}
}
}
return (ICompletionProposal[]) ((proposals.size() > 0) ? proposals.toArray(new ICompletionProposal[proposals.size()]) : null);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class BaseNodeActionManager method contributeAddSiblingActions.
protected void contributeAddSiblingActions(IMenuManager menu, Node node, int ic, int vc) {
IMenuManager addBeforeMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_BEFORE);
IMenuManager addAfterMenu = new MyMenuManager(XMLUIMessages._UI_MENU_ADD_AFTER);
menu.add(addBeforeMenu);
menu.add(addAfterMenu);
Node parentNode = node.getParentNode();
if (parentNode != null) {
int index = getIndex(parentNode, node);
if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
Element parentElement = (Element) parentNode;
CMElementDeclaration parentED = modelQuery.getCMElementDeclaration(parentElement);
if (parentED != null) {
// 'Add Before...' and 'Add After...' actions
//
List modelQueryActionList = new ArrayList();
modelQuery.getInsertActions(parentElement, parentED, index, ic, vc, modelQueryActionList);
addActionHelper(addBeforeMenu, modelQueryActionList);
modelQueryActionList = new ArrayList();
modelQuery.getInsertActions(parentElement, parentED, index + 1, ic, vc, modelQueryActionList);
addActionHelper(addAfterMenu, modelQueryActionList);
}
// add COMMENT and PI before and after
contributePIAndCommentActions(addBeforeMenu, parentElement, parentED, index);
contributePIAndCommentActions(addAfterMenu, parentElement, parentED, index + 1);
// add PCDATA, CDATA_SECTION before and after
contributeTextNodeActions(addBeforeMenu, parentElement, parentED, index);
contributeTextNodeActions(addAfterMenu, parentElement, parentED, index + 1);
// add NEW ELEMENT before and after
contributeUnconstrainedAddElementAction(addBeforeMenu, parentElement, parentED, index);
contributeUnconstrainedAddElementAction(addAfterMenu, parentElement, parentED, index + 1);
} else if (parentNode.getNodeType() == Node.DOCUMENT_NODE) {
Document document = (Document) parentNode;
CMDocument cmDocument = modelQuery.getCorrespondingCMDocument(parentNode);
if (cmDocument != null) {
// add possible root element insertions
//
List modelQueryActionList = new ArrayList();
modelQuery.getInsertActions(document, cmDocument, index, ic, vc, modelQueryActionList);
addActionHelper(addAfterMenu, modelQueryActionList);
modelQueryActionList = new ArrayList();
modelQuery.getInsertActions(document, cmDocument, index + 1, ic, vc, modelQueryActionList);
addActionHelper(addAfterMenu, modelQueryActionList);
}
// add COMMENT and PI before and after
contributePIAndCommentActions(addBeforeMenu, document, index);
contributePIAndCommentActions(addAfterMenu, document, index + 1);
// add ELEMENT before and after
contributeUnconstrainedAddElementAction(addBeforeMenu, document, index);
contributeUnconstrainedAddElementAction(addAfterMenu, document, index + 1);
}
}
}
Aggregations