|
|
|
@ -22,10 +22,12 @@ import java.io.OutputStream;
|
|
|
|
|
public class FileNodeFILE implements FILE { |
|
|
|
|
|
|
|
|
|
private FileNode node; |
|
|
|
|
|
|
|
|
|
// carl:记录下FILE对应的运行环境,每次创建都设置下当前的运行环境
|
|
|
|
|
private String envPath; |
|
|
|
|
|
|
|
|
|
public FileNodeFILE(FileNodeFILE parent, String name, boolean isDir) { |
|
|
|
|
|
|
|
|
|
FileNode fn = parent.node; |
|
|
|
|
String parentDir; |
|
|
|
|
if (fn.isDirectory()) { |
|
|
|
@ -39,16 +41,19 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public FileNodeFILE(FileNode node) { |
|
|
|
|
|
|
|
|
|
this.node = node; |
|
|
|
|
this.envPath = WorkContext.getCurrent().getPath(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public FileNodeFILE(String envPath) { |
|
|
|
|
|
|
|
|
|
this.node = null; |
|
|
|
|
this.envPath = envPath; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public FileNodeFILE(FileNode node, String envPath) { |
|
|
|
|
|
|
|
|
|
this.node = node; |
|
|
|
|
this.envPath = envPath; |
|
|
|
|
} |
|
|
|
@ -59,7 +64,8 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 返回后缀 |
|
|
|
|
*/ |
|
|
|
|
public String prefix() { |
|
|
|
|
if (ComparatorUtils.equals(getEnvPath(), FRContext.getCommonOperator().getWebReportPath())) { |
|
|
|
|
|
|
|
|
|
if (ComparatorUtils.equals(getEnvPath(), FRContext.getCommonOperator().getWebRootPath())) { |
|
|
|
|
return FILEFactory.WEBREPORT_PREFIX; |
|
|
|
|
} |
|
|
|
|
return FILEFactory.ENV_PREFIX; |
|
|
|
@ -69,6 +75,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public String getEnvPath() { |
|
|
|
|
|
|
|
|
|
return this.envPath; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -78,6 +85,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 是则返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean isDirectory() { |
|
|
|
|
|
|
|
|
|
return ComparatorUtils.equals(node, null) ? true : node.isDirectory(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -85,6 +93,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public String getName() { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -100,6 +109,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public Icon getIcon() { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -115,6 +125,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public String getPath() { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
@ -126,6 +137,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @param path |
|
|
|
|
*/ |
|
|
|
|
public void setPath(String path) { |
|
|
|
|
|
|
|
|
|
node.setEnvPath(path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -133,6 +145,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public FILE getParent() { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -146,6 +159,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 文件组 |
|
|
|
|
*/ |
|
|
|
|
public FILE[] listFiles() { |
|
|
|
|
|
|
|
|
|
if (ComparatorUtils.equals(node, null)) { |
|
|
|
|
node = new FileNode(CoreConstants.SEPARATOR, true); |
|
|
|
|
//return new FILE[0];
|
|
|
|
@ -178,10 +192,16 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 返回文件节点 |
|
|
|
|
*/ |
|
|
|
|
private FileNode[] listFile(String rootFilePath) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
return FRContext.getFileNodes().list(rootFilePath); |
|
|
|
|
if (ComparatorUtils.equals(envPath, FRContext.getCommonOperator().getWebRootPath())) { |
|
|
|
|
return FRContext.getFileNodes().listWebRootFile(rootFilePath); |
|
|
|
|
} else { |
|
|
|
|
return FRContext.getFileNodes().list(rootFilePath); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
FRContext.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return new FileNode[0]; |
|
|
|
|
} |
|
|
|
@ -193,6 +213,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 创建成功返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean createFolder(String name) { |
|
|
|
|
|
|
|
|
|
if (ComparatorUtils.equals(node, null) || !node.isDirectory()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -211,6 +232,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 文件被锁返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean isLocked() { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -229,6 +251,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 文件存在返回 true |
|
|
|
|
*/ |
|
|
|
|
public boolean exists() { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -251,6 +274,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 是报表当前环境返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean isCurrentEnv() { |
|
|
|
|
|
|
|
|
|
return ComparatorUtils.equals(WorkContext.getCurrent().getPath(), envPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -260,6 +284,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 成功返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean mkfile() { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -279,6 +304,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
public InputStream asInputStream() throws Exception { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -292,7 +318,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
InputStream in = new ByteArrayInputStream(WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)))); |
|
|
|
|
|
|
|
|
|
return envPath.endsWith(".cpt") || envPath.endsWith(".frm") |
|
|
|
|
? XMLEncryptUtils.decodeInputStream(in) : in; |
|
|
|
|
? XMLEncryptUtils.decodeInputStream(in) : in; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -302,6 +328,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
public OutputStream asOutputStream() throws Exception { |
|
|
|
|
|
|
|
|
|
if (ComparatorUtils.equals(node, null)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -312,8 +339,8 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return FRContext.getCommonOperator().writeBean( |
|
|
|
|
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1), |
|
|
|
|
ProjectConstants.REPORTLETS_NAME |
|
|
|
|
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1), |
|
|
|
|
ProjectConstants.REPORTLETS_NAME |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -323,6 +350,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
public void closeTemplate() throws Exception { |
|
|
|
|
|
|
|
|
|
if (node == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -334,7 +362,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FRContext.getCommonOperator().unlockTemplate( |
|
|
|
|
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)); |
|
|
|
|
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -343,6 +371,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public String getEnvFullName() { |
|
|
|
|
|
|
|
|
|
return this.node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -352,6 +381,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 是则返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean isMemFile() { |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -361,6 +391,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 是则返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean isEnvFile() { |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -371,6 +402,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean equals(Object obj) { |
|
|
|
|
|
|
|
|
|
if (!(obj instanceof FileNodeFILE)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -384,6 +416,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return 返回hash码 |
|
|
|
|
*/ |
|
|
|
|
public int hashCode() { |
|
|
|
|
|
|
|
|
|
int hash = 5; |
|
|
|
|
hash = 61 * hash + (this.node != null ? this.node.hashCode() : 0); |
|
|
|
|
hash = 61 * hash + (this.envPath != null ? this.envPath.hashCode() : 0); |
|
|
|
@ -396,6 +429,7 @@ public class FileNodeFILE implements FILE {
|
|
|
|
|
* @return String 字符串 |
|
|
|
|
*/ |
|
|
|
|
public String toString() { |
|
|
|
|
|
|
|
|
|
return prefix() + (this.node != null ? this.node.getEnvPath() : ""); |
|
|
|
|
} |
|
|
|
|
} |