Search in sources :

Example 1 with IDocumentCharsetDetector

use of org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector in project webtools.sourceediting by eclipse.

the class DTDDocumentCharsetDetector method parseInput.

/**
 */
protected void parseInput() throws IOException {
    IDocumentCharsetDetector documentEncodingDetector = new XMLDocumentCharsetDetector();
    documentEncodingDetector.set(fReader);
    fEncodingMemento = ((XMLResourceEncodingDetector) documentEncodingDetector).getEncodingMemento();
}
Also used : IDocumentCharsetDetector(org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector) XMLDocumentCharsetDetector(org.eclipse.wst.xml.core.internal.encoding.XMLDocumentCharsetDetector)

Example 2 with IDocumentCharsetDetector

use of org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method updateEncodingMemento.

private void updateEncodingMemento() {
    boolean failed = false;
    IStructuredModel internalModel = getInternalModel();
    if (internalModel != null) {
        IStructuredDocument doc = internalModel.getStructuredDocument();
        EncodingMemento memento = doc.getEncodingMemento();
        IDocumentCharsetDetector detector = internalModel.getModelHandler().getEncodingDetector();
        if (memento != null && detector != null) {
            detector.set(doc);
            try {
                String newEncoding = detector.getEncoding();
                if (newEncoding != null) {
                    memento.setDetectedCharsetName(newEncoding);
                }
            } catch (IOException e) {
                failed = true;
            }
        }
        /**
         * Be sure to use the new value but only if no exception
         * occurred. (we may find cases we need to do more error recovery
         * there) should be near impossible to get IOException from
         * processing the _document_
         */
        if (!failed) {
            doc.setEncodingMemento(memento);
        }
    }
}
Also used : IDocumentCharsetDetector(org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector) EncodingMemento(org.eclipse.wst.sse.core.internal.encoding.EncodingMemento) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 3 with IDocumentCharsetDetector

use of org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector in project webtools.sourceediting by eclipse.

the class JSPDocumentLoader method getEmbeddedType.

/**
 * Determine the MIME content type specified in a page directive. This
 * should appear "as early as possible in the JSP page" according to the
 * JSP v1.2 specification.
 */
private EmbeddedTypeHandler getEmbeddedType(IFile file) throws UnsupportedEncodingException, CoreException, IOException {
    EmbeddedTypeHandler handler = null;
    if (fFullPreparedReader == null) {
        handler = getJSPDefaultEmbeddedType();
    } else {
        String mimeType = null;
        IDocumentCharsetDetector jspProvider = getDocumentEncodingDetector();
        Reader fullPreparedReader = getFullPreparedReader();
        BufferedLimitedReader limitedReader = new BufferedLimitedReader(fullPreparedReader, CodedIO.MAX_BUF_SIZE);
        jspProvider.set(limitedReader);
        if (jspProvider instanceof IJSPHeadContentDetector) {
            mimeType = ((IJSPHeadContentDetector) jspProvider).getContentType();
            fullPreparedReader.reset();
        }
        EmbeddedTypeRegistry reg = getEmbeddedContentTypeRegistry();
        if (mimeType == null || mimeType.length() == 0) {
            handler = getJSPDefaultEmbeddedType();
        } else {
            handler = reg.getTypeFor(mimeType);
        }
    }
    return handler;
}
Also used : EmbeddedTypeRegistry(org.eclipse.wst.sse.core.internal.modelhandler.EmbeddedTypeRegistry) EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IDocumentCharsetDetector(org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector) BufferedLimitedReader(org.eclipse.wst.sse.core.internal.encoding.util.BufferedLimitedReader) BufferedLimitedReader(org.eclipse.wst.sse.core.internal.encoding.util.BufferedLimitedReader) Reader(java.io.Reader)

Aggregations

IDocumentCharsetDetector (org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector)3 IOException (java.io.IOException)1 Reader (java.io.Reader)1 EncodingMemento (org.eclipse.wst.sse.core.internal.encoding.EncodingMemento)1 BufferedLimitedReader (org.eclipse.wst.sse.core.internal.encoding.util.BufferedLimitedReader)1 EmbeddedTypeHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler)1 EmbeddedTypeRegistry (org.eclipse.wst.sse.core.internal.modelhandler.EmbeddedTypeRegistry)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 XMLDocumentCharsetDetector (org.eclipse.wst.xml.core.internal.encoding.XMLDocumentCharsetDetector)1