/*
* Created on Oct 25, 2006
*
*/
package com.cvicse.report.ui.portal.util;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* Contains methods to add no cache string to a url,creating the charts.<br>
* This class can be used to create chart xml given the swf filename and other<br>
* parameters.<br>
* In order to use this class in your jsps,import this class and<br>
* call the appropriate method directly as follows:<br>
* FusionChartsCreator.createChart(...);<br>
*
* @author InfoSoft Global (P) Ltd.
*/
public class FusionChartsCreator {
/**
* Adds additional string to the url to and encodes the parameters,<br>
* so as to disable caching of data.<br>
* @param strDataURL -
* dataURL to be fed to chart
* @param addNoCacheStr -
* Whether to add aditional string to URL to disable
* caching of data
* @return cachedURL - URL with the additional string added
*/
public static String addCacheToDataURL(String strDataURL) {
String cachedURL = strDataURL;
// Add the no-cache string if required
// We add ?FCCurrTime=xxyyzz
// If the dataURL already contains a ?, we add &FCCurrTime=xxyyzz
// We replace : with _, as FusionCharts cannot handle : in URLs
Calendar nowCal = Calendar.getInstance();
Date now = nowCal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH_mm_ss a");
String strNow = sdf.format(now);
try {
if (strDataURL.indexOf("?") > 0) {
cachedURL = strDataURL + "&FCCurrTime="
+ URLEncoder.encode(strNow, "UTF-8");
} else {
cachedURL = strDataURL + "?FCCurrTime="
+ URLEncoder.encode(strNow, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
cachedURL = strDataURL + "?FCCurrTime=" + strNow;
}
return cachedURL;
}
/**
* Creates the JavaScript + HTML code required to embed a chart.<br>
* Uses the javascript FusionCharts class to create the chart by supplying <br>
* the required parameters to it.<br>
* Note: Only one of the parameters strURL or strXML has to be not null for this<br>
* method to work. If both the parameters are provided then strURL is used for further processing.<br>
*
* @param chartSWF -
* SWF File Name (and Path) of the chart which you intend
* to plot
* @param strURL -
* If you intend to use dataURL method for this chart,
* pass the URL as this parameter. Else, set it to "" (in
* case of dataXML method)
* @param strXML -
* If you intend to use dataXML method for this chart,
* pass the XML data as this parameter. Else, set it to ""
* (in case of dataURL method)
* @param chartId -
* Id for the chart, using which it will be recognized in
* the HTML page. Each chart on the page needs to have a
* unique Id.
* @param chartWidth -
* Intended width for the chart (in pixels)
* @param chartHeight -
* Intended height for the chart (in pixels)
* @param debugMode -
* Whether to start the chart in debug mode
* @param registerWithJS -
* Whether to ask chart to register itself with
* JavaScript
*/
public static String createChart(String chartSWF, String strURL,
String strXML, String chartId, int chartWidth, int chartHeight,
boolean debugMode, boolean registerWithJS) {
StringBuffer strBuf = new StringBuffer();
// First we create a new DIV for each chart. We specify the name of DIV
// as "chartId"Div.
// DIV names are case-sensitive.
strBuf.append("\t\t<!-- START Script Block for Chart-->\n");
strBuf.append("\t\t<div id='" + chartId + "Div' align='center'>\n");
strBuf.append("\t\t\t\tChart.\n");
/*
* The above text "Chart" is shown to users before the chart has started
* loading (if there is a lag in relaying SWF from server). This text is
* also shown to users who do not have Flash Player installed. You can
* configure it as per your needs.
*/
strBuf.append("\t\t</div>\n");
/*
* Now, we create the chart using FusionCharts js class. Each chart's
* instance (JavaScript) Id is named as chart_"chartId".
*/
strBuf.append("\t\t<script type='text/javascript'>\n");
// Instantiate the Chart
Boolean registerWithJSBool = new Boolean(registerWithJS);
Boolean debugModeBool = new Boolean(debugMode);
int regWithJSInt = boolToNum(registerWithJSBool);
int debugModeInt = boolToNum(debugModeBool);
strBuf.append("\t\t\t\tvar chart_" + chartId + " = new FusionCharts('"
+ chartSWF + "', '" + chartId + "', '" + chartWidth + "', '"
+ chartHeight + "', '" + debugModeInt + "', '" + regWithJSInt
+ "');\n");
// Check whether we've to provide data using dataXML method or dataURL
// method
if (strXML.equals("")) {
strBuf.append("\t\t\t\t// Set the dataURL of the chart\n");
strBuf.append("\t\t\t\tchart_" + chartId + ".setDataURL(\"" + strURL
+ "\");\n");
} else {
strBuf.append("\t\t\t\t// Provide entire XML data using dataXML method\n");
strBuf.append("\t\t\t\tchart_" + chartId + ".setDataXML(\"" + strXML
+ "\");\n");
}
strBuf.append("\t\t\t\t// Finally, render the chart.\n");
strBuf.append("\t\t\t\tchart_" + chartId + ".render(\"" + chartId + "Div\");\n");
strBuf.append("\t\t</script>\n");
strBuf.append("\t\t<!--END Script Block for Chart-->\n");
return strBuf.substring(0);
}
/**
* Creates the object tag required to embed a chart.
* Generates the object tag to embed the swf directly into the html page.<br>
* Note: Only one of the parameters strURL or strXML has to be not null for this<br>
* method to work. If both the parameters are provided then strURL is used for further processing.<br>
*
* @param chartSWF -
* SWF File Name (and Path) of the chart which you intend
* to plot
* @param strURL -
* If you intend to use dataURL method for this chart,
* pass the URL as this parameter. Else, set it to "" (in
* case of dataXML method)
* @param strXML -
* If you intend to use dataXML method for this chart,
* pass the XML data as this parameter. Else, set it to ""
* (in case of dataURL method)
* @param chartId -
* Id for the chart, using which it will be recognized in
* the HTML page. Each chart on the page needs to have a
* unique Id.
* @param chartWidth -
* Intended width for the chart (in pixels)
* @param chartHeight -
* Intended height for the chart (in pixels)
* @param debugMode -
* Whether to start the chart in debug mode
*/
public static String createChartHTML(String chartSWF, String strURL,
String strXML, String chartId, int chartWidth, int chartHeight,
boolean debugMode) { /*
* Generate the FlashVars string based
* on whether dataURL has been provided
* or dataXML.
*/
String strFlashVars = "";
Boolean debugModeBool = new Boolean(debugMode);
if (strXML.equals("")) {
// DataURL Mode
strFlashVars = "chartWidth=" + chartWidth + "&chartHeight="
+ chartHeight + "&debugMode=" + boolToNum(debugModeBool)
+ "&dataURL=" + strURL + "";
} else {
// DataXML Mode
strFlashVars = "chartWidth=" + chartWidth + "&chartHeight="
+ chartHeight + "&debugMode=" + boolToNum(debugModeBool)
+ "&dataXML=" + strXML + "";
}
StringBuffer strBuf = new StringBuffer();
strBuf.append("\t\t<!--START Code Block for Chart-->\n");
strBuf
.append("\t\t<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"
+ chartWidth
+ "' height='"
+ chartHeight
+ "' id='"
+ chartId + "'>\n");
strBuf.append("\t\t\t\t<param name='allowScriptAccess' value='always' />\n");
strBuf.append("\t\t\t\t<param name='movie' value='" + chartSWF + "'/>\n");
strBuf.append("\t\t\t\t<param name='FlashVars' value=\"" + strFlashVars
+ "\" />\n");
strBuf.append("\t\t\t\t<param name='quality' value='high' />\n");
//防止flash遮盖Dhtml需要设置wmode为Opaque,若其他浏览器需要在embed标签中添加此属性
strBuf.append("\t\t\t\t<param name='wmode' value='Opaque' />\n");
strBuf
.append("\t\t\t\t<embed src='"
+ chartSWF
+ "' FlashVars=\""
+ strFlashVars
+ "\" quality='high' width='"
+ chartWidth
+ "' height='"
+ chartHeight
+ "' name='"
+ chartId
+ "' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />\n");
strBuf.append("\t\t</object>\n");
strBuf.append("\t\t<!--END Code Block for Chart-->\n");
return strBuf.substring(0);
}
/**
* Converts a Boolean value to int value<br>
*
* @param bool Boolean value which needs to be converted to int value
* @return int value correspoding to the boolean : 1 for true and 0 for false
*/
public static int boolToNum(Boolean bool) {
int num = 0;
if (bool.booleanValue()) {
num = 1;
}
return num;
}
}
分享到:
相关推荐
[工具类] 成各种密码随机串,加密解密,编码解码,执行url.java [工具类] 读取、打印输出、保存xml .java ...[工具类] Java中计算任意两个日期之间的工作天数 .java [工具类] java抓取网页 .java [工具类] MD5 .java
本篇将详细介绍如何在JSP中应用工具类,特别是名为"functionUtils"的工具类,以及它如何帮助我们实现查询等功能。 1. 创建工具类 首先,我们需要创建一个名为`FunctionUtils.java`的Java类。这个类通常位于项目的`...
在这个"JSP参数接收工具类.rar"压缩包中,包含了两个重要的文件:"JSP参数接收工具类(ParamUtils.txt)"和"类加载工具.txt"。这些文件很可能是为了帮助开发者更方便地管理和处理JSP页面传入的请求参数,以及理解类...
[工具类] Java中计算任意两个日期之间的工作天数 .java.txt [工具类] java抓取网页 .java.txt [工具类] MD5 .java.txt [工具类] MD5强化版 .java.txt [工具类] MD5超强化版 .java.txt [工具类] XML 实用工具类 .java...
5. **在JSP中集成FusionChart**:在JSP页面中,首先引入FusionCharts的JavaScript库。然后,创建一个`<div>`元素作为图表的容器,并定义一个JavaScript函数来加载图表。这个函数通常会使用Ajax请求Servlet获取数据,...
[工具类] Java中计算任意两个日期之间的工作天数 .java.txt [工具类] java抓取网页 .java.txt [工具类] MD5 .java.txt [工具类] MD5强化版 .java.txt [工具类] MD5超强化版 .java.txt [工具类] XML 实用工具类 .java...
2.[工具类] Java中计算任意两个日期之间的工作天数 .java 3.[工具类] MD5 .java 4.[工具类] 时间工具TimeUtil.java 5.[工具类] 通信服务端simpleServer 6.[工具类] 使用Java程序来实现HTTP文件的队列下载 .java 7....
本工具类专为这个目的设计,能够帮助开发者方便地在JSP页面中生成二维码并实现扫描后自动跳转到指定的URL。 首先,我们需要了解二维码(Quick Response Code)的基本概念。二维码是一种二维条码,可以存储比传统一...
### Java分页工具类及其在Struts、Spring、MyBatis和JSP中的应用 #### 一、Java分页概述 在开发Web应用程序时,为了提高用户体验并减轻服务器压力,通常会采用分页技术来展示大量的数据记录。本文将详细介绍一个...
下载使用tomcat就可以使用,数据库语句也有,如果要修改数据库配置就在tool下面的工具类修改即可大学本科JSP课程的期末作业JSP+Servlet+layui实现的博客系统源码。教程 下载使用tomcat就可以使用,数据库语句也有,...
它们可以帮助开发者更好地理解和操作JSP,提高开发效率,同时提供了一种可能的“jspshell”工具,使开发者能够在命令行环境中方便地管理和调试JSP应用。而“job.jsp”文件则提供了实际应用的参考,有助于学习和实践...
在本文中,作者分享了一个用于JSP和Servlet环境下的验证码工具类。这个工具类被命名为VeriyCodeUtils,它能够生成图形验证码,并且提供了将生成的验证码保存到输出流中的功能。这个工具类的实现涉及到Java图形编程...
主要介绍了Jsp的开发工具类,具体介绍了jsp中的myeclispe的用法还有一些界面的介绍,属于基础类介绍。
转换过程中,工具可能会把HTML中的数据绑定语句替换为JSP的EL(Expression Language)表达式或JSTL(JavaServer Pages Standard Tag Library)标签,这样就可以在服务器端运行这些表达式来获取或设置数据。...
Echarts在JSP中的使用配置手册 Echarts是一款基于JavaScript的数据可视化库,它提供了各种图表和组件,能够帮助开发者快速构建数据可视化应用。在JSP中使用Echarts需要进行一些配置和集成,本文将详细介绍如何在JSP...
由MIT提供的js美化大师,可对jsp、html,js等进行格式化,比其他格式化工具效果都好。该工具为web应用,解压后打开index.html,将源码复制到格式化区域,点击ctrl+Enter,即可完成格式化。
这些工具类极大地简化了JSP开发中的常见任务,提高了代码的可读性和可维护性。 对于初学者而言,理解并使用这些jar包是学习JSP开发的关键步骤。例如,通过引入Apache Commons Lang的jar包,可以使用其提供的字符串...
在Java编程环境中,读取Excel文件并将其内容在JSP(Java Server Pages)页面上以表格形式展示是一项常见的任务,特别是在处理数据导入、导出或数据可视化时。本篇文章将详细讲解如何实现这一功能,包括读取Excel文件...
2. **灵活性**:分页配置(如每页记录数)可能硬编码在工具类中,缺乏动态配置的能力。 3. **国际化与响应式**:分页标签可能没有考虑到多语言环境和不同设备的适配,如手机和平板的屏幕尺寸差异。 4. **安全考虑**...
在在线管理工具中,此类文件的编辑至关重要,因为它直接影响到用户界面的友好性和功能性。 5. **gpl.txt** 此文件可能是GNU General Public License(GPL)的文本,表明项目遵循开源许可,允许自由使用、修改和...