use of org.eclipse.wst.common.internal.emf.resource.TranslatorResource in project webtools.sourceediting by eclipse.
the class EMF2DOMSSERenderer method createDocument.
/**
* Create a new Document given
*
* @aResource.
*/
protected void createDocument() {
TranslatorResource res = getResource();
res.setDefaults();
IFile file = WorkbenchResourceHelper.getFile(resource);
InputStream is = DOMUtilities.createHeaderInputStream(res.getDoctype(), res.getPublicId(), res.getSystemId());
if (is == null)
return;
try {
try {
List folders = new ArrayList();
IContainer container = file.getParent();
while (null != container && !container.exists() && container instanceof IFolder) {
folders.add(container);
container = container.getParent();
}
IFolder folder = null;
for (int i = 0; i < folders.size(); i++) {
folder = (IFolder) folders.get(i);
folder.create(true, true, null);
}
file.create(is, true, null);
file.setLocal(true, 1, null);
} catch (CoreException e1) {
Logger.logException(e1);
} finally {
if (null != is) {
is.close();
}
}
initializeXMLModel(file, resource.getWriteCount() != 0);
} catch (IOException ex) {
// $NON-NLS-1$
Logger.log(Logger.ERROR, "IWAE0017E Unexpected IO exception occurred creating xml document");
}
}
use of org.eclipse.wst.common.internal.emf.resource.TranslatorResource in project webtools.sourceediting by eclipse.
the class EMF2DOMSSERenderer method getExistingDOMAdapter.
public EMF2DOMAdapter getExistingDOMAdapter(Node node) {
// IDOMNode xNode = (IDOMNode) node;
// return (EMF2DOMSSEAdapter) xNode.getAdapterFor(EMF2DOMAdapter.ADAPTER_CLASS);
INodeNotifier sseNode = (INodeNotifier) node;
Collection adapters = sseNode.getAdapters();
for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
INodeAdapter adapter = (INodeAdapter) iterator.next();
// First Check if it's an EMF2DOMAdapter
if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
// Cast to EMF2DOMSSEAdapter
EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
// Use the resourceClass to make sure the resource type is identical
if (getResource() == null || e2DAdapter.getTarget() == null)
if (resourceClass.equals(e2DAdapter.getResourceClass()))
return e2DAdapter;
else
continue;
// First check if targets are resources
if (e2DAdapter.getTarget() instanceof Resource) {
/*
* Now check if it's the right one (Multiple resources
* could be attached)
*/
if (e2DAdapter.getTarget() == getResource()) {
return e2DAdapter;
}
} else {
// Check if targets are EObjects with the same resources
TranslatorResource myTarget = getResource();
EObject adapterTarget = (EObject) e2DAdapter.getTarget();
/*
* Now check if it's the right one (Multiple resources could
* be attached)
*/
if (adapterTarget.eResource() == myTarget || adapterTarget.eResource() == null) {
return e2DAdapter;
}
}
}
}
return null;
}
Aggregations