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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations