Search in sources :

Example 6 with DTDFile

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);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) DTDEntity(org.eclipse.wst.dtd.core.internal.emf.DTDEntity) DTDFile(org.eclipse.wst.dtd.core.internal.emf.DTDFile) DTDObject(org.eclipse.wst.dtd.core.internal.emf.DTDObject)

Example 7 with DTDFile

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;
}
Also used : HashMap(java.util.HashMap) Resource(org.eclipse.emf.ecore.resource.Resource) Iterator(java.util.Iterator) URI(org.eclipse.emf.common.util.URI) Map(java.util.Map) HashMap(java.util.HashMap) DTDFile(org.eclipse.wst.dtd.core.internal.emf.DTDFile)

Example 8 with DTDFile

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);
}
Also used : EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) DTDObject(org.eclipse.wst.dtd.core.internal.emf.DTDObject) EObject(org.eclipse.emf.ecore.EObject) DTDFile(org.eclipse.wst.dtd.core.internal.emf.DTDFile)

Example 9 with DTDFile

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);
}
Also used : DTDUtil(org.eclipse.wst.dtd.core.internal.emf.util.DTDUtil) DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) URL(java.net.URL) DTDFile(org.eclipse.wst.dtd.core.internal.emf.DTDFile)

Aggregations

DTDFile (org.eclipse.wst.dtd.core.internal.emf.DTDFile)9 Iterator (java.util.Iterator)4 DTDObject (org.eclipse.wst.dtd.core.internal.emf.DTDObject)3 Collection (java.util.Collection)2 EObject (org.eclipse.emf.ecore.EObject)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EList (org.eclipse.emf.common.util.EList)1 URI (org.eclipse.emf.common.util.URI)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 URIResolver (org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)1 DTDElement (org.eclipse.wst.dtd.core.internal.emf.DTDElement)1 DTDElementReferenceContent (org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent)1 DTDEntity (org.eclipse.wst.dtd.core.internal.emf.DTDEntity)1 DTDUtil (org.eclipse.wst.dtd.core.internal.emf.util.DTDUtil)1 DTDVisitor (org.eclipse.wst.dtd.core.internal.emf.util.DTDVisitor)1 ErrorMessage (org.eclipse.wst.dtd.core.internal.saxparser.ErrorMessage)1