use of org.eclipse.wst.dtd.core.internal.emf.DTDFile in project webtools.sourceediting by eclipse.
the class DTDUtil method loadIncludedDTD.
// load xmiModels for included DTDs
private void loadIncludedDTD(ResourceSet resources, DTD dtd) {
ExternalDTDModel extModel = getExternalDTDModel(resources, dtd.getName());
if (extModel != null) {
// now fill our hash tables for elements and parameter entities
// so that we know what can be referenced by our main dtd
DTDFile file = extModel.getExternalDTDFile();
Collection elementList = file.listDTDElement();
Collection entityList = file.listDTDEntity();
Iterator i = elementList.iterator();
while (i.hasNext()) {
DTDObject object = (DTDObject) i.next();
elementPool.put(getBaseName(object), object);
}
i = entityList.iterator();
while (i.hasNext()) {
DTDEntity entity = (DTDEntity) i.next();
if (entity.isParameterEntity()) {
pePool.put(getBaseName(entity), entity);
}
}
}
}
use of org.eclipse.wst.dtd.core.internal.emf.DTDFile in project webtools.sourceediting by eclipse.
the class ExternalDTDModel method loadModel.
/**
* Load the DTD model specified by the uri e.g.
* file:C:/eclipse/examples/purchaseorder.dtd
*/
public boolean loadModel(ResourceSet resources, String uri) {
boolean rc = true;
if (uri == null || uri.equals("")) {
// $NON-NLS-1$
return false;
}
try {
// todo... Investigate why we can not create a new DTDUtil to load
// the external
// without breaking the bvt test bucket on the oagis cases.
// Are depending on mof's built in caching via
// resources.load(uri)?
//
URI uriObj = URI.createURI(uri);
Resource r = resources.createResource(uriObj);
Map options = new HashMap();
r.load(options);
for (Iterator i = resources.getResources().iterator(); i.hasNext(); ) {
DTDFile currentFile = (DTDFile) ((Resource) i.next()).getContents().get(0);
String currentURI = currentFile.eResource().getURI().toString();
// compare.
if (uri.endsWith(currentURI)) {
dtdFile = currentFile;
break;
}
}
if (dtdFile == null) {
rc = false;
}
} catch (Exception ex) {
rc = false;
}
return rc;
}
use of org.eclipse.wst.dtd.core.internal.emf.DTDFile in project webtools.sourceediting by eclipse.
the class DTDResourceImpl method getEObject.
/**
* Returns the resolved object for the given URI
* {@link URI#fragment fragment}.
* <p>
* The fragment encoding will typically be that produced by
* {@link #getURIFragment getURIFragment}.
* </p>
*
* @param uriFragment
* the fragment to resolve.
* @return the resolved object for the given fragment.
* @see #getURIFragment(EObject)
* @see org.eclipse.emf.ecore.resource.ResourceSet#getEObject(URI, boolean)
* @see org.eclipse.emf.ecore.util.EcoreUtil#resolve(EObject, org.eclipse.emf.ecore.resource.ResourceSet)
* @see org.eclipse.emf.ecore.InternalEObject#eObjectForURIFragmentSegment(String)
* @throws org.eclipse.emf.common.util.WrappedException
* if a problem occurs navigating the fragment.
*/
public EObject getEObject(java.lang.String uriFragment) {
EList contents = getContents();
if (contents != null) {
Iterator i = contents.iterator();
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof DTDFile) {
// there should only be one DTDFile in a DTD extent
EObject result = ((DTDFile) obj).findObject(uriFragment);
return result;
}
}
}
// $NON-NLS-1$
System.out.println(">>> DTDKey Error: cannot find object " + uriFragment);
return super.getEObject(uriFragment);
}
use of org.eclipse.wst.dtd.core.internal.emf.DTDFile in project webtools.sourceediting by eclipse.
the class DTDParserTest method testMultipleCommentParsing.
public void testMultipleCommentParsing() throws IOException {
DTDUtil util = new DTDUtil();
String sampleDTDpath = "/resources/dtdParserTest/sample.dtd";
URL bundleURL = DTDCoreTestsPlugin.getDefault().getBundle().getEntry(sampleDTDpath);
assertNotNull(sampleDTDpath + " not found in bundle", bundleURL);
// Do not rely on Common URI Resolver to find the contents
URL fileURL = FileLocator.toFileURL(bundleURL);
util.parse(fileURL.toExternalForm());
DTDFile dtdFile = util.getDTDFile();
assertEquals(UNEXPECTED_FILE_CONTENTS, 1, dtdFile.getDTDContent().size());
Object object = dtdFile.getDTDContent().get(0);
assertTrue(UNEXPECTED_FILE_CONTENTS, object instanceof DTDElement);
DTDElement dtdElement = (DTDElement) object;
String comment = dtdElement.getComment();
assertEquals("Comment value was not as expected", " line one \n line two ", comment);
}
Aggregations