use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class HTMLFormatter method getBreakSpaces.
/**
*/
protected String getBreakSpaces(Node node) {
if (node == null)
return null;
StringBuffer buffer = new StringBuffer();
String delim = ((IDOMNode) node).getModel().getStructuredDocument().getLineDelimiter();
if (delim != null && delim.length() > 0)
buffer.append(delim);
String indent = getIndent();
if (indent != null && indent.length() > 0) {
for (Node parent = node.getParentNode(); parent != null; parent = parent.getParentNode()) {
if (parent.getNodeType() != Node.ELEMENT_NODE)
break;
// ignore omitted tag
if (((IDOMNode) parent).getStartStructuredDocumentRegion() == null)
continue;
IDOMElement element = (IDOMElement) parent;
if (element.getPrefix() != null) {
String localName = element.getLocalName();
// special for html:html
if (localName != null && !localName.equals(HTML_NAME)) {
buffer.append(indent);
}
continue;
} else {
String localName = element.getLocalName();
if (HTML_NAME.equalsIgnoreCase(localName) || HEAD_NAME.equalsIgnoreCase(localName))
break;
}
CMElementDeclaration decl = getElementDeclaration(element);
if (decl != null && decl.supports(HTMLCMProperties.SHOULD_INDENT_CHILD_SOURCE)) {
boolean shouldIndent = isIdentable(node, parent);
if (shouldIndent)
buffer.append(indent);
}
}
}
return buffer.toString();
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class BaseAssociationProvider method getCMDataType.
public CMDataType getCMDataType(Text text) {
CMDataType result = null;
Node parentNode = text.getParentNode();
if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
CMElementDeclaration ed = getCMElementDeclaration((Element) parentNode);
result = ed.getDataType();
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class InferredGrammarBuildingCMDocumentLoader method handleElement.
public void handleElement(Element element) {
CMElementDeclaration parentInferredCMElementDeclaration = inferredCMElementDeclaration;
if (inferredCMDocument == null) {
// $NON-NLS-1$
String cacheKey = "inferred-document";
// $NON-NLS-1$
inferredCMDocument = inferredGrammarFactory.createCMDocument("");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
cmDocumentManager.addCMDocument("", "", cacheKey, "DTD", inferredCMDocument);
createdCMDocumentTable.put(cacheKey, inferredCMDocument);
}
inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, false);
if (parentInferredCMElementDeclaration != null) {
inferredGrammarFactory.createCMContent(inferredCMDocument, parentInferredCMElementDeclaration, inferredCMDocument, inferredCMElementDeclaration, false, null);
}
visitChildNodes(element);
// reset the 'current' state to inital values
inferredCMElementDeclaration = parentInferredCMElementDeclaration;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class InferredGrammarBuildingCMDocumentLoader method handleElementNS.
public void handleElementNS(Element element) {
CMDocument parentInferredCMDocument = inferredCMDocument;
CMElementDeclaration parentInferredCMElementDeclaration = inferredCMElementDeclaration;
inferredCMDocument = null;
inferredCMElementDeclaration = null;
// by adding the element to the namespaceTable, handleGrammar() will get called for any schema references
if (element.getParentNode() != document) {
namespaceTable.addElement(element);
}
String prefix = element.getPrefix();
String uri = namespaceTable.getURIForPrefix(prefix);
if (uri == null && element.getParentNode() == document) {
// when this is the root element
// we need to add an implied "no namespace schema location"
// $NON-NLS-1$
uri = "ommitted-namespace";
// $NON-NLS-1$
namespaceTable.addNamespaceInfo(prefix, uri, "");
}
// here's where we update the inferred grammar if required
//
boolean createCMElementDeclaration = true;
boolean isLocal = (uri == null && prefix == null);
if (isLocal) {
if (parentInferredCMDocument == null) {
// this is a local element... and the parent is not inferred (e.g) it has a known grammar
// so we don't need to create an element declaration for this element
createCMElementDeclaration = false;
} else {
if (uri == null) {
// $NON-NLS-1$
uri = "ommitted-namespace";
}
}
}
if (createCMElementDeclaration) {
if (isLocal) {
inferredCMDocument = parentInferredCMDocument;
inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, true);
} else {
boolean createCMDocument = false;
// $NON-NLS-1$
String cacheKey = "inferred-document" + uri;
inferredCMDocument = (CMDocument) createdCMDocumentTable.get(cacheKey);
if (inferredCMDocument == null) {
// we don't have an inferred document for this uri yet... let's see of we need one
int status = cmDocumentManager.getCMDocumentStatus(uri);
if (status == CMDocumentCache.STATUS_NOT_LOADED || status == CMDocumentCache.STATUS_ERROR) {
// the cache does not contain a 'proper' CMDocument for this uri
// so we need to create an inferred one
createCMDocument = true;
}
}
if (createCMDocument) {
// System.out.println("encountered element {" + element.getNodeName() + "} ... creating inferred CMDocument for " + uri);
inferredCMDocument = inferredGrammarFactory.createCMDocument(uri);
// $NON-NLS-1$ //$NON-NLS-2$
cmDocumentManager.addCMDocument(uri, "", cacheKey, "XSD", inferredCMDocument);
createdCMDocumentTable.put(cacheKey, inferredCMDocument);
}
if (inferredCMDocument != null) {
inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, false);
}
}
if (parentInferredCMElementDeclaration != null) {
inferredGrammarFactory.createCMContent(parentInferredCMDocument, parentInferredCMElementDeclaration, inferredCMDocument, inferredCMElementDeclaration, isLocal, uri);
}
}
visitChildNodes(element);
// reset the 'current' state to inital values
inferredCMElementDeclaration = parentInferredCMElementDeclaration;
inferredCMDocument = parentInferredCMDocument;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class ModelQueryImpl method canInsert.
public boolean canInsert(Element parent, CMNode cmNode, int index, int validityChecking) {
boolean result = true;
CMElementDeclaration ed = getCMElementDeclaration(parent);
if (ed != null) {
result = canInsert(parent, ed, cmNode, index, validityChecking);
}
return result;
}
Aggregations