use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class HTMLValidator method validate.
private HTMLValidationResult validate(IReporter reporter, IFile file, IDOMModel model) {
if (file == null || model == null)
// error
return null;
IDOMDocument document = model.getDocument();
if (document == null)
// error
return null;
if (!hasHTMLFeature(document))
// ignore
return null;
INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document);
if (adapter == null)
// error
return null;
HTMLValidationReporter rep = getReporter(reporter, file, model);
rep.clear();
adapter.setReporter(rep);
adapter.validate(document);
return rep.getResult();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class URLModelProvider method resolveURI.
/**
* <code>baseModel</code>: the model containing the link
* <code>ref</code>: the link URL string
* <code>resolveCrossProjectLinks</code>: If resolveCrossProjectLinks
* is set to true, then this method will properly resolve the URI if it is
* a valid URI pointing to another (appropriate) project.
*/
public static String resolveURI(IStructuredModel baseModel, String ref, boolean resolveCrossProjectLinks) {
if (baseModel == null)
return null;
// for HTML, 'href' attribute value of BASE element
// should be used, if exists any
String baseHref = null;
// of HTML or XHTML
if (isHTMLFamily(baseModel)) {
final IDOMModel xmlmodel = (IDOMModel) baseModel;
final IDOMDocument doc = xmlmodel.getDocument();
// look for <BASE> w/ href
// $NON-NLS-1$
final NodeList nl = doc.getElementsByTagName("BASE");
if ((nl != null) && (nl.getLength() > 0)) {
// per each <BASE>
for (int i = 0; i < nl.getLength(); i++) {
final Node baseNode = nl.item(i);
if (baseNode != null) {
// get all attrs
final NamedNodeMap attrNodes = baseNode.getAttributes();
if (attrNodes != null) {
// $NON-NLS-1$
final Node attrNode = attrNodes.getNamedItem("HREF");
if (attrNode != null) {
// found href=""
final String attrValue = attrNode.getNodeValue();
if (attrValue != null) {
baseHref = attrValue.trim();
}
}
}
}
// what if there are multiple <BASE> tags ??
if (baseHref != null) {
break;
}
}
}
}
// get resolver in Model
final URIResolver resolver = baseModel.getResolver();
// resolve to absolute url
final String absurl = (resolver != null) ? ((baseHref != null) ? resolver.getLocationByURI(ref, baseHref, resolveCrossProjectLinks) : resolver.getLocationByURI(ref, resolveCrossProjectLinks)) : null;
if ((resolver != null) && (absurl == null) && (ref != null) && (ref.trim().length() > 0) && (ref.trim().charAt(0) == '/')) {
// so that href is a broken and should not create model
return null;
}
if ((absurl != null) && (absurl.length() > 0)) {
return absurl;
}
// maybe ref is at outside of the Project
// obtain docroot;
final IContainer container = (resolver != null) ? resolver.getRootLocation() : null;
String docroot = null;
if (container != null) {
IPath containerLocation = container.getLocation();
if (containerLocation != null) {
docroot = containerLocation.toString();
} else if (container.getLocationURI() != null) {
docroot = container.getLocationURI().toString();
}
}
if (docroot == null) {
docroot = baseModel.getBaseLocation();
}
if (docroot == null) {
// should not be
return null;
}
// obtain document url
String modelBaseLocation = baseModel.getBaseLocation();
if ((modelBaseLocation == null) || (modelBaseLocation.length() == 0)) {
// fallback...
modelBaseLocation = baseModel.getId();
}
if ((modelBaseLocation == null) || (modelBaseLocation.length() == 0)) {
// i can't resolve uri !
return null;
}
// resolve url
URLHelper helper = new URLHelper(PathHelper.getContainingFolderPath(modelBaseLocation), PathHelper.getContainingFolderPath(PathHelper.appendTrailingURLSlash(docroot)));
return helper.toAbsolute(ref);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyHTML method isXHTML.
/**
* Is the node part of an XHTML document
* @param node
* @return
*/
private boolean isXHTML(Node node) {
Document doc = node.getOwnerDocument();
if (!(doc instanceof IDOMDocument))
return false;
String typeid = ((IDOMDocument) doc).getDocumentTypeId();
if (typeid != null) {
HTMLDocumentTypeEntry entry = HTMLDocumentTypeRegistry.getInstance().getEntry(typeid);
return (entry != null && entry.isXMLType());
}
return false;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class HTMLModelQueryCMProvider method getCorrespondingCMDocument.
/**
* Returns the CMDocument that corresponds to the DOM Node. or null if no
* CMDocument is appropriate for the DOM Node.
*/
public CMDocument getCorrespondingCMDocument(Node node) {
IDOMDocument owner = getOwnerXMLDocument(node);
if (owner == null)
return null;
String pid = getPublicId(owner);
// no PID, always return the currently-supported HTML version
if (pid == null || "".equals(pid)) {
return staticHTML5;
}
HTMLDocumentTypeEntry entry = doctypeRegistry.getEntry(pid);
if (entry == null)
return staticHTML;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=151000 - use internal content model
if (entry.useInternalModel()) {
if (pid != null && pid.equals(HTMLDocumentTypeRegistry.CHTML_PUBLIC_ID)) {
return staticCHTML;
}
return staticHTML;
}
pid = entry.getPublicId();
String sid = entry.getSystemId();
CMDocument dtdcm = xhtmlassoc.getXHTMLCMDocument(pid, sid);
if (dtdcm == null) {
if (pid != null && pid.equals(HTMLDocumentTypeRegistry.CHTML_PUBLIC_ID)) {
return staticCHTML;
}
return staticHTML;
}
String grammarURI = xhtmlassoc.getCachedGrammerURI();
CMDocument buddycm = (CMDocument) buddyCache.get(grammarURI);
if (buddycm != null)
return buddycm;
buddycm = new CMDocumentForBuddySystem(dtdcm, entry.isXMLType());
buddyCache.put(grammarURI, buddycm);
return buddycm;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class SyntaxValidator method getInfo.
private void getInfo(ElementInfo info) {
info.decl = CMUtil.getDeclaration(info.target);
info.startTag = info.target.getStartStructuredDocumentRegion();
info.endTag = info.target.getEndStructuredDocumentRegion();
Document doc = info.target.getOwnerDocument();
if (!(doc instanceof IDOMDocument))
return;
String typeid = ((IDOMDocument) doc).getDocumentTypeId();
if (typeid != null) {
if (typeid.trim().length() != 0) {
HTMLDocumentTypeEntry entry = HTMLDocumentTypeRegistry.getInstance().getEntry(typeid);
info.isXHTML = (entry != null && entry.isXMLType());
} else {
info.isXHTML = getXMLTarget(doc);
info.isXHTML5 = info.isXHTML;
}
}
}
Aggregations