use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class URLModelProvider method getModelForEdit.
/**
*/
private IStructuredModel getModelForEdit(IFile file) throws IOException {
if (file == null)
return null;
IModelManager manager = getModelManager();
// create a fake InputStream
IStructuredModel model = null;
try {
model = manager.getModelForEdit(file);
} catch (UnsupportedCharsetException ex) {
try {
model = manager.getModelForEdit(file, EncodingRule.FORCE_DEFAULT);
} catch (IOException ioe) {
} catch (CoreException ce) {
}
} catch (CoreException ce) {
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class URLModelProvider method getModelForRead.
/**
*/
private IStructuredModel getModelForRead(IFile file) throws IOException {
if (file == null)
return null;
IModelManager manager = getModelManager();
// create a fake InputStream
IStructuredModel model = null;
try {
model = manager.getModelForRead(file);
} catch (UnsupportedCharsetException ex) {
try {
model = manager.getModelForRead(file, EncodingRule.FORCE_DEFAULT);
} catch (IOException ioe) {
} catch (CoreException ce) {
}
} catch (CoreException ce) {
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AnchorHyperlinkDetector method getCurrentNode.
/**
* Returns the node the cursor is currently on in the document. null if no
* node is selected
*
* @param offset
* @return Node either element, doctype, text, or null
*/
private Node getCurrentNode(IDocument document, int offset) {
// get the current node at the offset (returns either: element,
// doctype, text)
IndexedRegion inode = null;
IStructuredModel sModel = null;
try {
sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (sModel != null) {
inode = sModel.getIndexedRegion(offset);
if (inode == null) {
inode = sModel.getIndexedRegion(offset - 1);
}
}
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
if (inode instanceof Node) {
return (Node) inode;
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class LinkElementAdapter method retrieveModel.
/**
*/
private ICSSModel retrieveModel() {
if (!isValidAttribute()) {
return null;
}
// null,attr check is done in isValidAttribute()
Element element = getElement();
// $NON-NLS-1$
String href = element.getAttribute("href");
IDOMModel baseModel = ((IDOMNode) element).getModel();
if (baseModel == null)
return null;
Object id = baseModel.getId();
if (!(id instanceof String))
return null;
// String base = (String)id;
// get ModelProvideAdapter
IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(ModelProvideAdapterClass);
URLModelProvider provider = new URLModelProvider();
try {
IStructuredModel newModel = provider.getModelForRead(baseModel, href);
if (newModel == null)
return null;
if (!(newModel instanceof ICSSModel)) {
newModel.releaseFromRead();
return null;
}
// notify adapter
if (adapter != null)
adapter.modelProvided(newModel);
return (ICSSModel) newModel;
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class LinkElementAdapter method createModel.
protected ICSSModel createModel() {
// create phantom(broken link) external CSS model
if (getElement() == null)
return null;
IStructuredModel baseModel = ((IDOMNode) getElement()).getModel();
ICSSModel newModel = (ICSSModel) baseModel.getModelManager().createUnManagedStructuredModelFor(CSS_ID);
// calculate base location and set
// get resolver in Model
URIResolver resolver = baseModel.getResolver();
// resolve to absolute url : this need not exact location of css file. It is important that absurl is not null.
String ref = getElement().getAttribute(HTML40Namespace.ATTR_NAME_HREF);
String absurl = (resolver != null && ref != null && ref.length() > 0) ? resolver.getLocationByURI(ref, true) : null;
if ((absurl == null) || (absurl.length() == 0)) {
IPath basePath = new Path(baseModel.getBaseLocation());
URLHelper helper = new URLHelper(basePath.removeLastSegments(1).toString());
// $NON-NLS-1$
absurl = helper.toAbsolute(ref == null ? "" : ref);
}
if ((absurl == null) || (absurl.length() == 0)) {
absurl = ref;
}
if (absurl == null) {
// $NON-NLS-1$
absurl = "";
}
newModel.setBaseLocation(absurl);
// set style listener
newModel.addStyleListener(this);
return newModel;
}
Aggregations