Search in sources :

Example 6 with CMDocumentManager

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.

the class ModelQueryTester method testDTDLoadFromSystemID_2.

/**
 * A short test to ensure that a DTD, the XHTML 1.0 Transitional one, can
 * be loaded from a system reference.
 *
 * Note: May require a functioning network connection for the references
 * to be resolved properly.
 * @throws IOException
 */
public void testDTDLoadFromSystemID_2() throws IOException {
    if (testShippedDTDLookup) {
        URL installationPath = Platform.getBundle(JSPUITestsPlugin.ID).getEntry("/");
        String diskLocation = null;
        diskLocation = FileLocator.resolve(installationPath).toExternalForm();
        assertTrue("failed to resolve plugin install path", diskLocation != null);
        setUpXML();
        String content = "<?xml version=\"1.0\"?><!DOCTYPE html SYSTEM " + diskLocation + "testfiles/XHTML/xhtml1-transitional.dtd\"" + "><html></html>";
        fModel.getStructuredDocument().set(content);
        CMDocumentManager documentManagaer = fModelQuery.getCMDocumentManager();
        documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, false);
        documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, true);
        // see defect 282429
        CMElementDeclaration htmlDecl = (CMElementDeclaration) fModelQuery.getCMNode((Node) fModel.getIndexedRegion(content.length() - 2));
        assertTrue("xhtml1-transitional.dtd not loaded", htmlDecl != null);
        // HTML's children are within a group
        CMContent contents = htmlDecl.getContent();
        assertTrue("content type is not a group", contents.getNodeType() == CMNode.GROUP);
        CMGroup group = (CMGroup) contents;
        int operator = group.getOperator();
        CMNodeList childList = group.getChildNodes();
        int max = contents.getMaxOccur();
        int min = contents.getMinOccur();
        // the group should be allowed once, with a sequence whose first
        // entry
        // is the declaration for HEAD
        assertTrue("occurrance of group", min == 1 && max == 1);
        assertTrue("relationship in group", operator == CMGroup.SEQUENCE);
        assertTrue("content descriptor type, position 0", contents.getNodeType() == CMNode.GROUP);
        assertTrue("child order (HEAD first)", childList.item(0).getNodeName().equals(HTML40Namespace.ElementName.HEAD.toLowerCase()));
        assertTrue("child order (BODY second)", childList.item(1).getNodeName().equals(HTML40Namespace.ElementName.BODY.toLowerCase()));
    }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent) URL(java.net.URL) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 7 with CMDocumentManager

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.

the class GlobalCMDocumentCacheTest method getCMDocumentFromXMLFile.

private CMDocument getCMDocumentFromXMLFile(String documentPath) {
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(documentPath));
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel structuredModel = null;
    CMDocument cmDocument = null;
    try {
        structuredModel = modelManager.getModelForRead(file);
        Document document = ((IDOMModel) structuredModel).getDocument();
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
        CMDocumentManager cmDocumentManager = modelQuery.getCMDocumentManager();
        CMDocumentLoader loader = new CMDocumentLoader(document, cmDocumentManager);
        loader.loadCMDocuments();
        cmDocument = modelQuery.getCorrespondingCMDocument(document.getDocumentElement());
    } catch (Exception exception) {
        exception.printStackTrace();
    } finally {
        if (structuredModel != null) {
            structuredModel.releaseFromRead();
        }
    }
    return cmDocument;
}
Also used : Path(org.eclipse.core.runtime.Path) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) CMDocumentLoader(org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Document(org.w3c.dom.Document)

Example 8 with CMDocumentManager

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.

the class AdapterFactoryProviderForXSL method addContentBasedFactories.

@Override
protected void addContentBasedFactories(IStructuredModel structuredModel) {
    FactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry();
    Assert.isNotNull(factoryRegistry, // $NON-NLS-1$
    "Program Error: client caller must ensure model has factory registry");
    INodeAdapterFactory factory = null;
    factory = factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class);
    if (factory == null) {
        factory = new JFaceNodeAdapterFactory();
        factoryRegistry.addFactory(factory);
    }
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(structuredModel);
    if (modelQuery != null) {
        CMDocumentManager documentManager = modelQuery.getCMDocumentManager();
        if (documentManager != null) {
            IPreferenceStore store = XMLUIPlugin.getDefault().getPreferenceStore();
            boolean useInferredGrammar = (store != null) ? store.getBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR) : true;
            documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
            documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, false);
            documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_USE_CACHED_RESOLVED_URI, true);
            DOMObserver domObserver = new DOMObserver(structuredModel);
            domObserver.setGrammarInferenceEnabled(useInferredGrammar);
            domObserver.init();
        }
    }
}
Also used : CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) FactoryRegistry(org.eclipse.wst.sse.core.internal.model.FactoryRegistry) DOMObserver(org.eclipse.wst.xml.ui.internal.DOMObserver) JFaceNodeAdapterFactory(org.eclipse.wst.xsl.ui.internal.contentoutline.JFaceNodeAdapterFactory) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IJFaceNodeAdapter(org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)

Aggregations

CMDocumentManager (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager)8 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)5 Node (org.w3c.dom.Node)3 URL (java.net.URL)2 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 FactoryRegistry (org.eclipse.wst.sse.core.internal.model.FactoryRegistry)2 INodeAdapterFactory (org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IJFaceNodeAdapter (org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter)2 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 DOMObserver (org.eclipse.wst.xml.ui.internal.DOMObserver)2 File (java.io.File)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1