use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project jbosstools-hibernate by jbosstools.
the class SQLTypeContentProvider method getElements.
public Object[] getElements(Object inputElement) {
IStructuredModel im = (IStructuredModel) inputElement;
if (im instanceof IDOMModel) {
IDOMModel model = (IDOMModel) im;
// $NON-NLS-1$
List childNodes = DOMModelUtil.getChildrenByTagName(model.getDocument(), "hibernate-reverse-engineering");
if (childNodes.size() >= 1) {
Element l = (Element) childNodes.get(0);
// $NON-NLS-1$
childNodes = DOMModelUtil.getChildrenByTagName(l, "type-mapping");
if (childNodes.size() >= 1) {
// $NON-NLS-1$
childNodes = DOMModelUtil.getChildrenByTagName(l, "sql-type");
Object[] o = new Object[childNodes.size()];
for (int i = 0; i < childNodes.size(); i++) {
o[i] = childNodes.get(i);
}
return o;
}
}
}
return new Object[0];
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class CSSFormatUtil method collectCSSNodes.
public List collectCSSNodes(IStructuredModel model, int start, int length) {
List nodes = new ArrayList();
IndexedRegion startNode = model.getIndexedRegion(start);
IndexedRegion endNode = model.getIndexedRegion(start + length - 1);
if (startNode == null || endNode == null) {
return nodes;
}
if (model instanceof ICSSModel && startNode instanceof ICSSNode && endNode instanceof ICSSNode) {
// CSS model
ICSSNode ca = getCommonAncestor((ICSSNode) startNode, (ICSSNode) endNode);
if (ca != null) {
for (ICSSNode node = ca.getFirstChild(); node != null && start + length < ((IndexedRegion) node).getStartOffset(); node = node.getNextSibling()) {
if (start < ((IndexedRegion) node).getEndOffset()) {
nodes.add(node);
}
}
}
} else if (model instanceof IDOMModel && startNode instanceof IDOMNode && endNode instanceof IDOMNode) {
if (startNode instanceof Text) {
startNode = (IndexedRegion) ((Text) startNode).getParentNode();
}
if (endNode instanceof Text) {
endNode = (IndexedRegion) ((Text) endNode).getParentNode();
}
// HTML model, maybe
IDOMNode ca = (IDOMNode) getCommonAncestor((Node) startNode, (Node) endNode);
findCSS(nodes, ca);
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class HTMLValidator method getModel.
/**
*/
protected IDOMModel getModel(IProject project, IFile file) {
if (project == null || file == null)
return null;
if (!file.exists())
return null;
if (!canHandle(file))
return null;
IModelManager manager = StructuredModelManager.getModelManager();
if (manager == null)
return null;
IStructuredModel model = null;
try {
file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
} catch (CoreException e) {
Logger.logException(e);
}
try {
try {
model = manager.getModelForRead(file);
} catch (UnsupportedEncodingException ex) {
// retry ignoring META charset for invalid META charset
// specification
// recreate input stream, because it is already partially read
model = manager.getModelForRead(file, new String(), null);
}
} catch (UnsupportedEncodingException ex) {
} catch (IOException ex) {
} catch (CoreException e) {
Logger.logException(e);
}
if (model == null)
return null;
if (!(model instanceof IDOMModel)) {
releaseModel(model);
return null;
}
return (IDOMModel) model;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class HTMLValidator method validateFile.
/**
* @param result
*/
private void validateFile(IValidationContext helper, IReporter reporter, IFile file, ValidationResult result) {
if ((reporter != null) && (reporter.isCancelled() == true)) {
throw new OperationCanceledException();
}
if (!shouldValidate(file)) {
return;
}
IDOMModel model = getModel(file.getProject(), file);
if (model == null)
return;
try {
Collection dependencies = null;
NodeImpl document = null;
if (model.getDocument() instanceof NodeImpl) {
document = (NodeImpl) model.getDocument();
}
if (result != null && document != null) {
dependencies = new HashSet();
document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, dependencies, null);
}
validate(reporter, file, model);
if (result != null && document != null) {
document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, null, null);
result.setDependsOn((IResource[]) dependencies.toArray(new IResource[dependencies.size()]));
}
} finally {
releaseModel(model);
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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);
}
Aggregations