use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class JSPContentAssistProcessor method getDefaultJSPCMDocument.
/**
* For JSP files and segments, this is just the JSP
* document, but when editing tag files and their fragments, it
* should be the tag document.
*
* It may also vary based on the model being edited in the future.
*
* @return the default non-embedded CMDocument for the document being
* edited.
*/
CMDocument getDefaultJSPCMDocument(IDOMNode node) {
// handle tag files here
String contentType = node.getModel().getContentTypeIdentifier();
if (ContentTypeIdForJSP.ContentTypeID_JSPTAG.equals(contentType))
return JSPCMDocumentFactory.getCMDocument(CMDocType.TAG20_DOC_TYPE);
CMDocument jcmdoc = null;
String modelPath = node.getModel().getBaseLocation();
if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
jcmdoc = JSPCMDocumentFactory.getCMDocument(version);
}
if (jcmdoc == null) {
jcmdoc = JSPCMDocumentFactory.getCMDocument();
}
return jcmdoc;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class LibraryTagsCompletionProposalComputer method getDefaultJSPCMDocument.
/**
* <p><b>NOTE: </b>This should be removed as soon as Bug 311961 is fixed</p>
*
* For JSP files and segments, this is just the JSP document, but when
* editing tag files and their fragments, it should be the tag document.
*
* It may also vary based on the model being edited in the future.
*
* @return the default non-embedded CMDocument for the document being
* edited.
*/
private CMDocument getDefaultJSPCMDocument(IDOMNode node) {
// handle tag files here
String contentType = node.getModel().getContentTypeIdentifier();
if (ContentTypeIdForJSP.ContentTypeID_JSPTAG.equals(contentType))
return JSPCMDocumentFactory.getCMDocument(CMDocType.TAG20_DOC_TYPE);
CMDocument jcmdoc = null;
String modelPath = node.getModel().getBaseLocation();
if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
jcmdoc = JSPCMDocumentFactory.getCMDocument(version);
}
if (jcmdoc == null) {
jcmdoc = JSPCMDocumentFactory.getCMDocument();
}
return jcmdoc;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class TestCatalogContentModels method assertIsNotXHTMLContentModel.
private void assertIsNotXHTMLContentModel(IDOMModel htmlModel) {
Element html = htmlModel.getDocument().getDocumentElement();
CMDocument correspondingCMDocument = ModelQueryUtil.getModelQuery(htmlModel).getCorrespondingCMDocument(html);
assertNotNull("content model document not found", correspondingCMDocument);
assertTrue("document is unexpectedly XHTML", correspondingCMDocument.supports(HTMLCMProperties.IS_XHTML));
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class DocumentImpl method getCharValue.
/**
* getCharValue method
*
* @return java.lang.String
* @param name
* java.lang.String
*/
protected String getCharValue(String name) {
if (name == null)
return null;
int length = name.length();
if (length == 0)
return null;
if (name.charAt(0) == '#') {
// character reference
if (length == 1)
return null;
int radix = 10;
String s = null;
// now allow hexadecimal also for non XML document
if (name.charAt(1) == 'x') {
// hexadecimal
radix = 16;
s = name.substring(2);
} else {
// decimal
s = name.substring(1);
}
if (s == null || s.length() == 0)
return null;
if (s.charAt(0) == '-')
// no minus accepted
return null;
char c = 0;
try {
c = (char) Integer.parseInt(s, radix);
} catch (NumberFormatException ex) {
}
if (c == 0)
return null;
return String.valueOf(c);
}
// implicit character entities for XML
if (name.equals(IXMLCharEntity.LT_NAME))
return IXMLCharEntity.LT_VALUE;
if (name.equals(IXMLCharEntity.GT_NAME))
return IXMLCharEntity.GT_VALUE;
if (name.equals(IXMLCharEntity.AMP_NAME))
return IXMLCharEntity.AMP_VALUE;
if (name.equals(IXMLCharEntity.QUOT_NAME))
return IXMLCharEntity.QUOT_VALUE;
if (isXMLType()) {
if (name.equals(IXMLCharEntity.APOS_NAME))
return IXMLCharEntity.APOS_VALUE;
}
CMDocument cm = getCMDocument();
if (cm != null) {
CMNamedNodeMap map = cm.getEntities();
if (map != null) {
CMEntityDeclaration decl = (CMEntityDeclaration) map.getNamedItem(name);
if (decl != null) {
String value = decl.getValue();
if (value == null)
return null;
int valueLength = value.length();
if (valueLength > 1 && value.charAt(0) == '&' && value.charAt(1) == '#' && value.charAt(valueLength - 1) == ';') {
// character reference
return getCharValue(value.substring(1, valueLength - 1));
}
return value;
}
}
}
return null;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method visitCMAnyElement.
public void visitCMAnyElement(CMAnyElement anyElement) {
// ingnore buildPolicy for ANY elements... only create elements if
// absolutely needed
//
int forcedMin = alwaysVisit ? 1 : 0;
int min = Math.max(anyElement.getMinOccur(), forcedMin);
alwaysVisit = false;
String uri = anyElement.getNamespaceURI();
// $NON-NLS-1$
String targetNSProperty = "http://org.eclipse.wst/cm/properties/targetNamespaceURI";
// $NON-NLS-1$
CMDocument parentCMDocument = (CMDocument) anyElement.getProperty("CMDocument");
CMElementDeclaration ed = null;
// //$NON-NLS-1$
if (parentCMDocument != null) {
if (// $NON-NLS-1$
uri == null || uri.startsWith("##") || uri.equals(parentCMDocument.getProperty(targetNSProperty))) {
ed = getSuitableElement(getParentCMElementDeclaration(), parentCMDocument);
}
}
if (// $NON-NLS-1$
ed == null && externalCMDocumentSupport != null && uri != null && !uri.startsWith("##") && currentParent instanceof Element) {
CMDocument externalCMDocument = externalCMDocumentSupport.getCMDocument((Element) currentParent, uri);
if (externalCMDocument != null) {
ed = getSuitableElement(null, externalCMDocument);
}
}
for (int i = 1; i <= min; i++) {
if (ed != null) {
visitCMElementDeclaration(ed);
} else {
// $NON-NLS-1$
Element element = document.createElement("ANY-ELEMENT");
linkNode(element);
}
}
}
Aggregations