Skip to content

Commit 1ead1bf

Browse files
committed
init
1 parent 0afe016 commit 1ead1bf

File tree

241 files changed

+5129
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+5129
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.class
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import javax.crypto.Cipher;
2+
import javax.crypto.KeyGenerator;
3+
import javax.crypto.SecretKey;
4+
5+
public class DESEncrypt {
6+
public static void main(String args[])
7+
{
8+
String codeStringBegin="Sunny Liu"; //要加密的明文
9+
String codeStringEnd=null; //加密后的密文
10+
String decodeString=null; //密文解密后得到的明文
11+
String cipherType = "DESede"; //加密算法类型,可设置为DES、DESede、AES等字符串
12+
int keyLength = 112; //设置密钥长度
13+
try
14+
{
15+
//获取密钥生成器
16+
KeyGenerator keyGen=KeyGenerator.getInstance(cipherType);
17+
//初始化密钥生成器,不同的加密算法其密钥长度可能不同
18+
keyGen.init(keyLength);
19+
//生成密钥
20+
SecretKey key=keyGen.generateKey();
21+
22+
//得到密钥字节码
23+
byte[] keyByte=key.getEncoded();
24+
//输出密钥的字节码
25+
System.out.println("密钥是:");
26+
for(int i=0;i<keyByte.length;i++)
27+
{
28+
System.out.print(keyByte[i]+",");
29+
}
30+
System.out.println("");
31+
//创建密码器
32+
Cipher cp=Cipher.getInstance(cipherType);
33+
//初始化密码器
34+
cp.init(Cipher.ENCRYPT_MODE,key);
35+
System.out.println("要加密的字符串是:"+ codeStringBegin);
36+
byte[] codeStringByte=codeStringBegin.getBytes("UTF8");
37+
System.out.println("要加密的字符串对应的字节码是:");
38+
for(int i=0;i<codeStringByte.length;i++)
39+
{
40+
System.out.print(codeStringByte[i]+",");
41+
}
42+
System.out.println("");
43+
//开始加密
44+
byte[] codeStringByteEnd=cp.doFinal(codeStringByte);
45+
System.out.println("加密后的字符串对应的字节码是:");
46+
for(int i=0;i<codeStringByteEnd.length;i++)
47+
{
48+
System.out.print(codeStringByteEnd[i]+",");
49+
}
50+
System.out.println("");
51+
codeStringEnd=new String(codeStringByteEnd);
52+
System.out.println("加密后的字符串是:" + codeStringEnd);
53+
System.out.println("");
54+
//重新初始化密码器
55+
cp.init(Cipher.DECRYPT_MODE,key);
56+
//开始解密
57+
byte[] decodeStringByteEnd=cp.doFinal(codeStringByteEnd);
58+
System.out.println("解密后的字符串对应的字节码是:");
59+
for(int i=0;i<decodeStringByteEnd.length;i++)
60+
{
61+
System.out.print(decodeStringByteEnd[i]+",");
62+
}
63+
System.out.println("");
64+
decodeString=new String(decodeStringByteEnd);
65+
System.out.println("解密后的字符串是:" + decodeString);
66+
System.out.println("");
67+
}
68+
catch(Exception e)
69+
{
70+
e.printStackTrace();
71+
}
72+
}
73+
}
74+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Client
2+
{
3+
public static void main(String args[])
4+
{
5+
try
6+
{
7+
TV tv;
8+
String brandName=XMLUtilTV.getBrandName();
9+
tv=TVFactory.produceTV(brandName);
10+
tv.play();
11+
}
12+
catch(Exception e)
13+
{
14+
System.out.println(e.getMessage());
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class HaierTV implements TV
2+
{
3+
public void play()
4+
{
5+
System.out.println("º£¶ûµçÊÓ»ú²¥·ÅÖÐ......");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class HisenseTV implements TV
2+
{
3+
public void play()
4+
{
5+
System.out.println("º£ÐŵçÊÓ»ú²¥·ÅÖÐ......");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface TV
2+
{
3+
public void play();
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class TVFactory
2+
{
3+
public static TV produceTV(String brand) throws Exception
4+
{
5+
if(brand.equalsIgnoreCase("Haier"))
6+
{
7+
System.out.println("电视机工厂生产海尔电视机!");
8+
return new HaierTV();
9+
}
10+
else if(brand.equalsIgnoreCase("Hisense"))
11+
{
12+
System.out.println("电视机工厂生产海信电视机!");
13+
return new HisenseTV();
14+
}
15+
else
16+
{
17+
throw new Exception("对不起,暂不能生产该品牌电视机!");
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import javax.xml.parsers.*;
2+
import org.w3c.dom.*;
3+
import org.xml.sax.SAXException;
4+
import java.io.*;
5+
public class XMLUtilTV
6+
{
7+
//该方法用于从XML配置文件中提取品牌名称,并返回该品牌名称
8+
public static String getBrandName()
9+
{
10+
try
11+
{
12+
//创建文档对象
13+
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
14+
DocumentBuilder builder = dFactory.newDocumentBuilder();
15+
Document doc;
16+
doc = builder.parse(new File("configTV.xml"));
17+
18+
//获取包含品牌名称的文本节点
19+
NodeList nl = doc.getElementsByTagName("brandName");
20+
Node classNode=nl.item(0).getFirstChild();
21+
String brandName=classNode.getNodeValue().trim();
22+
return brandName;
23+
}
24+
catch(Exception e)
25+
{
26+
e.printStackTrace();
27+
return null;
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<brandName>TCL</brandName>
4+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Administrator extends User
2+
{
3+
public Administrator()
4+
{
5+
System.out.println("创建管理员对象!");
6+
}
7+
8+
public void diffOperation()
9+
{
10+
System.out.println("管理员拥有创建和管理假条权限!");
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Client
2+
{
3+
public static void main(String args[])
4+
{
5+
try
6+
{
7+
User user;
8+
UserDAO userDao=new UserDAO();
9+
int permission=userDao.findPermission("zhangsan","123456");
10+
user=UserFactory.getUser(permission);
11+
user.sameOperation();
12+
user.diffOperation();
13+
}
14+
catch(Exception e)
15+
{
16+
System.out.println(e.getMessage());
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Employee extends User
2+
{
3+
public Employee()
4+
{
5+
System.out.println("创建员工对象!");
6+
}
7+
8+
public void diffOperation()
9+
{
10+
System.out.println("员工拥有创建假条权限!");
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Manager extends User
2+
{
3+
public Manager()
4+
{
5+
System.out.println("创建经理对象!");
6+
}
7+
8+
public void diffOperation()
9+
{
10+
System.out.println("经理拥有创建和审批假条权限!");
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public abstract class User
2+
{
3+
public void sameOperation()
4+
{
5+
System.out.println("Ð޸ĸöÈË×ÊÁÏ£¡");
6+
}
7+
8+
public abstract void diffOperation();
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class UserDAO
2+
{
3+
public int findPermission(String userName,String userPassword)
4+
{
5+
if("zhangsan"==userName&&"123456"==userPassword)
6+
{
7+
return 2;
8+
}
9+
else
10+
{
11+
return -1;
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class UserFactory
2+
{
3+
public static User getUser(int permission)
4+
{
5+
if(0==permission)
6+
{
7+
return new Employee();
8+
}
9+
else if(1==permission)
10+
{
11+
return new Manager();
12+
}
13+
else if(2==permission)
14+
{
15+
return new Administrator();
16+
}
17+
else
18+
{
19+
return null;
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Client
2+
{
3+
public static void main(String args[])
4+
{
5+
try
6+
{
7+
TV tv;
8+
TVFactory factory;
9+
factory=(TVFactory)XMLUtil.getBean();
10+
tv=factory.produceTV();
11+
tv.play();
12+
}
13+
catch(Exception e)
14+
{
15+
System.out.println(e.getMessage());
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class HaierTV implements TV
2+
{
3+
public void play()
4+
{
5+
System.out.println("º£¶ûµçÊÓ»ú²¥·ÅÖÐ......");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class HaierTVFactory implements TVFactory
2+
{
3+
public TV produceTV()
4+
{
5+
System.out.println("海尔电视机工厂生产海尔电视机。");
6+
return new HaierTV();
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class HisenseTV implements TV
2+
{
3+
public void play()
4+
{
5+
System.out.println("º£ÐŵçÊÓ»ú²¥·ÅÖÐ......");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class HisenseTVFactory implements TVFactory
2+
{
3+
public TV produceTV()
4+
{
5+
System.out.println("海信电视机工厂生产海信电视机。");
6+
return new HisenseTV();
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface TV
2+
{
3+
public void play();
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface TVFactory
2+
{
3+
public TV produceTV();
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import javax.xml.parsers.*;
2+
import org.w3c.dom.*;
3+
import org.xml.sax.SAXException;
4+
import java.io.*;
5+
public class XMLUtil
6+
{
7+
//该方法用于从XML配置文件中提取具体类类名,并返回一个实例对象
8+
public static Object getBean()
9+
{
10+
try
11+
{
12+
//创建文档对象
13+
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
14+
DocumentBuilder builder = dFactory.newDocumentBuilder();
15+
Document doc;
16+
doc = builder.parse(new File("config.xml"));
17+
18+
//获取包含类名的文本节点
19+
NodeList nl = doc.getElementsByTagName("className");
20+
Node classNode=nl.item(0).getFirstChild();
21+
String cName=classNode.getNodeValue();
22+
23+
//通过类名生成实例对象并将其返回
24+
Class c=Class.forName(cName);
25+
Object obj=c.newInstance();
26+
return obj;
27+
}
28+
catch(Exception e)
29+
{
30+
e.printStackTrace();
31+
return null;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)