use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.
the class XMLPropertySource method getDocTypeFromDOMNode.
/**
* by "internal spec" the DOCTYPE adapter is only available from Document
* Node
*
* @return {@link DocumentTypeAdapter}
*/
private DocumentTypeAdapter getDocTypeFromDOMNode(Node node) {
DocumentTypeAdapter adapter = null;
Document ownerDocument = node.getOwnerDocument();
if (ownerDocument == null) {
// ... but, maybe a separate issue).
if (node instanceof Document) {
ownerDocument = (Document) node;
}
}
if (ownerDocument != null) {
adapter = (DocumentTypeAdapter) ((INodeNotifier) ownerDocument).getAdapterFor(DocumentTypeAdapter.class);
}
return adapter;
}
use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForHTMLTag method getCandidates.
/**
* getCandidates method comment.
*/
protected Iterator getCandidates() {
List candidates = new ArrayList();
if (checkLeadingColon()) {
return candidates.iterator();
}
boolean bLowerCase = CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_SELECTOR) == CSSCorePreferenceNames.LOWER;
// XHTML requires lower case
if (fContext.getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
Node domNode = fContext.getModel().getOwnerDOMNode();
if (domNode != null && !(domNode instanceof Document)) {
domNode = domNode.getOwnerDocument();
if (domNode instanceof IDOMDocument) {
DocumentTypeAdapter adapter = (DocumentTypeAdapter) ((IDOMDocument) domNode).getAdapterFor(DocumentTypeAdapter.class);
if (adapter != null)
bLowerCase = (adapter.getTagNameCase() == DocumentTypeAdapter.LOWER_CASE);
}
}
}
int length = fHTMLTags.length;
for (int i = 0; i < length; i++) {
String tagText = fHTMLTags[i];
if (bLowerCase) {
tagText = tagText.toLowerCase();
}
if (!isMatch(tagText)) {
continue;
}
int cursorPos = 0;
StringBuffer buf = new StringBuffer();
buf.append(tagText);
cursorPos += tagText.length();
boolean inRule = (fContext.getTargetNode() instanceof ICSSStyleRule);
if (!inRule || fContext.getTextToReplace().length() == 0) {
// $NON-NLS-1$
buf.append(" ");
cursorPos += 1;
}
if (!inRule) {
StringAndOffset sao = generateBraces();
buf.append(sao.fString);
cursorPos += sao.fOffset;
}
CSSCACandidate item = new CSSCACandidate();
item.setReplacementString(buf.toString());
item.setCursorPosition(cursorPos);
item.setDisplayString(tagText);
item.setImageType(CSSImageType.SELECTOR_TAG);
candidates.add(item);
}
return candidates.iterator();
}
use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.
the class HTMLDocumentTypeAdapterFactory method adapt.
/**
* Method that returns the adapter associated with the given object. It
* may be a singleton or not ... depending on the needs of the
* INodeAdapter ... but in general it is recommended for an adapter to be
* stateless, so the efficiencies of a singleton can be gained.
*
* The implementation of this method should call addAdapter on the adapted
* object with the correct instance of the adapter.
*/
public INodeAdapter adapt(INodeNotifier notifier) {
INodeAdapter result = null;
// only adapt IDOMDocument
if (notifier instanceof IDOMDocument) {
// if already has an adapter, no need to recreate/initialize.
// Note: this means if "doctype" for DOM changes,
// theDocumentTypeAdatper for that DOM
// should be removed (and released) and it will be re-created next
// time required.
DocumentTypeAdapter oldAdapter = (DocumentTypeAdapter) notifier.getExistingAdapter(DocumentTypeAdapter.class);
if (oldAdapter != null) {
result = oldAdapter;
} else {
// if there already was an adapter
// if(fAdapter != null)
// fAdapter.release();
// note, the factory is included in this case to have a central place
// to come back to for case preferences.
result = new HTMLDocumentTypeAdapter((IDOMDocument) notifier, this);
notifier.addAdapter(result);
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.
the class URLModelProvider method isHTMLFamily.
/**
* Utility to check the model is HTML family or not
*/
private static boolean isHTMLFamily(IStructuredModel model) {
if (model instanceof IDOMModel) {
IDOMDocument document = ((IDOMModel) model).getDocument();
DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class);
if (adapter != null)
return adapter.hasFeature(HTMLDocumentTypeConstants.HTML);
}
return false;
}
Aggregations