Search in sources :

Example 1 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class PageDirectiveAdapterImpl method getHandlerFor.

private EmbeddedTypeHandler getHandlerFor(String contentType) {
    EmbeddedTypeRegistry reg = getEmbeddedContentTypeRegistry();
    EmbeddedTypeHandler handler = null;
    if (reg != null)
        handler = reg.getTypeFor(contentType);
    return handler;
}
Also used : EmbeddedTypeRegistry(org.eclipse.wst.sse.core.internal.modelhandler.EmbeddedTypeRegistry) EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler)

Example 2 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class PageDirectiveAdapterImpl method setCachedContentType.

/**
 * Sets the cachedContentType.
 *
 * @param cachedContentType
 *            The cachedContentType to set
 */
public void setCachedContentType(String newContentType) {
    /*
		 * if the passed in value is the same as existing, there's nothing to
		 * do. if its different, then we need to change the contentHandler as
		 * well and, more to the point, signal a re-initializtation is needed.
		 * 
		 * Note: if the value we're getting set to does not have a handler in
		 * the registry, we'll actually not set it to null or anything, we'll
		 * just continue on with the one we have. This is pretty important to
		 * avoid re-initializing on every key stroke if someone is typing in a
		 * new content type, but haven't yet finished the whole "word".
		 * However, if an contentType is not recognized, the registry returns
		 * the one for XML.
		 */
    /* set the actual value first, the rest is "side effect" */
    this.cachedContentType = newContentType;
    /* just safety check, can be removed later, early in release cycle */
    if (model == null) {
        // throw IllegalStateException("model should never be null in
        // PageDirective Adapter");
        Logger.log(Logger.ERROR, "model should never be null in PageDirective Adapter");
        return;
    }
    EmbeddedTypeHandler potentialNewandler = null;
    IContentDescription contentDescription = getContentDescription(model.getStructuredDocument());
    Object prop = contentDescription.getProperty(IContentDescriptionForJSP.CONTENT_FAMILY_ATTRIBUTE);
    if (prop != null) {
        if (ContentTypeFamilyForHTML.HTML_FAMILY.equals(prop)) {
            potentialNewandler = EmbeddedTypeRegistryImpl.getInstance().getTypeFor("text/html");
        }
    }
    if (potentialNewandler == null) {
        /*
			 * getHandler should always return something (never null), based
			 * on the rules in the factory.
			 */
        potentialNewandler = getHandlerFor(this.cachedContentType);
    }
    /*
		 * we do this check for re-init here, instead of in setEmbeddedType,
		 * since setEmbeddedType is called during the normal initializtion
		 * process, when re-init is not needed (since there is no content)
		 */
    if (embeddedTypeHandler == null) {
        setEmbeddedType(potentialNewandler);
    } else if (potentialNewandler != null && embeddedTypeHandler != potentialNewandler) {
        /*
			 * changing this embedded handler here may be in the middle of a
			 * notify loop. That's why we set that "it's needed". Then the
			 * model decides when its "safe" to actually do the re-init.
			 * 
			 * be sure to hold oldHandler in temp var or else setEmbeddedType
			 * will "reset" it before modelReinitNeeded(oldHandler, handler)
			 * is called
			 * 
			 */
        EmbeddedTypeHandler oldHandler = embeddedTypeHandler;
        setEmbeddedType(potentialNewandler);
        modelReinitNeeded(oldHandler, potentialNewandler);
    }
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 3 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class JSPDocumentLoader method createNewStructuredDocument.

public synchronized IEncodedDocument createNewStructuredDocument(IFile iFile) throws IOException, CoreException {
    IStructuredDocument structuredDocument = null;
    try {
        structuredDocument = createCodedDocument(iFile);
        EmbeddedTypeHandler embeddedType = getEmbeddedType(iFile);
        if (embeddedType != null)
            embeddedType.initializeParser(structuredDocument.getParser());
        fFullPreparedReader.reset();
        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);
    } finally {
        if (fFullPreparedReader != null) {
            fFullPreparedReader.close();
        }
    }
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 4 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class JSPDocumentLoader method createNewStructuredDocument.

public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream) throws UnsupportedEncodingException, IOException {
    if (filename == null && inputStream == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("can not have both null filename and inputstream");
    }
    IEncodedDocument structuredDocument = createNewStructuredDocument();
    CodedReaderCreator codedReaderCreator = new CodedReaderCreator();
    try {
        codedReaderCreator.set(filename, inputStream);
        fFullPreparedReader = codedReaderCreator.getCodedReader();
        fEncodingMemento = codedReaderCreator.getEncodingMemento();
        structuredDocument.setEncodingMemento(fEncodingMemento);
        // the fact that file is null means this method/code path is no
        // good for JSP fragments
        EmbeddedTypeHandler embeddedType = getEmbeddedType((IFile) null);
        fFullPreparedReader.reset();
        if (embeddedType != null)
            embeddedType.initializeParser(((IStructuredDocument) structuredDocument).getParser());
        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);
    } catch (CoreException e) {
        // impossible in this context
        throw new Error(e);
    } finally {
        if (fFullPreparedReader != null) {
            fFullPreparedReader.close();
        }
    }
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) CodedReaderCreator(org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator) CoreException(org.eclipse.core.runtime.CoreException) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 5 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class JSPDocumentLoader method newEncodedDocument.

/**
 * This method must return a new instance of IStructuredDocument, that has
 * been initialized with appropriate parser. For many loaders, the
 * (default) parser used is known for any input. For others, the correct
 * parser (and its initialization) is normall dependent on the content of
 * the file. This no-argument method should assume "empty input" and would
 * therefore return the default parser for the default contentType. If the
 * parser is to handle tag libraries, it must have a TaglibSupport object
 * with a valid URIResolver and this IStructuredDocument attached to it
 * before the contents are set on the IStructuredDocument.
 */
protected IEncodedDocument newEncodedDocument() {
    IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
    ((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser());
    // structuredDocument.setDocumentPartitioner(new
    // JSPJavaDocumentPartioner());
    // even though this is an "empty model" ... we want it to have at
    // least
    // the
    // default embeddeded content type handler
    EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType();
    embeddedType.initializeParser(structuredDocument.getParser());
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) JSPReParser(org.eclipse.jst.jsp.core.internal.parser.JSPReParser)

Aggregations

EmbeddedTypeHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler)24 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)11 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)9 Document (org.w3c.dom.Document)9 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)5 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)3 BasicStructuredDocument (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)2 JSPReParser (org.eclipse.jst.jsp.core.internal.parser.JSPReParser)2 EmbeddedTypeRegistry (org.eclipse.wst.sse.core.internal.modelhandler.EmbeddedTypeRegistry)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1