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

com.reprezen.genflow.swagger.doc.HtmlHelper Maven / Gradle / Ivy

The newest version!
package com.reprezen.genflow.swagger.doc;

import com.google.common.collect.Maps;
import com.reprezen.genflow.api.normal.openapi.RepreZenVendorExtension;
import com.reprezen.genflow.swagger.doc.Helper;
import com.reprezen.genflow.swagger.doc.NoEscapeString;
import java.util.Map;
import org.apache.commons.text.StringEscapeUtils;
import org.eclipse.xtend2.lib.StringConcatenation;

@SuppressWarnings("all")
public class HtmlHelper implements Helper {
  @Override
  public void init() {
  }
  
  private final Map htmlIds = Maps.newHashMap();
  
  private int nextIdNum = 1;
  
  public String htmlEscape(final String value) {
    return StringEscapeUtils.escapeHtml4(value);
  }
  
  public String htmlEscape(final NoEscapeString value) {
    return value.get();
  }
  
  public NoEscapeString noEscape(final String value) {
    return new NoEscapeString(value);
  }
  
  public String getCode(final String s) {
    String _xifexpression = null;
    boolean _isEmpty = s.isEmpty();
    if (_isEmpty) {
      _xifexpression = s;
    } else {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.append(s);
      _builder.append("");
      _xifexpression = _builder.toString();
    }
    return _xifexpression;
  }
  
  public String getSamp(final String s) {
    String _xifexpression = null;
    boolean _isEmpty = s.isEmpty();
    if (_isEmpty) {
      _xifexpression = s;
    } else {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.append(s);
      _builder.append("");
      _xifexpression = _builder.toString();
    }
    return _xifexpression;
  }
  
  public String getHtmlId(final Object obj) {
    String _elvis = null;
    String _get = this.htmlIds.get(obj);
    if (_get != null) {
      _elvis = _get;
    } else {
      String _mkId = this.mkId(obj);
      _elvis = _mkId;
    }
    final String id = _elvis;
    return id;
  }
  
  public String getHtmlId(final Object obj, final String role) {
    String _htmlId = this.getHtmlId(obj);
    String _elvis = null;
    if (role != null) {
      _elvis = role;
    } else {
      _elvis = "";
    }
    return (_htmlId + _elvis);
  }
  
  private String mkId(final Object obj) {
    String _elvis = null;
    String _pointer = this.getPointer(obj);
    String _escapeHtmlId = null;
    if (_pointer!=null) {
      _escapeHtmlId=this.escapeHtmlId(_pointer);
    }
    if (_escapeHtmlId != null) {
      _elvis = _escapeHtmlId;
    } else {
      String _xblockexpression = null;
      {
        final String id = String.format("_%05d", Integer.valueOf(this.nextIdNum));
        this.nextIdNum = (this.nextIdNum + 1);
        this.htmlIds.put(obj, id);
        _xblockexpression = id;
      }
      _elvis = _xblockexpression;
    }
    return _elvis;
  }
  
  public String escapeHtmlId(final String jsonPointer) {
    return jsonPointer.replaceAll("[^a-zA-Z0-9_]", "_");
  }
  
  public String getPointer(final Object obj) {
    RepreZenVendorExtension _get = RepreZenVendorExtension.get(obj);
    String _pointer = null;
    if (_get!=null) {
      _pointer=_get.getPointer();
    }
    return _pointer;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy