博客首页
注册
建议与交流
排行榜
加入友情链接
推荐
投诉
搜索:
帮助
J.Y.N
NAN
nan.cublog.cn
管理博客
发表文章
留言
收藏夹
博客圈
音乐
相册
文章
首页
关于作者
||
<<
>>
||
我的分类
最新文章
·
我写的一段程序,内嵌一个..
·
这些是我经常使用的一些..
·
使用 commons-configurat..
·
程序嵌入Tomcat服务器
·
使用Java Service Wrappe..
最新留言
·
weishuwei
看到你的那个tomcat管理器..
最新评论
·
谢谢了!我的邮箱jangyuan..
·
真的是个不错的程序哦,花..
·
好东西啊
·
请给我一个源程序看看吧。..
·
cxd
最新收藏
·
达子
统计信息
·
总访问量:12373
·
文章个数:10
·
评论条数:7
·
留言条数:1
·
网友推荐:
我写的一段程序,内嵌一个WEB服务器,提供在线升级功能.需要的可以提供源码
<DIV> <DIV align=center> </DIV>前一段时间写的一个系统给用户,用户总是说Tomcat的Dos框很难看,而且容易关掉,并且不能很明白的看到运行的日志,所以看仿别人的样子写了这样的一个程序,需要的可以试用一下,如查需要源码,可以发邮件给我.</DIV> <DIV> </DIV> <DIV>图:<IMG src="http://www.cublog.cn/u/1677/upfile/060314093755.jpg" onload="javascript:if(this.width>500)this.width=500;" border=0></DIV> <DIV> </DIV> <DIV> <DIV align=center><IMG src="http://www.cublog.cn/u/1677/upf……
查看全文
发表于:2006-03-14 ┆
阅读(631)
┆
评论(5)
这些是我经常使用的一些Java代码查询网站,希望在这里能起到抛砖引玉的效果,大家群策群力,一起分享
<DIV> 这些是我经常使用的一些Java代码查询网站,希望在这里能起到抛砖引玉的效果,大家群策群力,一起分享Java快乐。 <DIV> </DIV> <DIV> 1. java2s <A href="http://www.java2s.com/"><FONT color=#0000ff>http://www.java2s.com/</FONT></A></DIV> <DIV> 这个网站非常好,分成三大类,分别是<FONT color=#0000ff size=2><A href="http://www.java2s.com/">Example</A></FONT>、<FONT size=2><A href="http://www.java2s.com/Product/CatalogProduct.htm"><FONT color=#003399>Pro……
查看全文
发表于:2006-01-12 ┆
阅读(549)
┆
评论(0)
使用 commons-configuration 读配置文件
<DIV> XMLConfiguration config = new XMLConfiguration(configFile);</DIV> <DIV> String port = config.getString("server.port");</DIV> <DIV> </DIV> <DIV> 文件内容:</DIV> <DIV> </DIV> <DIV> </DIV> <DIV> <?xml version="1.0" encoding="UTF-8"?><BR><xml-body></DIV> <DIV> <server><BR> <port>990</port><BR> <securePort>0</securePort><BR> <domain&g……
查看全文
发表于:2006-01-12 ┆
阅读(639)
┆
评论(0)
程序嵌入Tomcat服务器
<DIV> </DIV> <DIV>import org.apache.commons.logging.Log;<BR>import org.apache.commons.logging.LogFactory;<BR>import org.apache.catalina.Connector;<BR>import org.apache.catalina.Context;<BR>import org.apache.catalina.Engine;<BR>import org.apache.catalina.Host;<BR>import org.apache.catalina.LifecycleException;<BR>import org.apache.catalina.Logger;<BR>import org.apache.catalina.logger.FileLogger;<BR>import org.apache.catalina.startup.Embedded;<BR>import org.yak.util.YAKGlobals;</DIV> <DIV>im……
查看全文
发表于:2006-01-12 ┆
阅读(708)
┆
评论(0)
使用Java Service Wrapper 把Java程序作为Windows系统服务
查看全文
发表于:2006-01-11 ┆
阅读(1280)
┆
评论(1)
Struts Hack!解决中文参数在Form Bean中的乱码问题!
<DIV>一句话...Struts的Action Servlet存在缺陷...用继承吧... <PRE class=CodeFormat><DIV><SPAN style="COLOR: rgb(0,0,255)">package</SPAN><SPAN style="COLOR: rgb(0,0,0)"> net.csdn.blog.xport.struts;……
查看全文
发表于:2006-01-10 ┆
阅读(649)
┆
评论(1)
使用TrueLicense来保护我们的JAVA软件产品
<DIV> <H1><A name=%E4%BD%BF%E7%94%A8TrueLicense%E6%9D%A5%E4%BF%9D%E6%8A%A4%E6%88%91%E4%BB%AC%E7%9A%84JAVA%E8%BD%AF%E4%BB%B6%E4%BA%A7%E5%93%81-%E4%BD%BF%E7%94%A8TrueLicense%E6%9D%A5%E4%BF%9D%E6%8A%A4%E6%88%91%E4%BB%AC%E7%9A%84JAVA%E8%BD%AF%E4%BB%B6%E4%BA%A7%E5%93%81>使用TrueLicense来保护我们的JAVA软件产品</A></H1> <P>也可以查看我的wiki:http://sms.i6688.com/pages/viewpage.action?pageId=25</P> <P>我们的JAVA软件产品有时需要限制非法用户,只有购买了LICENSE的用户才能使用,因此,我们可以通过TrueLicense来实现。</P> <P>首先要用KeyTool工具来生成私匙库:</P> <DIV class=code> <DIV class=codeContent><PRE class=code-java>keytool -genkey -alias privatekey -keystore privateKeys.store</PRE></DIV></DIV> <P>然后把私匙库内的公匙导出到一个文件当中:</P> <DIV class=code> <DIV class=codeContent><PRE class=code-java>keytool -export -alias privatekey -file certfile.cer -keystore privateKeys.store</PRE></DIV></DIV> <P>然后再把这个证书文件导入到公匙库:</P> <DIV class=code> <DIV class=codeContent><PRE class=code-java>keytool -<SPAN class=code-keyword>import</SPAN> -alias publiccert -file certfile.cer -keystore publicCerts.store</PRE></DIV></DIV> <H3><A name=%E4%BD%BF%E7%94%A8TrueLicense%E6%9D%A5%E4%BF%9D%E6%8A%A4%E6%88%91%E4%BB%AC%E7%9A%84JAVA%E8%BD%AF%E4%BB%B6%E4%BA%A7%E5%93%81-%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF%E5%88%A9%E7%94%A8%E7%A7%81%E5%8C%99%E5%BA%93%E6%9D%A5%E5%88%9B%E5%BB%BAlicense%E7%9A%84%E4%BB%A3%E7%A0%81%E4%BE%8B%E5%AD%90%EF%BC%9A>服务器端利用私匙库来创建license的代码例子:</A></H3> <DIV class=code> <DIV class=codeContent><PRE class=code-java><SPAN class=code-keyword>package</SPAN> com.sourceware.license; <SPAN class=code-keyword>import</SPAN> de.schlichtherle.license.*; <SPAN class=code-keyword>import</SPAN> java.io.*; <SPAN class=code-keyword>import</SPAN> java.util.*; <SPAN class=code-keyword>import</SPAN> javax.security.auth.x500.X500Principal; <SPAN class=code-keyword>import</SPAN> java.util.prefs.Preferences; /** * <p>Title: CMVP通用媒体增值业务平台</p> * * <p>Description: CMVP通用媒体增值业务平台</p> * * <p>Copyright: Copyright (c) 2005</p> * * <p>Company: source-ware.com inc.</p> * * @author 黑山 * @version 2.0 */ <SPAN class=code-keyword>public</SPAN> class SWLicenseManager { <SPAN class=code-keyword>public</SPAN> SWLicenseManager() { } LicenseContent verifyLicenseKey(LicenseParam parameter) { <SPAN class=code-comment>// Create a configured license manager. </SPAN> LicenseManager manager = <SPAN class=code-keyword>new</SPAN> LicenseManager(parameter); <SPAN class=code-keyword>try</SPAN> { <SPAN class=code-comment>// Verify the previously installed current license certificate. </SPAN> <SPAN class=code-keyword>return</SPAN> manager.verify(); } <SPAN class=code-keyword>catch</SPAN> (Exception exc) { <SPAN class=code-object>System</SPAN>.err.println(<SPAN class=code-quote>"Could not verify license key"</SPAN>); exc.printStackTrace(); <SPAN class=code-keyword>return</SPAN> <SPAN class=code-keyword>null</SPAN>; } } void installLicenseKey(LicenseParam parameter, File keyFile) { <SPAN class=code-comment>// Create a configured license manager. </SPAN> LicenseManager manager = <SPAN class=code-keyword>new</SPAN> LicenseManager(parameter); <SPAN class=code-keyword>try</SPAN> { <SPAN class=code-comment>// Load the license key, verify and install it as the current license key. </SPAN> manager.install(keyFile); } <SPAN class=code-keyword>catch</SPAN> (Exception exc) { <SPAN class=code-object>System</SPAN>.err.println(<SPAN class=code-quote>"Could not install license certificate"</SPAN>); exc.printStackTrace(); } } void createLicenseKey(LicenseParam parameter, LicenseContent content) { <SPAN class=code-comment>// Create a configured license manager. </SPAN> LicenseManager manager = <SPAN class=code-keyword>new</SPAN> LicenseManager(parameter); <SPAN class=code-keyword>try</SPAN> { <SPAN class=code-comment>// Create the license key from the license content and save it to a file. </SPAN> manager.store(content, <SPAN class=code-keyword>new</SPAN> File(<SPAN class=code-quote>"license.lic"</SPAN>)); } <SPAN class=code-keyword>catch</SPAN> (Exception exc) { <SPAN class=code-object>System</SPAN>.err.println(<SPAN class=code-quote>"Could not save license key"</SPAN>); exc.printStackTrace(); } } <SPAN class=code-comment>// </SPAN> <SPAN class=code-comment>// Customizable global properties. </SPAN> <SPAN class=code-comment>// </SPAN> /** The product id of your software */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> PRODUCT_ID = <SPAN class=code-quote>"cmvp20"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** * The subject <SPAN class=code-keyword>for</SPAN> the license manager and also the alias of the <SPAN class=code-keyword>private</SPAN> * key entry in the keystore. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> SUBJECT = <SPAN class=code-quote>"别名"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** The resource name of your <SPAN class=code-keyword>private</SPAN> keystore file. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> KEYSTORE_RESOURCE = <SPAN class=code-quote>"私匙库文件名"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** The password <SPAN class=code-keyword>for</SPAN> the keystore. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> KEYSTORE_STORE_PWD = <SPAN class=code-quote>"私匙库密码"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /* The password <SPAN class=code-keyword>for</SPAN> the <SPAN class=code-keyword>private</SPAN> key entry in the keystore. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> KEYSTORE_KEY_PWD = <SPAN class=code-quote>"私匙库主键密码"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** The password to encrypt the generated license key file. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> CIPHER_KEY_PWD = <SPAN class=code-quote>"即将生成的license密码"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** * The filename to be displayed <SPAN class=code-keyword>for</SPAN> the generated binary key file when * delivered. Please note that <SPAN class=code-keyword>this</SPAN> is not used to write to a file of * <SPAN class=code-keyword>this</SPAN> name. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> DISPLAY_FILENAME = <SPAN class=code-quote>"license.lic"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> <SPAN class=code-comment>// </SPAN> <SPAN class=code-comment>// The <SPAN class=code-keyword>rest</SPAN> of <SPAN class=code-keyword>this</SPAN> key generator does not need to get customized. </SPAN> <SPAN class=code-comment>// </SPAN> /** The MIME type of the generated binary key file. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> MIME_TYPE = <SPAN class=code-quote>"application/octet-stream"</SPAN>; <SPAN class=code-comment>// </SPAN> <SPAN class=code-comment>// Possible key generator exit codes </SPAN> <SPAN class=code-comment>// </SPAN> /** * Return <code>ERC_SUCCESS</code> on succesful creation of a textual key. * Note that <SPAN class=code-keyword>this</SPAN> example creates a binary key and thus <SPAN class=code-keyword>this</SPAN> constant is not * used here */ <SPAN class=code-comment>//<SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_SUCCESS = 00; </SPAN> /** * Return <code>ERC_SUCCESS_BIN</code> on succesful creation of a binary * key. (Which could contain text as well, <SPAN class=code-keyword>if</SPAN> the content type is specified * as <code>text/plain</code>) */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_SUCCESS_BIN = 01; /** * Return <code>ERC_ERROR</code> <SPAN class=code-keyword>for</SPAN> general errors. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_ERROR = 10; /** * Return <code>ERC_MEMORY</code> <SPAN class=code-keyword>if</SPAN> memory allocation fails. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_MEMORY = 11; /** * Return <code>ERC_FILE_IO</code> on IOException */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_FILE_IO = 12; /** * Return <code>ERC_BAD_ARGS</code> <SPAN class=code-keyword>if</SPAN> the command line parameters are * bad. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_BAD_ARGS = 13; /** * Return <code>ERC_BAD_INPUT</code> <SPAN class=code-keyword>if</SPAN> a particular input value is * missing or has a bad value. Don't forget to supply a meaningful error * message naming the exact cause of the error. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_BAD_INPUT = 14; /** * Return <code>ERC_EXPIRED</code> <SPAN class=code-keyword>if</SPAN> <SPAN class=code-keyword>this</SPAN> generator is expired. This can * be used to limit the lifetime of <SPAN class=code-keyword>this</SPAN> generator. */ <SPAN class=code-comment>//<SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_EXPIRED = 15; </SPAN> /** * Return <code>ERC_INTERNAL</code> <SPAN class=code-keyword>if</SPAN> an unhandled exception occurs. * * @see java.lang.Exception */ <SPAN class=code-comment>//<SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>int</SPAN> ERC_INTERNAL = 16; </SPAN> /** Encoding keys in properties. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> ENCODING_KEY = <SPAN class=code-quote>"ENCODING"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> PRODUCT_ID_KEY = <SPAN class=code-quote>"PRODUCT_ID"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> PURCHASE_ID_KEY = <SPAN class=code-quote>"PURCHASE_ID"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> RUNNING_NO_KEY = <SPAN class=code-quote>"RUNNING_NO"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> PURCHASE_DATE_KEY = <SPAN class=code-quote>"PURCHASE_DATE"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> LANGUAGE_ID_KEY = <SPAN class=code-quote>"LANGUAGE_ID"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> QUANTITY_KEY = <SPAN class=code-quote>"QUANTITY"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> REG_NAME_KEY = <SPAN class=code-quote>"REG_NAME"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> ADDITIONAL1_KEY = <SPAN class=code-quote>"ADDITIONAL1"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> ADDITIONAL2_KEY = <SPAN class=code-quote>"ADDITIONAL2"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> RESELLER_KEY = <SPAN class=code-quote>"RESELLER"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> LASTNAME_KEY = <SPAN class=code-quote>"LASTNAME"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> FIRSTNAME_KEY = <SPAN class=code-quote>"FIRSTNAME"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> COMPANY_KEY = <SPAN class=code-quote>"COMPANY"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> EMAIL_KEY = <SPAN class=code-quote>"EMAIL"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> PHONE_KEY = <SPAN class=code-quote>"PHONE"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> FAX_KEY = <SPAN class=code-quote>"FAX"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> STREET_KEY = <SPAN class=code-quote>"STREET"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> ZIP_KEY = <SPAN class=code-quote>"ZIP"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> CITY_KEY = <SPAN class=code-quote>"CITY"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> STATE_KEY = <SPAN class=code-quote>"STATE"</SPAN>; <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> COUNTRY_KEY = <SPAN class=code-quote>"COUNTRY"</SPAN>; /** Default encoding <SPAN class=code-keyword>for</SPAN> properties. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> ENCODING_PROPERTIES = <SPAN class=code-quote>"ISO-8859-1"</SPAN>; /** Default share-it encoding <SPAN class=code-keyword>if</SPAN> key not present in properties. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> ENCODING_DEFAULT = ENCODING_PROPERTIES; <SPAN class=code-keyword>protected</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> LicenseManager manager = <SPAN class=code-keyword>new</SPAN> LicenseManager( <SPAN class=code-keyword>new</SPAN> DefaultLicenseParam( SUBJECT, Preferences.userRoot(), <SPAN class=code-keyword>new</SPAN> DefaultKeyStoreParam( SWLicenseManager.class, <SPAN class=code-comment>// CUSTOMIZE </SPAN> KEYSTORE_RESOURCE, SUBJECT, KEYSTORE_STORE_PWD, KEYSTORE_KEY_PWD), <SPAN class=code-keyword>new</SPAN> DefaultCipherParam(CIPHER_KEY_PWD))); /** * Validates the properties and generates a license certificate file. */ <SPAN class=code-keyword>private</SPAN> <SPAN class=code-keyword>static</SPAN> void generateLicense(Properties props, File certFile) <SPAN class=code-keyword>throws</SPAN> Exception { <SPAN class=code-comment>// Check <SPAN class=code-keyword>for</SPAN> supported product id. </SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> productId = props.getProperty(PRODUCT_ID_KEY); <SPAN class=code-keyword>if</SPAN> (!PRODUCT_ID.equals(productId)) { <SPAN class=code-keyword>throw</SPAN> <SPAN class=code-keyword>new</SPAN> BadInputException(<SPAN class=code-quote>"Bad product ID: "</SPAN> + productId); } <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>StringBuffer</SPAN> dn = <SPAN class=code-keyword>new</SPAN> <SPAN class=code-object>StringBuffer</SPAN>(); addAttribute(dn, <SPAN class=code-quote>"CN"</SPAN>, props.getProperty(FIRSTNAME_KEY) + ' ' + props.getProperty(LASTNAME_KEY)); <SPAN class=code-keyword>if</SPAN> (dn.length() == 0) { addAttribute(dn, <SPAN class=code-quote>"CN"</SPAN>, props, REG_NAME_KEY); } addAttribute(dn, <SPAN class=code-quote>"O"</SPAN>, props, COMPANY_KEY); addAttribute(dn, <SPAN class=code-quote>"STREET"</SPAN>, props, STREET_KEY); addAttribute(dn, <SPAN class=code-quote>"L"</SPAN>, props.getProperty(ZIP_KEY) + ' ' + props.getProperty(CITY_KEY)); addAttribute(dn, <SPAN class=code-quote>"ST"</SPAN>, props, STATE_KEY); addAttribute(dn, <SPAN class=code-quote>"C"</SPAN>, props, COUNTRY_KEY); <SPAN class=code-keyword>final</SPAN> X500Principal holder = <SPAN class=code-keyword>new</SPAN> X500Principal(dn.toString()); <SPAN class=code-keyword>final</SPAN> X500Principal issuer = <SPAN class=code-keyword>new</SPAN> X500Principal( <SPAN class=code-quote>"OU=share-it!,O=element 5 AG,STREET=Vogelsanger Strasse 78,L=50823 Ku00F6ln,ST=Nordrhein-Westfalen,C=DE"</SPAN>); <SPAN class=code-keyword>final</SPAN> LicenseContent content = <SPAN class=code-keyword>new</SPAN> LicenseContent(); content.setHolder(holder); content.setIssuer(issuer); content.setConsumerType(<SPAN class=code-quote>"User"</SPAN>); content.setConsumerAmount(1); content.setInfo(props.toString()); content.setSubject(SUBJECT); java.util.Calendar cal =java.util.Calendar.getInstance(); cal.set(2006,1,1); content.setNotAfter(cal.getTime()); manager.store(content, certFile); } <SPAN class=code-keyword>private</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> void addAttribute( <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>StringBuffer</SPAN> dn, <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> oid, <SPAN class=code-keyword>final</SPAN> Properties props, <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> key) { addAttribute(dn, oid, props.getProperty(key)); } <SPAN class=code-keyword>private</SPAN> <SPAN class=code-keyword>static</SPAN> void addAttribute( <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>StringBuffer</SPAN> dn, <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> oid, <SPAN class=code-object>String</SPAN> value) { <SPAN class=code-keyword>if</SPAN> (value == <SPAN class=code-keyword>null</SPAN>) { <SPAN class=code-keyword>return</SPAN>; } <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> trimmedValue = value.trim(); <SPAN class=code-keyword>if</SPAN> ("".equals(trimmedValue)) { <SPAN class=code-keyword>return</SPAN>; } <SPAN class=code-comment>// See http://www.ietf.org/rfc/rfc2253.txt </SPAN> <SPAN class=code-object>boolean</SPAN> quote = <SPAN class=code-keyword>false</SPAN>; <SPAN class=code-keyword>if</SPAN> (!value.equals(trimmedValue)) { quote = <SPAN class=code-keyword>true</SPAN>; } <SPAN class=code-keyword>else</SPAN> <SPAN class=code-keyword>if</SPAN> (value.matches(<SPAN class=code-quote>".*[+,;<>"</SPAN>].*")) { ; } quote = <SPAN class=code-keyword>true</SPAN>; <SPAN class=code-keyword>if</SPAN> (dn.length() != 0) { dn.append(','); } dn.append(oid); dn.append('='); <SPAN class=code-keyword>if</SPAN> (quote) { dn.append('"'); } <SPAN class=code-comment>// Replace every single backslash with two backslashes </SPAN> <SPAN class=code-comment>// whereas both parameters are expressed as regular expressions. </SPAN> value = value.replaceAll(<SPAN class=code-quote>"\"</SPAN>, <SPAN class=code-quote>"\\"</SPAN>); <SPAN class=code-comment>// Replace every single quote with an escaped quote </SPAN> <SPAN class=code-comment>// whereas both parameters are expressed as regular expressions. </SPAN> value = value.replaceAll(<SPAN class=code-quote>""</SPAN><SPAN class=code-quote>", "</SPAN>\""); dn.append(value); <SPAN class=code-keyword>if</SPAN> (quote) { dn.append('"'); } } <SPAN class=code-keyword>private</SPAN> <SPAN class=code-keyword>static</SPAN> Properties readInput(<SPAN class=code-object>String</SPAN> pathname) <SPAN class=code-keyword>throws</SPAN> IOException { Properties props = <SPAN class=code-keyword>new</SPAN> EncodedProperties(); InputStream in = <SPAN class=code-keyword>new</SPAN> FileInputStream(pathname); <SPAN class=code-keyword>try</SPAN> { props.load(in); } <SPAN class=code-keyword>catch</SPAN> (IllegalArgumentException iae) { <SPAN class=code-keyword>throw</SPAN> <SPAN class=code-keyword>new</SPAN> BadInputException(iae); } <SPAN class=code-keyword>finally</SPAN> { in.close(); } <SPAN class=code-keyword>return</SPAN> props; } /** * This is the main entry point <SPAN class=code-keyword>for</SPAN> JAVA key generators. It processes the * command line arguments, loads and parses the input file, calls the key * generator and writes output files. * * JAVA Exceptions are handled and transformed into key generator error * codes. Exception messages will be written to <code>args[1]</code> and * display on the error console. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-object>int</SPAN> KeyMain(<SPAN class=code-object>String</SPAN> args[]) { args = <SPAN class=code-keyword>new</SPAN> <SPAN class=code-object>String</SPAN>[3]; args[0] = <SPAN class=code-quote>"license.properties"</SPAN>; args[1] = <SPAN class=code-quote>"license.status"</SPAN>; args[2] = <SPAN class=code-quote>"license.lic"</SPAN>; <SPAN class=code-keyword>if</SPAN> (args.length != 3) { <SPAN class=code-object>System</SPAN>.err.println(<SPAN class=code-quote>"Usage: <input> <output1> <output2>"</SPAN>); <SPAN class=code-keyword>return</SPAN> ERC_BAD_ARGS; } <SPAN class=code-object>int</SPAN> errorCode = ERC_ERROR; PrintWriter out = <SPAN class=code-keyword>new</SPAN> PrintWriter(<SPAN class=code-object>System</SPAN>.err); <SPAN class=code-keyword>try</SPAN> { <SPAN class=code-keyword>try</SPAN> { <SPAN class=code-comment>// Read input and get encoding </SPAN> <SPAN class=code-keyword>final</SPAN> Properties props = readInput(args[0]); <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> encoding = props.getProperty(ENCODING_KEY, ENCODING_DEFAULT); <SPAN class=code-comment>// Setup real output with encoding read from input file. </SPAN> out = <SPAN class=code-keyword>new</SPAN> PrintWriter( <SPAN class=code-keyword>new</SPAN> OutputStreamWriter( <SPAN class=code-keyword>new</SPAN> FileOutputStream(args[1]), encoding)); <SPAN class=code-comment>// Validate input and generate key file. </SPAN> generateLicense(props, <SPAN class=code-keyword>new</SPAN> File(args[2])); <SPAN class=code-comment>// Write status. </SPAN> out.write(MIME_TYPE + <SPAN class=code-quote>":"</SPAN> + DISPLAY_FILENAME); } <SPAN class=code-keyword>catch</SPAN> (BadInputException bie) { errorCode = ERC_BAD_INPUT; <SPAN class=code-keyword>throw</SPAN> bie; } <SPAN class=code-keyword>catch</SPAN> (IOException ioe) { errorCode = ERC_FILE_IO; <SPAN class=code-keyword>throw</SPAN> ioe; } <SPAN class=code-keyword>catch</SPAN> (OutOfMemoryError oome) { errorCode = ERC_MEMORY; <SPAN class=code-keyword>throw</SPAN> oome; } } <SPAN class=code-keyword>catch</SPAN> (Throwable t) { out.println(<SPAN class=code-quote>"Error #"</SPAN> + errorCode); t.printStackTrace(out); <SPAN class=code-keyword>return</SPAN> errorCode; } <SPAN class=code-keyword>finally</SPAN> { out.close(); } <SPAN class=code-keyword>return</SPAN> ERC_SUCCESS_BIN; } /** * NOTE: This main() method is never called by the actual key server. It is * just useful <SPAN class=code-keyword>for</SPAN> debugging the key generator. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> void main(<SPAN class=code-object>String</SPAN> args[]) { KeyMain(args); /*<SPAN class=code-keyword>try</SPAN>{ manager.install(<SPAN class=code-keyword>new</SPAN> java.io.File(<SPAN class=code-quote>"swutil.log"</SPAN>)); <SPAN class=code-object>System</SPAN>.out.println(<SPAN class=code-quote>"subject="</SPAN> + manager.verify().getSubject()); <SPAN class=code-object>System</SPAN>.exit(0); }<SPAN class=code-keyword>catch</SPAN>(Exception ex){ ex.printStackTrace(); }*/ } <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> class EncodedProperties <SPAN class=code-keyword>extends</SPAN> Properties { <SPAN class=code-keyword>public</SPAN> EncodedProperties() { <SPAN class=code-keyword>this</SPAN>(<SPAN class=code-keyword>new</SPAN> Properties()); } /** * @<SPAN class=code-keyword>throws</SPAN> NullPointerException <SPAN class=code-keyword>if</SPAN> <tt>defaults</tt> is <tt><SPAN class=code-keyword>null</SPAN></tt>. */ <SPAN class=code-keyword>public</SPAN> EncodedProperties(Properties defaults) { <SPAN class=code-keyword>super</SPAN>(defaults); <SPAN class=code-comment>// Make sure we have a proper <SPAN class=code-keyword>default</SPAN> <SPAN class=code-keyword>for</SPAN> the encoding. </SPAN> defaults.setProperty(ENCODING_KEY, ENCODING_DEFAULT); } <SPAN class=code-keyword>public</SPAN> void load(InputStream inStream) <SPAN class=code-keyword>throws</SPAN> IOException { <SPAN class=code-keyword>super</SPAN>.load(inStream); <SPAN class=code-object>String</SPAN> encoding = <SPAN class=code-keyword>super</SPAN>.getProperty(ENCODING_KEY); <SPAN class=code-keyword>if</SPAN> (ENCODING_PROPERTIES.equals(encoding)) { <SPAN class=code-keyword>return</SPAN>; } <SPAN class=code-comment>// Convert properties </SPAN> <SPAN class=code-keyword>try</SPAN> { Map.Entry[] entries = <SPAN class=code-keyword>new</SPAN> Map.Entry[entrySet().size()]; entrySet().toArray(entries); <SPAN class=code-keyword>for</SPAN> (<SPAN class=code-object>int</SPAN> i = entries.length; --i >= 0; ) { Map.Entry entry = entries[i]; <SPAN class=code-object>String</SPAN> value = (<SPAN class=code-object>String</SPAN>) entry.getValue(); value = <SPAN class=code-keyword>new</SPAN> <SPAN class=code-object>String</SPAN>(value.getBytes(ENCODING_PROPERTIES), encoding); setProperty( (<SPAN class=code-object>String</SPAN>) entry.getKey(), value); } } <SPAN class=code-keyword>catch</SPAN> (UnsupportedEncodingException ignored) {} } } <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> class BadInputException <SPAN class=code-keyword>extends</SPAN> IOException { <SPAN class=code-keyword>public</SPAN> BadInputException(<SPAN class=code-object>String</SPAN> message) { <SPAN class=code-keyword>super</SPAN>(message); } <SPAN class=code-keyword>public</SPAN> BadInputException(Throwable cause) { initCause(cause); } } }</PRE></DIV></DIV> <H3><A name=%E4%BD%BF%E7%94%A8TrueLicense%E6%9D%A5%E4%BF%9D%E6%8A%A4%E6%88%91%E4%BB%AC%E7%9A%84JAVA%E8%BD%AF%E4%BB%B6%E4%BA%A7%E5%93%81-%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%A8%8B%E5%BA%8F%E5%AE%89%E8%A3%85license%E4%BB%A5%E5%8F%8A%E6%A3%80%E9%AA%8Clicense%E5%90%88%E6%B3%95%E6%80%A7%E7%9A%84%E4%BB%A3%E7%A0%81%EF%BC%9A>客户端程序安装license以及检验license合法性的代码:</A></H3> <DIV class=information-block align=center> <DIV class=informationMacroPadding> <TABLE class=warningMacro cellSpacing=0 cellPadding=5 width="85%" border=0> <TBODY> <TR> <TD vAlign=top width=16><IMG height=16 alt="" src="http://sms.i6688.com/images/icons/emoticons/forbidden.gif" width=16 align=absMiddle border=0></TD> <TD><B class=strong>安全警告</B><BR>不要把私匙库拷贝到客户端,而只拷贝公匙库,要不然黑客就可以用你的私匙库来生成许许多多的license了</TD></TR></TBODY></TABLE></DIV></DIV> <DIV class=code> <DIV class=codeContent><PRE class=code-java><SPAN class=code-keyword>package</SPAN> com.sourceware.cmvp.license; <SPAN class=code-keyword>import</SPAN> de.schlichtherle.license.*; <SPAN class=code-keyword>import</SPAN> java.io.*; <SPAN class=code-keyword>import</SPAN> java.util.*; <SPAN class=code-keyword>import</SPAN> javax.security.auth.x500.X500Principal; <SPAN class=code-keyword>import</SPAN> java.util.prefs.Preferences; /** * <p>Title: CMVP通用媒体增值业务平台</p> * * <p>Description: CMVP通用媒体增值业务平台</p> * * <p>Copyright: Copyright (c) 2005</p> * * <p>Company: source-ware.com inc.</p> * * @author 黑山 * @version 2.0 */ <SPAN class=code-keyword>public</SPAN> class CMVPLicenseManager { <SPAN class=code-keyword>public</SPAN> CMVPLicenseManager() { } /** The product id of your software */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> PRODUCT_ID = <SPAN class=code-quote>"cmvp20"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** * The subject <SPAN class=code-keyword>for</SPAN> the license manager and also the alias of the <SPAN class=code-keyword>private</SPAN> * key entry in the keystore. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> SUBJECT = <SPAN class=code-quote>"别名"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** The resource name of your <SPAN class=code-keyword>private</SPAN> keystore file. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> KEYSTORE_RESOURCE = <SPAN class=code-quote>"公匙库文件名"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** The password <SPAN class=code-keyword>for</SPAN> the keystore. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> KEYSTORE_STORE_PWD = <SPAN class=code-quote>"公匙库密码"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> /** The password to encrypt the generated license key file. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> <SPAN class=code-object>String</SPAN> CIPHER_KEY_PWD = <SPAN class=code-quote>"license文件密码"</SPAN>; <SPAN class=code-comment>// CUSTOMIZE </SPAN> <SPAN class=code-keyword>protected</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> LicenseManager manager = <SPAN class=code-keyword>new</SPAN> LicenseManager( <SPAN class=code-keyword>new</SPAN> DefaultLicenseParam( SUBJECT, Preferences.userNodeForPackage(CMVPLicenseManager.class), <SPAN class=code-keyword>new</SPAN> DefaultKeyStoreParam( CMVPLicenseManager.class, <SPAN class=code-comment>// CUSTOMIZE </SPAN> KEYSTORE_RESOURCE, SUBJECT, KEYSTORE_STORE_PWD, <SPAN class=code-keyword>null</SPAN>),<SPAN class=code-comment>//这里一定要是null </SPAN> <SPAN class=code-keyword>new</SPAN> DefaultCipherParam(CIPHER_KEY_PWD))); /** * NOTE: This main() method is never called by the actual key server. It is * just useful <SPAN class=code-keyword>for</SPAN> debugging the key generator. */ <SPAN class=code-keyword>public</SPAN> <SPAN class=code-keyword>static</SPAN> <SPAN class=code-keyword>final</SPAN> void main(<SPAN class=code-object>String</SPAN> args[]) { <SPAN class=code-keyword>try</SPAN> { manager.install(<SPAN class=code-keyword>new</SPAN> java.io.File(<SPAN class=code-quote>"license.lic"</SPAN>)); <SPAN class=code-object>String</SPAN> subject = manager.verify().getSubject(); <SPAN class=code-object>System</SPAN>.out.println(<SPAN class=code-quote>"subject========"</SPAN>+subject); } <SPAN class=code-keyword>catch</SPAN> (Exception ex) { ex.printStackTrace(); } } }</PRE></DIV></DIV></DIV>
查看全文
发表于:2006-01-05 ┆
阅读(514)
┆
评论(0)
代码生成 Html
查看全文
发表于:2005-12-27 ┆
阅读(595)
┆
评论(0)
页面中关于 Table 增加行,列,以及删除行列的代码
<p>页面中关于 Table 增加行,列,以及删除行列的代码</p><p><center> <!-- START NETSHELTER 728x90 JAVASCRIPT AD CODE v2.1 FOR JAVA2S.COM --> <script language="javascript"><!-- d=new Date();flash=Math.round(Math.random()*d.getTime()); chk='E';document.cookie=chk+"="+chk+"; path=/";k=document.cookie.indexOf(chk+"="+chk,0)<0?0:1;cgi='http://servedby.netshelter.net'; document.write('<scr'+'ipt src="'+cgi+'/serve.cgi?pid=JAVA2S&g=1&m=9&j=1&k='+k+'&id='+flash+'&d=js"></scr'+'ipt>'); // --> </script>……
查看全文
发表于:2005-12-27 ┆
阅读(523)
┆
评论(0)
开始
希望可以在这里留下一些岁月的痕迹!
查看全文
发表于:2004-11-01 ┆
阅读(609)
┆
评论(0)