use of org.eclipse.wst.sse.core.internal.encoding.EncodingMemento in project webtools.sourceediting by eclipse.
the class UnicodeBOMEncodingDetector method createEncodingMemento.
private EncodingMemento createEncodingMemento(String javaEncodingName) {
EncodingMemento encodingMemento = new EncodingMemento();
encodingMemento.setJavaCharsetName(javaEncodingName);
String ianaName = Charset.forName(javaEncodingName).name();
encodingMemento.setDetectedCharsetName(ianaName);
if (javaEncodingName.equals(UTF_8_CHARSET_NAME)) {
encodingMemento.setUTF83ByteBOMUsed(true);
}
return encodingMemento;
}
use of org.eclipse.wst.sse.core.internal.encoding.EncodingMemento in project webtools.sourceediting by eclipse.
the class ContentDescriberForJSP method handleStandardCalculations.
/**
* @param description
* @param detector
* @throws IOException
*/
private void handleStandardCalculations(IContentDescription description, IResourceCharsetDetector detector) throws IOException {
// note: if we're asked for one, we set them all. I need to be sure if
// called
// mulitiple times (one for each, say) that we don't waste time
// processing same
// content again.
EncodingMemento encodingMemento = ((JSPResourceEncodingDetector) detector).getEncodingMemento();
// TODO: I need to verify to see if this BOM work is always done
// by text type.
Object detectedByteOrderMark = encodingMemento.getUnicodeBOM();
if (detectedByteOrderMark != null) {
Object existingByteOrderMark = description.getProperty(IContentDescription.BYTE_ORDER_MARK);
// need to "push" up into base.
if (!detectedByteOrderMark.equals(existingByteOrderMark))
description.setProperty(IContentDescription.BYTE_ORDER_MARK, detectedByteOrderMark);
}
if (!encodingMemento.isValid()) {
// note: after setting here, its the mere presence of
// IContentDescriptionExtended.UNSUPPORTED_CHARSET
// in the resource's description that can be used to determine if
// invalid
// in those cases, the "detected" property contains an
// "appropriate default" to use.
description.setProperty(IContentDescriptionExtended.UNSUPPORTED_CHARSET, encodingMemento.getInvalidEncoding());
description.setProperty(IContentDescriptionExtended.APPROPRIATE_DEFAULT, encodingMemento.getAppropriateDefault());
}
Object detectedCharset = encodingMemento.getDetectedCharsetName();
Object javaCharset = encodingMemento.getJavaCharsetName();
// we always include detected, if its different than java
handleDetectedSpecialCase(description, detectedCharset, javaCharset);
if (javaCharset != null) {
Object existingCharset = description.getProperty(IContentDescription.CHARSET);
if (javaCharset.equals(existingCharset)) {
handleDetectedSpecialCase(description, detectedCharset, javaCharset);
} else {
// we may need to add what we found, but only need to add
// if different from the default.
Object defaultCharset = detector.getSpecDefaultEncoding();
if (defaultCharset != null) {
if (!defaultCharset.equals(javaCharset)) {
description.setProperty(IContentDescription.CHARSET, javaCharset);
}
} else {
// assuming if there is no spec default, we always need to
// add, I'm assuming
description.setProperty(IContentDescription.CHARSET, javaCharset);
}
}
}
}
use of org.eclipse.wst.sse.core.internal.encoding.EncodingMemento 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);
}
}
}
use of org.eclipse.wst.sse.core.internal.encoding.EncodingMemento in project webtools.sourceediting by eclipse.
the class AbstractResourceEncodingDetector method getSpecDefaultEncodingMemento.
public EncodingMemento getSpecDefaultEncodingMemento() {
resetAll();
EncodingMemento result = null;
String enc = getSpecDefaultEncoding();
if (enc != null) {
createEncodingMemento(enc, EncodingMemento.DEFAULTS_ASSUMED_FOR_EMPTY_INPUT);
fEncodingMemento.setAppropriateDefault(enc);
result = fEncodingMemento;
}
return result;
}
use of org.eclipse.wst.sse.core.internal.encoding.EncodingMemento in project webtools.sourceediting by eclipse.
the class AbstractResourceEncodingDetector method createEncodingMemento.
/**
* Note: once this instance is created, trace info still needs to be
* appended by caller, depending on the context its created.
*/
private void createEncodingMemento(String detectedCharsetName) {
fEncodingMemento = new EncodingMemento();
fEncodingMemento.setJavaCharsetName(getAppropriateJavaCharset(detectedCharsetName));
fEncodingMemento.setDetectedCharsetName(detectedCharsetName);
// TODO: if detectedCharset and spec default is
// null, need to use "work
// bench based" defaults.
fEncodingMemento.setAppropriateDefault(getSpecDefaultEncoding());
}
Aggregations