📄 itemmanager.java
字号:
package xmlMenu;
import java.util.*;
import java.io.*;
import javax.servlet.jsp.PageContext;
import javax.servlet.*;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class ItemManager {
private Vector m_vector = new Vector();
protected ServletContext m_application;
private boolean m_denyPhysicalPath;
public ItemManager()
{
}
public final void initialize(PageContext pageContext)
throws ServletException
{
m_application = pageContext.getServletContext();
}
private boolean isVirtual(String pathName) //判断是否是虚拟路径
{
if(m_application.getRealPath(pathName) != null)
{
java.io.File virtualFile = new java.io.File(m_application.getRealPath(pathName));
return virtualFile.exists();
}
else
{
return false;
}
}
private String getPhysicalPath(String filePathName, int option)
throws IOException
{
String path = new String();
String fileName = new String();
String fileSeparator = new String();
boolean isPhysical = false;
fileSeparator=System.getProperty("file.separator");
/* if(filePathName == null)
{
throw new IllegalArgumentException("There is no specified destination file (1140).");
}
if(filePathName.equals(""))
{
throw new IllegalArgumentException("There is no specified destination file (1140).");
}
//*/
if(filePathName.lastIndexOf("\\") >= 0)
{
path = filePathName.substring(0, filePathName.lastIndexOf("\\"));
fileName = filePathName.substring(filePathName.lastIndexOf("\\") + 1);
}
if(filePathName.lastIndexOf("/") >= 0)
{
path = filePathName.substring(0, filePathName.lastIndexOf("/"));
fileName = filePathName.substring(filePathName.lastIndexOf("/") + 1);
}
path = path.length() != 0 ? path : "/";
java.io.File physicalPath = new java.io.File(path);
if(physicalPath.exists())
{
isPhysical = true;
}
if(option == 0)
{
if(isVirtual(path))
{
path = m_application.getRealPath(path);
if(path.endsWith(fileSeparator))
path = path + fileName;
else
path = String.valueOf((new StringBuffer(String.valueOf(path))).append(fileSeparator).append(fileName));
return path;
}
if(isPhysical)
{
if(m_denyPhysicalPath)
throw new IllegalArgumentException("Physical path is denied (1125).");
else
return filePathName;
}
else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
if(option == 1)
{
if(isVirtual(path))
{
path = m_application.getRealPath(path);
if(path.endsWith(fileSeparator))
path = path + fileName;
else
path = String.valueOf((new StringBuffer(String.valueOf(path))).append(fileSeparator).append(fileName));
return path;
}
if(isPhysical)
throw new IllegalArgumentException("The path is not a virtual path.");
else
throw new IllegalArgumentException("This path does not exist (1135).");
}
if(option == 2)
{
if(isPhysical)
if(m_denyPhysicalPath)
throw new IllegalArgumentException("Physical path is denied (1125).");
else
return filePathName;
if(isVirtual(path))
throw new IllegalArgumentException("The path is not a physical path.");
else
throw new IllegalArgumentException("This path does not exist (1135).");
}
else
{
return null;
}
}
public void initVector()
{
try
{
String path = getPhysicalPath("",0);
String filename = path + "items.txt";
FileReader fileReader = new FileReader(filename);
BufferedReader in = new BufferedReader(fileReader);
String type, title, url, str = new String();
do{
type = in.readLine();
title = in.readLine();
url = in.readLine();
str = in.readLine();
if (type==null || title==null || url==null)
break;
item it = new item();
it.setType(type);
it.setUrl(url);
it.setTitle(title);
m_vector.addElement(it);
}while(true);
in.close();
}
catch(FileNotFoundException e)
{
System.out.println("File Not Found");
}
catch(IOException e)
{
System.out.println("End of stream");
}
}
public Vector getOneVector(String string)
{
Vector vt = new Vector();
int size = m_vector.size();
for(int i=0; i<size; i++)
{
item item1 = (item)m_vector.elementAt(i);
item item2 = new item();
if (item1.getType().equalsIgnoreCase(string))
{
item2.setTitle(item1.getTitle());
item2.setType(item1.getType());
item2.setUrl(item1.getUrl());
vt.addElement(item2);
}
}
return vt;
}
public Vector getMenuVector()
{
Vector vc = new Vector();
int size = m_vector.size();
for(int i=0; i<size; i++)
{
item item1 = (item)m_vector.elementAt(i);
boolean isFind = false;
int size1 = vc.size();
String strMenu = new String();
strMenu = item1.getType();
for(int j=0; j<size1; j++)
{
String str = (String)vc.elementAt(j);
if (strMenu.equalsIgnoreCase(str))
{
isFind = true;
break;
}
}
if (isFind == false)
{
vc.add(strMenu);
}
}
return vc;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -