use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel 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.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class StructureSelectAction method getIndexedRegion.
protected IndexedRegion getIndexedRegion(int offset) {
IndexedRegion indexedRegion = null;
int lastOffset = offset;
IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null) {
try {
indexedRegion = model.getIndexedRegion(lastOffset);
while (indexedRegion == null && lastOffset >= 0) {
lastOffset--;
indexedRegion = model.getIndexedRegion(lastOffset);
}
} finally {
model.releaseFromRead();
}
}
return indexedRegion;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class StructuredSelectActionDelegate method getIndexedRegion.
/**
* This method will probably be removed and replaced by using new selection provider
* @param document
* @param offset
* @return
*/
protected IndexedRegion getIndexedRegion(IDocument document, int offset) {
IndexedRegion indexedRegion = null;
int lastOffset = offset;
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null) {
try {
indexedRegion = model.getIndexedRegion(lastOffset);
while (indexedRegion == null && lastOffset >= 0) {
lastOffset--;
indexedRegion = model.getIndexedRegion(lastOffset);
}
} finally {
model.releaseFromRead();
}
}
return indexedRegion;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel 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.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class URLModelProvider method getCommonModelFor.
/**
* <code>baseModel</code>: the model containing the link
* <code>ref</code>: the link URL string
*/
private IStructuredModel getCommonModelFor(final IStructuredModel baseModel, final String ref, final int which) throws IOException {
// first, create absolute url
String absURL = resolveURI(baseModel, ref, true);
if ((absURL == null) || (absURL.length() == 0)) {
return null;
}
// need to remove file:// scheme if necessary
try {
final java.net.URL aURL = new java.net.URL(absURL);
// resolve it by finding the file it points to
if (!aURL.getProtocol().equals("platform")) {
// $NON-NLS-1$
if (aURL.getProtocol().equals("file") && (aURL.getHost().equals("localhost") || aURL.getHost().length() == 0)) {
// $NON-NLS-2$//$NON-NLS-1$
absURL = aURL.getFile();
final IPath ipath = new Path(absURL);
// if path has a device, and if it begins with
// IPath.SEPARATOR, remove it
final String device = ipath.getDevice();
if ((device != null) && (device.length() > 0)) {
if (device.charAt(0) == IPath.SEPARATOR) {
final String newDevice = device.substring(1);
absURL = ipath.setDevice(newDevice).toString();
}
}
}
}
} catch (java.net.MalformedURLException mfuExc) {
}
// next, decide project
IProject project = null;
final IPath fullIPath = new Path(absURL);
IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
IContainer container = workspace.getContainerForLocation(fullIPath);
if (container != null) {
// fullIPath doesn't exist in workspace
project = container.getProject();
}
// now, get absURL's IFile
if ((project != null) && (project.getLocation().isPrefixOf(fullIPath) == false)) {
// it's at outside of Project
return null;
}
IStructuredModel model = null;
if (project != null) {
IPath filePath = fullIPath.removeFirstSegments(project.getLocation().segmentCount());
IFile file = (filePath != null && !filePath.isEmpty()) ? project.getFile(filePath) : null;
if (file == null) {
return null;
}
// obtain model
if (which == GET_MODEL_FOR_EDIT) {
model = getModelForEdit(file);
} else if (which == GET_MODEL_FOR_READ) {
model = getModelForRead(file);
}
// responsibility
if (model != null && model.getSynchronizationStamp() == IResource.NULL_STAMP)
model.resetSynchronizationStamp(file);
} else {
String id = null;
InputStream inStream = null;
// obtain resolver
URIResolver resolver = (project != null) ? (URIResolver) project.getAdapter(URIResolver.class) : null;
if (resolver == null) {
// ProjectResolver can take care of the case if project is
// null.
resolver = new ProjectResolver(project);
}
if (resolver == null) {
return null;
}
// there is no project. we can't expect IProject help to create
// id/inputStream
java.io.File file = fullIPath.toFile();
// obatin id
id = calculateId(fullIPath);
// obtain InputStream
try {
inStream = new FileInputStream(file);
} catch (FileNotFoundException fnfe) {
// the file does not exist, or we don't have read permission
return null;
}
// obtain model
try {
if (which == GET_MODEL_FOR_EDIT) {
model = getModelManager().getModelForEdit(id, inStream, resolver);
} else if (which == GET_MODEL_FOR_READ) {
model = getModelManager().getModelForRead(id, inStream, resolver);
}
} catch (UnsupportedEncodingException ue) {
} catch (IOException ioe) {
} finally {
// close now !
if (inStream != null) {
inStream.close();
}
}
}
// set locationid
if (model != null && model.getBaseLocation() == null) {
model.setBaseLocation(fullIPath.toString());
}
return model;
}
Aggregations