use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class BaseNodeActionManager method contributeReplaceActions.
protected void contributeReplaceActions(IMenuManager menu, List selectedNodeList, int ic, int vc) {
// 'Replace With...' actions
//
IMenuManager replaceWithMenu = new MyMenuManager(XMLUIMessages._UI_MENU_REPLACE_WITH);
menu.add(replaceWithMenu);
if ((modelQuery.getEditMode() == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) && (selectedNodeList.size() > 0)) {
Node node = (Node) selectedNodeList.get(0);
Node parentNode = node.getParentNode();
if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) {
Element parentElement = (Element) parentNode;
CMElementDeclaration parentED = modelQuery.getCMElementDeclaration(parentElement);
if (parentED != null) {
List replaceActionList = new Vector();
modelQuery.getReplaceActions(parentElement, parentED, selectedNodeList, ic, vc, replaceActionList);
addActionHelper(replaceWithMenu, replaceActionList);
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLTableTreePropertyDescriptorFactory method createTextPropertyDescriptor.
public IPropertyDescriptor createTextPropertyDescriptor(Text text) {
IPropertyDescriptor result = null;
Node parentNode = text.getParentNode();
if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) {
Element parentElement = (Element) parentNode;
ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument());
CMElementDeclaration ed = null;
if (mq != null) {
ed = mq.getCMElementDeclaration(parentElement);
}
if (ed != null) {
result = createPropertyDescriptorHelper(HACK, parentElement, ed);
} else {
result = createDefaultPropertyDescriptor(parentElement.getNodeName());
}
}
if (result == null) {
result = new TextPropertyDescriptor(HACK, HACK);
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLTreeExtension method getElementValueHelper.
public String getElementValueHelper(Element element) {
String result = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if ((result == null) && (mq != null)) {
CMElementDeclaration ed = mq.getCMElementDeclaration(element);
if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
// $NON-NLS-1$
result = decriptionBuilder.buildDescription(ed);
}
}
// $NON-NLS-1$
return result != null ? result : "";
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class NewXMLGenerator method createXMLDocument.
public ByteArrayOutputStream createXMLDocument(String xmlFileName, String charset) throws Exception {
if (charset == null) {
charset = getUserPreferredCharset();
if (charset == null) {
// $NON-NLS-1$
charset = "UTF-8";
}
}
CMDocument cmDocument = getCMDocument();
Assert.isNotNull(cmDocument);
Assert.isNotNull(getRootElementName());
// create the xml model
CMNamedNodeMap nameNodeMap = cmDocument.getElements();
CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) nameNodeMap.getNamedItem(getRootElementName());
Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(xmlDocument);
// this 'uglyTempHack' flag is required in order to supress the
// creation a default encoding
// we'll handle this later in the domWriter.print() method used below
//
contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = true;
contentBuilder.setBuildPolicy(buildPolicy);
contentBuilder.setOptionalElementDepthLimit(optionalElementDepthLimit);
contentBuilder.setExternalCMDocumentSupport(new MyExternalCMDocumentSupport(namespaceInfoList, xmlFileName));
contentBuilder.createDefaultRootContent(cmDocument, cmElementDeclaration, namespaceInfoList);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, charset);
DOMWriter domWriter = new DOMWriter(outputStreamWriter);
// TODO... instead of relying on file extensions, we need to keep
// track of the grammar type
// better yet we should reate an SSE document so that we can format it
// nicely before saving
// then we won't need the DOMWriter at all
//
domWriter.print(xmlDocument, charset, cmDocument.getNodeName(), getNonWhitespaceString(getPublicId()), getNonWhitespaceString(getSystemId()));
outputStream.flush();
outputStream.close();
return outputStream;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLTableTreeContentProvider method getElementValueHelper.
private String getElementValueHelper(Element element) {
String result = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if ((result == null) && (mq != null)) {
CMElementDeclaration ed = mq.getCMElementDeclaration(element);
if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
// $NON-NLS-1$
result = descriptionBuilder.buildDescription(ed);
}
}
// $NON-NLS-1$
return result != null ? result : "";
}
Aggregations