/* * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * * https://creativecommons.org/licenses/by/4.0/ * * Unless required by applicable law or agreed to in writing, documentation * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ============LICENSE_END============================================ * * */ package org.onap.portalsdk.analytics.view; import org.json.JSONObject; import org.onap.portalsdk.analytics.RaptorObject; import com.google.gson.JsonObject; public class HtmlFormatter extends RaptorObject { private boolean bold = false; private boolean italic = false; private boolean underline = false; private String bgColor = ""; private String fontColor = ""; private String fontFace = ""; private String fontSize = ""; private String alignment = ""; private String formatId = ""; public HtmlFormatter() { super(); } public HtmlFormatter(boolean bold, boolean italic, boolean underline, String bgColor, String fontColor, String fontFace, String fontSize) { this(); setBold(bold); setItalic(italic); setUnderline(underline); setBgColor(bgColor); setFontColor(fontColor); setFontFace(fontFace); setFontSize(fontSize); } // HtmlFormatter public HtmlFormatter(boolean bold, boolean italic, boolean underline, String bgColor, String fontColor, String fontFace, String fontSize, String alignment) { this(bold, italic, underline, bgColor, fontColor, fontFace, fontSize); setAlignment(alignment); } // HtmlFormatter public boolean isBold() { return bold; } public boolean isItalic() { return italic; } public boolean isUnderline() { return underline; } public String getBgColor() { return bgColor; } public String getFontColor() { return fontColor; } public String getFontFace() { return fontFace; } public String getFontSize() { return fontSize; } public String getAlignment() { return alignment; } public void setBold(boolean bold) { this.bold = bold; } public void setItalic(boolean italic) { this.italic = italic; } public void setUnderline(boolean underline) { this.underline = underline; } public void setBgColor(String bgColor) { this.bgColor = nvl(bgColor); } public void setFontColor(String fontColor) { this.fontColor = nvl(fontColor); } public void setFontFace(String fontFace) { this.fontFace = nvl(fontFace); } public void setFontSize(String fontSize) { this.fontSize = nvl(fontSize); } public void setAlignment(String alignment) { this.alignment = nvl(alignment); } private String generateStyleHtml() { StringBuffer sb = new StringBuffer(); if (isBold()) sb.append("font-weight:bold;"); if (isItalic()) sb.append("font-style:italic;"); if (isUnderline()) sb.append("text-decoration:underline;"); if (getFontColor().length() > 0) sb.append("color:" + getFontColor() + ";"); if (getFontFace().length() > 0) sb.append("font-family:" + getFontFace() + ";"); if (getFontSize().length() > 0) sb.append("font-size:" + getFontSize() + "px;"); if (getAlignment().length() > 0) sb.append("text-align:" + getAlignment() + ";"); if (sb.length() > 0) { sb.insert(0, " style=\""); sb.append("\""); } // if return sb.toString(); } // generateStyleHtml public String generateJsonHtmlStyle() { JSONObject style = new JSONObject(); if (isBold()) style.put("font-weight", "bold"); if (isItalic()) style.put("font-style", "italic"); if (isUnderline()) style.put("text-decoration", "underline"); if(getBgColor().length()>0) style.put("background-color", getBgColor()); if (getFontColor().length() > 0) style.put("color", getFontColor()); if (getFontFace().length() > 0) style.put("font-family", getFontFace()); if (getFontSize().length() > 0) style.put("font-size", getFontSize() + "px"); if (getAlignment().length() > 0) style.put("text-align",getAlignment()); return style.toString(); } public String generateStyleForZK() { StringBuffer sb = new StringBuffer(); if (isBold()) sb.append("font-weight:bold;"); if (isItalic()) sb.append("font-style:italic;"); if (isUnderline()) sb.append("text-decoration:underline;"); if (getFontColor().length() > 0) sb.append("color:" + getFontColor() + ";"); if (getFontFace().length() > 0) sb.append("font-family:" + getFontFace() + ";"); if (getFontSize().length() > 0) sb.append("font-size:" + getFontSize() + "px;"); if (getAlignment().length() > 0) sb.append("text-align:" + getAlignment() + ";"); return sb.toString(); } // generateStyleHtml public String formatValue(String value) { String style = generateJsonHtmlStyle(); if (style.length() > 0) return style; else return value; } // formatValue public String formatLink(String value, String url, boolean drillDowninPoPUp) { if(!drillDowninPoPUp) { return "" + value + ""; } else { return "" + value + ""; } } // formatLink public String getFormatId() { return formatId; } public void setFormatId(String formatId) { this.formatId = formatId; } } // HtmlFormatter