All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.acrolinx.sidebar.pojo.document.CheckResult Maven / Gradle / Ivy

/* Copyright (c) 2018 Acrolinx GmbH */
package com.acrolinx.sidebar.pojo.document;

import com.acrolinx.sidebar.pojo.settings.InputFormat;
import java.util.Map;
import java.util.Optional;

public class CheckResult {
  public static final String ACROLINX_PROCESSING_INSTRUCTION_TAG_NAME = "acrolinxCheckData";

  private final CheckedDocumentPart checkedDocumentPart;
  private Map embedCheckInformation;
  private String inputFormat;

  public CheckResult(final CheckedDocumentPart checkedDocumentPart) {
    this.checkedDocumentPart = checkedDocumentPart;
  }

  public CheckResult(
      final CheckedDocumentPart checkedDocumentPart,
      final Map embedCheckInformation,
      final String inputFormat) {
    this.checkedDocumentPart = checkedDocumentPart;
    this.embedCheckInformation = embedCheckInformation;
    this.inputFormat = inputFormat;
  }

  public CheckedDocumentPart getCheckedDocumentPart() {
    return checkedDocumentPart;
  }

  public Optional> getEmbedCheckInformation() {
    return Optional.ofNullable(embedCheckInformation);
  }

  public Optional getEmbedCheckDataAsEmbeddableString() {
    if (InputFormat.XML.toString().equalsIgnoreCase(this.inputFormat)) {
      final StringBuilder stringBuilder = new StringBuilder();
      getEmbedCheckInformation()
          .ifPresent(
              map -> {
                stringBuilder.append("
                        stringBuilder
                            .append(key)
                            .append('=')
                            .append('"')
                            .append(value)
                            .append("\" "));
                stringBuilder.append("?>");
              });

      if (stringBuilder.length() > 0) {
        return Optional.of(stringBuilder.toString());
      }
    } else if (InputFormat.MARKDOWN.toString().equalsIgnoreCase(this.inputFormat)) {
      final StringBuilder stringBuilder = new StringBuilder();
      getEmbedCheckInformation()
          .ifPresent(
              map -> {
                stringBuilder.append("");
              });

      if (stringBuilder.length() > 0) {
        return Optional.of(stringBuilder.toString());
      }
    } else if (InputFormat.HTML.toString().equalsIgnoreCase(this.inputFormat)) {
      final StringBuilder stringBuilder = new StringBuilder();
      getEmbedCheckInformation()
          .ifPresent(
              map -> {
                stringBuilder.append(
                    "
                        stringBuilder
                            .append(key)
                            .append('=')
                            .append('"')
                            .append(value)
                            .append("\" "));
                stringBuilder.append("/>");
              });

      if (stringBuilder.length() > 0) {
        return Optional.of(stringBuilder.toString());
      }
    }

    return Optional.empty();
  }

  public Optional getInputFormat() {
    return Optional.ofNullable(this.inputFormat);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy