Package org.eclipse.wst.sse.core.internal.encoding

Examples of org.eclipse.wst.sse.core.internal.encoding.EncodingMemento


  private IResourceCharsetDetector getDetector() {
    return new HTMLResourceEncodingDetector();
  }

  private void handleCalculations(IContentDescription description, IResourceCharsetDetector detector) throws IOException {
    EncodingMemento encodingMemento = ((HTMLResourceEncodingDetector) detector).getEncodingMemento();
    Object detectedByteOrderMark = encodingMemento.getUnicodeBOM();
    if (detectedByteOrderMark != null) {
      Object existingByteOrderMark = description.getProperty(IContentDescription.BYTE_ORDER_MARK);
      if (!detectedByteOrderMark.equals(existingByteOrderMark)) {
        description.setProperty(IContentDescription.BYTE_ORDER_MARK, detectedByteOrderMark);
      }
    }

    if (!encodingMemento.isValid()) {
      description.setProperty(IContentDescriptionExtended.UNSUPPORTED_CHARSET, encodingMemento.getInvalidEncoding());
      description.setProperty(IContentDescriptionExtended.APPROPRIATE_DEFAULT, encodingMemento.getAppropriateDefault());
    }

    Object detectedCharset = encodingMemento.getDetectedCharsetName();
    Object javaCharset = encodingMemento.getJavaCharsetName();

    if (detectedCharset != null) {
      description.setProperty(IContentDescriptionExtended.DETECTED_CHARSET, detectedCharset);
    }
View Full Code Here


  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;
        }
View Full Code Here

   * @param detector
   * @throws IOException
   */
  private void handleCalculations(IContentDescription description, IResourceCharsetDetector detector) throws IOException {

    EncodingMemento encodingMemento = ((HTMLResourceEncodingDetector) 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);
      // not sure why would ever be different, so if is different, may
      // 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) {
View Full Code Here

  /**
   * 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.
View Full Code Here

   */
  abstract public String getSpecDefaultEncoding();

  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;
View Full Code Here

    String encodingName;
    encodingName = getSpecDefaultEncoding();
    if (encodingName != null) {
      // createEncodingMemento(encodingName,
      // EncodingMemento.USED_CONTENT_TYPE_DEFAULT);
      fEncodingMemento = new EncodingMemento();
      fEncodingMemento.setJavaCharsetName(encodingName);
      fEncodingMemento.setAppropriateDefault(encodingName);
    }
  }
View Full Code Here

   * @param detector
   * @throws IOException
   */
  private int handleCalculations(int result, IContentDescription description, IResourceCharsetDetector detector) throws IOException {
    int returnResult = result;
    EncodingMemento encodingMemento = ((XMLResourceEncodingDetector) detector).getEncodingMemento();
    if (description != null) {
      // 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);
        // not sure why would ever be different, so if is different,
        // may
        // 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) {
View Full Code Here

  public String getEncoding() throws IOException {
    return UTF_8;
  }

  public EncodingMemento getEncodingMemento() throws IOException {
    EncodingMemento fEncodingMemento = new EncodingMemento();
    fEncodingMemento.setJavaCharsetName(UTF_8_JAVA);
    fEncodingMemento.setDetectedCharsetName(UTF_8);

    fEncodingMemento.setAppropriateDefault(getSpecDefaultEncoding());
    return null;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.wst.sse.core.internal.encoding.EncodingMemento

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.