gt:         if (stiReport == null) {
context: /*
   * Decompiled with CFR 0_114.
   * 
   * Could not load the following classes:
   *  com.stimulsoft.base.StiAttribute
   *  com.stimulsoft.base.drawing.StiColor
   *  com.stimulsoft.base.exception.StiException
   *  com.stimulsoft.base.json.JSONException
   *  com.stimulsoft.base.json.JSONObject
   *  com.stimulsoft.base.localization.StiLocalization
   *  com.stimulsoft.base.mail.StiMailProperties
   *  com.stimulsoft.lib.base64.StiBase64DecoderUtil
   *  com.stimulsoft.lib.base64.StiBase64EncoderUtil
   *  com.stimulsoft.lib.utils.StiValidationUtil
   *  com.stimulsoft.lib.utils.StiXmlUtil
   *  com.stimulsoft.report.StiReport
   *  com.stimulsoft.report.components.StiBookmark
   *  com.stimulsoft.report.components.StiBookmarksCollection
   *  com.stimulsoft.report.components.StiPagesCollection
   *  com.stimulsoft.report.dictionary.StiDictionary
   *  com.stimulsoft.report.export.service.StiHtmlExportService
   *  com.stimulsoft.report.export.service.StiPdfExportService
   *  com.stimulsoft.report.export.settings.StiHtmlExportSettings
   *  com.stimulsoft.report.export.settings.StiPdfExportSettings
   *  com.stimulsoft.report.export.tools.StiPdfAutoPrintMode
   *  com.stimulsoft.report.export.tools.html.StiHtmlExportBookmarksMode
   *  com.stimulsoft.web.helper.StiFileResult
   *  com.stimulsoft.web.html.StiHtmlElement
   *  javax.servlet.ServletContext
   *  javax.servlet.http.HttpServletRequest
   *  javax.servlet.http.HttpSession
   */
  package com.stimulsoft.webviewer;
  
  import com.stimulsoft.base.StiAttribute;
  import com.stimulsoft.base.drawing.StiColor;
  import com.stimulsoft.base.exception.StiException;
  import com.stimulsoft.base.json.JSONException;
  import com.stimulsoft.base.json.JSONObject;
  import com.stimulsoft.base.localization.StiLocalization;
  import com.stimulsoft.base.mail.StiMailProperties;
  import com.stimulsoft.lib.base64.StiBase64DecoderUtil;
  import com.stimulsoft.lib.base64.StiBase64EncoderUtil;
  import com.stimulsoft.lib.utils.StiValidationUtil;
  import com.stimulsoft.lib.utils.StiXmlUtil;
  import com.stimulsoft.report.StiReport;
  import com.stimulsoft.report.components.StiBookmark;
  import com.stimulsoft.report.components.StiBookmarksCollection;
  import com.stimulsoft.report.components.StiPagesCollection;
  import com.stimulsoft.report.dictionary.StiDictionary;
  import com.stimulsoft.report.export.service.StiHtmlExportService;
  import com.stimulsoft.report.export.service.StiPdfExportService;
  import com.stimulsoft.report.export.settings.StiHtmlExportSettings;
  import com.stimulsoft.report.export.settings.StiPdfExportSettings;
  import com.stimulsoft.report.export.tools.StiPdfAutoPrintMode;
  import com.stimulsoft.report.export.tools.html.StiHtmlExportBookmarksMode;
  import com.stimulsoft.web.helper.StiFileResult;
  import com.stimulsoft.web.html.StiHtmlElement;
  import com.stimulsoft.webviewer.StiJavascriptParameters;
  import com.stimulsoft.webviewer.StiRequiredOptions;
  import com.stimulsoft.webviewer.StiWebViewerOptions;
  import com.stimulsoft.webviewer.enums.StiPagesViewMode;
  import com.stimulsoft.webviewer.enums.StiWebViewerTheme;
  import com.stimulsoft.webviewer.helper.StiEditableFieldsHelper;
  import com.stimulsoft.webviewer.helper.StiExportsClass;
  import com.stimulsoft.webviewer.helper.StiJavascriptHelper;
  import com.stimulsoft.webviewer.helper.StiReportHelper;
  import com.stimulsoft.webviewer.helper.StiResourcesHelper;
  import com.stimulsoft.webviewer.helper.StiVariablesHelper;
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.OutputStreamWriter;
  import java.io.UnsupportedEncodingException;
  import java.io.Writer;
  import java.lang.reflect.Method;
  import java.net.URL;
  import java.security.NoSuchAlgorithmException;
  import java.util.Hashtable;
  import java.util.List;
  import java.util.Map;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;
  import javax.xml.transform.Result;
  import javax.xml.transform.Source;
  import javax.xml.transform.Transformer;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.stream.StreamResult;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.ProcessingInstruction;
  
  public class StiWebViewer {
      public static final String VERSION = StiAttribute.getVersion((boolean)true);
      protected static final Logger LOG = Logger.getLogger(StiWebViewer.class.getName());
      public static final String PAGE_SEPARATOR = "###STIMULSOFTPAGESEPARATOR###";
      public static final String ACTION_REPORT_SNAPSHOT = "ReportSnapshot";
      public static final String ACTION_VIEWER_EVENT = "ViewEvent";
      public static final String ACTION_PRINT_REPORT = "Print";
      public static final String ACTION_EXPORT_REPORT = "Export";
      public static final String ACTION_DESIGN_REPORT = "Design";
      public static final String ACTION_ITERACTION = "Iteraction";
      public static final String ACTION_EMAIL_REPORT = "Email";
      public static final String ACTION_JS = "js";
      private static final String SESSION_ATTRIBUTE_PARAMETERS = "webviewer_params";
      public static final String SESSION_ATTRIBUTE_DEMO_REPORT_NAME = "webviewer_demo_report_name";
      private static final String SESSION_ATTRIBUTE_CACHED_REPORT = "webviewer_cached_report";
      public static final String VIEWER_PARAMETER_ATTRIBUTE = "mvcviewer_parameters";
      public static final String VIEWER_ID_PARAM = "viewerId";
      public static final String PARAMETERS_ATTRIBUTE = "parameters";
      public static final String MAIL_PROPERTIES = "mailProperties";
      public static final String EXCEPTION_HANDLER = "exceptionHandler";
      private StiWebViewerOptions options;
      private String id;
  
      public StiWebViewer(StiWebViewerOptions stiWebViewerOptions, URL uRL) {
          this.options = stiWebViewerOptions;
          this.id = stiWebViewerOptions.getViewerID();
          String string = stiWebViewerOptions.getLocalization();
          if (StiValidationUtil.isNotNullOrEmpty((String)string)) {
              File file = new File(string);
              if (file.exists()) {
                  try {
                      StiLocalization stiLocalization = StiLocalization.load((InputStream)new FileInputStream(file));
                      StiLocalization.setLocalization((StiLocalization)stiLocalization);
                  }
                  catch (FileNotFoundException var5_6) {
                      LOG.log(Level.SEVERE, "", var5_6);
                  }
                  catch (StiException var5_7) {
                      LOG.log(Level.SEVERE, "", (Throwable)var5_7);
                  }
              } else {
                  LOG.log(Level.SEVERE, "Unable to load localization file: " + file.getAbsolutePath());
              }
          }
      }
  
      public String getViewer(URL uRL, ServletContext servletContext) throws ParserConfigurationException, IOException {
          DocumentBuilderFactory documentBuilderFactory = StiXmlUtil.getBuilderFactory();
          DocumentBuilder documentBuilder = null;
          documentBuilder = documentBuilderFactory.newDocumentBuilder();
          Document document = documentBuilder.newDocument();
          ProcessingInstruction processingInstruction = document.createProcessingInstruction("javax.xml.transform.disable-output-escaping", "");
          document.appendChild(processingInstruction);
          Element element = StiHtmlElement.createPanelHtmlElement((Document)document);
          document.appendChild(element);
          StiHtmlElement.setID((Element)element, (String)this.id);
          return this.createChildControls(element, document, uRL, servletContext);
      }
  
      protected String createChildControls(Element element, Document document, URL uRL, ServletContext servletContext) throws IOException {
          String string;
          StiHtmlElement.addStyle((Element)element, (String)"width", (String)this.options.getWidth());
          StiHtmlElement.addStyle((Element)element, (String)"height", (String)(StiValidationUtil.isNotNullOrEmpty((String)this.options.getHeight()) ? this.options.getHeight() : (this.options.getAppearance().isScrollbarsMode() ? "600px" : "100%")));
          StiHtmlElement.setBackColor((Element)element, (StiColor)this.options.getAppearance().getBackgroundColor());
          JSONObject jSONObject = new JSONObject();
          try {
              jSONObject.put("viewerId", (Object)this.id);
              jSONObject.put("theme", (Object)this.options.getTheme().toString());
              jSONObject.put("requestAbsoluteUrl", (Object)(uRL.toString() + "/" + "stimulsoft_webviewer_action" + "?a={action}"));
              jSONObject.put("requestUrl", (Object)(uRL.toString() + "/" + "stimulsoft_webviewer_action" + "?a={action}"));
              jSONObject.put("requestStylesUrl", (Object)(uRL.toString() + "/" + "stimulsoft_webviewer_action" + "?a={action}"));
              jSONObject.put("routes", (Object)"[]");
              jSONObject.put("formValues", (Object)"{}");
              jSONObject.put("cultureName", (Object)StiLocalization.getLocalization().getCultureName());
              jSONObject.put("shortProductVersion", (Object)StiAttribute.getVersion((boolean)true));
              jSONObject.put("productVersion", (Object)("<br>Version: " + StiAttribute.getVersion((boolean)true) + "<br>Java: " + System.getProperty("java.runtime.version") + " " + System.getProperty("os.name") + " " + System.getProperty("sun.os.patch.level") + " " + System.getProperty("os.arch") + " " + System.getProperty("os.version")));
              String string2 = string = StiValidationUtil.isNotNullOrEmpty((String)this.options.getHeight()) ? this.options.getHeight() : null;
              jSONObject.put("viewerHeightType", (Object)(string == null ? "Pixel" : (string.substring(string.length() - 1).equals("%") ? "Percentage" : "Pixel")));
              jSONObject.put("actions", (Object)this.options.getActions());
              jSONObject.put("server", (Object)this.toHash(this.options.getServer()));
              jSONObject.put("appearance", (Object)this.toHash(this.options.getAppearance()));
              jSONObject.put("toolbar", (Object)this.toHash(this.options.getToolbar()));
              jSONObject.put("exports", (Object)this.toHash(this.options.getExports()));
              jSONObject.put("email", (Object)this.toHash(this.options.getEmail()));
          }
          catch (JSONException var6_7) {
              var6_7.printStackTrace();
          }
          string = String.format("{options:%s,defaultExportSettings:%s}", jSONObject.toString(), new JSONObject(StiExportsClass.getDefaultExportSettings(this.options)).toString());
          String string3 = "";
          if (StiValidationUtil.isNotNullOrEmpty((String)this.options.getLocalization())) {
              try {
                  string3 = "&l=" + new String(StiBase64EncoderUtil.encode((byte[])this.options.getLocalization().getBytes("UTF-8")), "UTF-8");
              }
              catch (Exception var8_9) {
                  var8_9.printStackTrace();
              }
          }
          Element element2 = StiHtmlElement.createJavascriptHtmlElement((Document)document);
          String string4 = uRL.toString() + "/" + "stimulsoft_webviewer_action" + "?mvcviewer_resource=scripts&a=ViewEvent&mvcviewer_theme=" + this.options.getTheme().toString() + "&v=" + VERSION + string3;
          element2.setAttribute("src", string4);
          element.appendChild(element2);
          Element element3 = StiHtmlElement.createPanelHtmlElement((Document)document);
          StiHtmlElement.setCssClass((Element)element3, (String)"stiMvcViewerMainPanel");
          StiHtmlElement.setID((Element)element3, (String)(this.id + "_MvcViewerMainPanel"));
          element.appendChild(element3);
          Element element4 = StiHtmlElement.createJavascriptHtmlElement((Document)document);
          element4.setTextContent(String.format("var js%s = new StiMvcViewer(%s)", this.id, string));
          element3.appendChild(element4);
          Element element5 = StiHtmlElement.createJavascriptHtmlElement((Document)document);
          element5.setTextContent(String.format("if (document.readyState == 'complete') js%s.postAction(); else js%s.addEvent(window, 'load', function () { js%s.postAction() });", this.id, this.id, this.id));
          element.appendChild(element5);
          if (this.options.getRefreshTimeout() > 0) {
              Element element6 = StiHtmlElement.createJavascriptHtmlElement((Document)document);
              element6.setTextContent(String.format("function refreshSession(){ js%s.postAjax('%s' + '?refresh=' + Math.random(),'', function(){} ); setTimeout('refreshSession()',%s);}refreshSession();", this.id, uRL.toString() + "/" + "stimulsoft_webviewer_action", this.options.getRefreshTimeout() * 60000));
              element.appendChild(element6);
          }
          return StiWebViewer.serialize(document, true);
      }
  
      private JSONObject toHash(Object object) {
          JSONObject jSONObject = new JSONObject();
          try {
              for (Method method : object.getClass().getMethods()) {
                  if (!method.getName().startsWith("get") && !method.getName().startsWith("is") || method.getParameterTypes().length != 0) continue;
                  String string = method.getName().substring(method.getName().startsWith("get") ? 3 : 2);
                  Object object2 = method.invoke(object, new Object[0]);
                  string = string.substring(0, 1).toLowerCase() + string.substring(1);
                  if (object2 instanceof StiColor) {
                      StiColor stiColor = (StiColor)object2;
                      jSONObject.put(string, (Object)("" + stiColor.getR() + "," + stiColor.getG() + "," + stiColor.getB()));
                      continue;
                  }
                  jSONObject.put(string, object2 != null ? object2 : "");
              }
          }
          catch (Exception var3_4) {
              var3_4.printStackTrace();
          }
          return jSONObject;
      }
  
      public static String serialize(Document document, boolean bl) throws IOException {
          try {
              TransformerFactory transformerFactory = TransformerFactory.newInstance();
              Transformer transformer = transformerFactory.newTransformer();
              transformer.setOutputProperty("method", "html");
              transformer.setOutputProperty("omit-xml-declaration", "yes");
              ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
              transformer.transform(new DOMSource(document), new StreamResult(new OutputStreamWriter((OutputStream)byteArrayOutputStream, "UTF-8")));
              byteArrayOutputStream.close();
              return new String(byteArrayOutputStream.toByteArray(), "UTF8");
          }
          catch (Exception var2_3) {
              LOG.log(Level.SEVERE, "", var2_3);
              return "";
          }
      }
  
      public static StiReport getReportObject(HttpServletRequest httpServletRequest, StiJavascriptParameters stiJavascriptParameters) {
          return StiWebViewer.getReportObject(httpServletRequest, null, stiJavascriptParameters);
      }
  
      public static StiReport getReportObject(HttpServletRequest httpServletRequest, String string, StiJavascriptParameters stiJavascriptParameters) {
          if (stiJavascriptParameters.getOptions().getViewerId() == null) {
              return null;
          }
          Object object = null;
          Object[] arrobject = new Object[4];
          arrobject[0] = stiJavascriptParameters.getOptions().getViewerId();
          arrobject[1] = stiJavascriptParameters.getOptions().getClientGuid();
          arrobject[2] = stiJavascriptParameters.getOptions().getReportGuid();
          arrobject[3] = string != null ? string : stiJavascriptParameters.getOptions().getParamsGuid();
          String string2 = String.format("%s|%s|%s|%s", arrobject);
          object = httpServletRequest.getSession().getAttribute(string2);
          if (object == null) {
              string2 = String.format("%s|%s|%s", stiJavascriptParameters.getOptions().getViewerId(), stiJavascriptParameters.getOptions().getClientGuid(), stiJavascriptParameters.getOptions().getReportGuid());
              object = httpServletRequest.getSession().getAttribute(string2);
          }
          return (StiReport)object;
      }
  
      private static String getViewerId(HttpServletRequest httpServletRequest) {
          String string = "";
          try {
              if (httpServletRequest.getParameter("mvcviewer_parameters") != null) {
                  string = new JSONObject(new String(StiBase64DecoderUtil.decode((String)httpServletRequest.getParameter("mvcviewer_parameters")), "UTF-8")).getString("viewerId");
              }
          }
          catch (Exception var2_2) {
              var2_2.printStackTrace();
          }
          return string;
      }
  
      public static Object getStoredObject(HttpServletRequest httpServletRequest, String string) {
          return httpServletRequest.getSession().getAttribute(string + "webviewer_cached_report");
      }
  
      public void storeObject(HttpServletRequest httpServletRequest, Object object, String string) throws IOException, StiException {
          String string2 = string + "webviewer_cached_report";
          httpServletRequest.getSession().removeAttribute(string + "webviewer_params");
          if (object != null) {
              httpServletRequest.getSession().setAttribute(string2, object);
          }
      }
  
      public static void saveReportObject(HttpServletRequest httpServletRequest, StiReport stiReport, StiJavascriptParameters stiJavascriptParameters) {
          StiWebViewer.saveReportObject(httpServletRequest, stiReport, false, stiJavascriptParameters);
      }
  
      public static void saveReportObject(HttpServletRequest httpServletRequest, StiReport stiReport, boolean bl, StiJavascriptParameters stiJavascriptParameters) {
          if (!stiJavascriptParameters.hasParameters()) {
              return;
          }
          if (stiReport != null) {
              String string = String.format("%s|%s|%s", stiJavascriptParameters.getOptions().getViewerId(), stiJavascriptParameters.getOptions().getClientGuid(), stiReport.getReportGuid());
              if (!stiReport.isDocument && "null".equals(stiJavascriptParameters.getOptions().getParamsGuid()) && (stiReport.getDictionary().getisRequestFromUserVariablesPresent() || StiReportHelper.isInteractionsPresent(stiReport))) {
                  StiReport stiReport2 = StiReportHelper.createReportCopy(stiReport);
                  stiReport2.isRendered = false;
                  httpServletRequest.getSession().setAttribute(string, (Object)stiReport2);
              }
              string = String.format("%s|%s", string, stiJavascriptParameters.getOptions().getParamsGuid());
              if (stiReport.isDocument && !stiReport.getIsRendered()) {
                  stiReport.Render(false);
              }
              httpServletRequest.getSession().setAttribute(string, (Object)stiReport);
          }
      }
  
      public static Object viewerEventResult(HttpServletRequest httpServletRequest, StiReport stiReport, boolean bl, StiJavascriptParameters stiJavascriptParameters) throws IOException, StiException, JSONException, NoSuchAlgorithmException, ParserConfigurationException {
          if (bl) {
              if ("resource".equals(stiJavascriptParameters.getAction())) {
                  return StiResourcesHelper.get(new URL(httpServletRequest.getScheme(), httpServletRequest.getServerName(), httpServletRequest.getServerPort(), httpServletRequest.getContextPath()), stiJavascriptParameters);
              }
              if ("print".equals(stiJavascriptParameters.getAction())) {
                  return StiWebViewer.printReportResult(httpServletRequest, stiReport);
              }
              if ("export".equals(stiJavascriptParameters.getAction())) {
                  return StiWebViewer.exportReportResult(httpServletRequest, stiReport);
              }
              if ("init-vars".equals(stiJavascriptParameters.getAction()) || "variables".equals(stiJavascriptParameters.getAction()) || "sorting".equals(stiJavascriptParameters.getAction()) || "drill-down".equals(stiJavascriptParameters.getAction()) || "drilldown".equals(stiJavascriptParameters.getAction()) || "collapsing".equals(stiJavascriptParameters.getAction())) {
                  return StiWebViewer.interactionResult(httpServletRequest, stiReport, stiJavascriptParameters);
              }
          }
          if (!stiJavascriptParameters.hasParameters()) {
              return "{}";
          }
  