Browse Source

Merge pull request #140 in DESIGN/design from ~JU/design:feature/10.0 to feature/10.0

* commit 'f6048da455029ed36c338e5882a53c2de9ad20e6':
  REPORT-8881 com.fr.file.FileNodeFILE#listFiles有问题
master
ju 7 years ago
parent
commit
b44fd56c70
  1. 4
      designer-base/src/com/fr/design/extra/WebViewDlgHelper.java
  2. 4
      designer-base/src/com/fr/file/FILEChooserPane.java
  3. 4
      designer-base/src/com/fr/file/FILEFactory.java
  4. 138
      designer-base/src/com/fr/file/FileNodeFILE.java

4
designer-base/src/com/fr/design/extra/WebViewDlgHelper.java

@ -44,7 +44,7 @@ public class WebViewDlgHelper {
private static final String LATEST = "latest";
private static final String SHOP_SCRIPTS = "shop_scripts";
private static final int VERSION_8 = 8;
private static String installHome = FRContext.getCommonOperator().getWebReportPath();
private static String installHome = FRContext.getCommonOperator().getWebRootPath();
private static final String MAIN_JS_PATH = "/scripts/plugin.html";
private static final String ENV_VERSION = "ENV_VERSION";
@ -52,7 +52,7 @@ public class WebViewDlgHelper {
GeneralContext.addEnvChangedListener(new EnvChangedListener() {
@Override
public void envChanged() {
installHome = FRContext.getCommonOperator().getWebReportPath();
installHome = FRContext.getCommonOperator().getWebRootPath();
}
});
}

4
designer-base/src/com/fr/file/FILEChooserPane.java

@ -787,7 +787,7 @@ public class FILEChooserPane extends BasicPane {
if (FILEChooserPane.this.showWebReport) {
// webReportFILE = new FileFILE(new
// File(FRContext.getCommonOperator().getWebReportPath()));
webReportFILE = new FileNodeFILE(FRContext.getCommonOperator().getWebReportPath());
webReportFILE = new FileNodeFILE(FRContext.getCommonOperator().getWebRootPath());
// String webReportPath =
// FRContext.getCommonOperator().getWebReportPath();
// String webReportParentPath = new
@ -1108,7 +1108,7 @@ public class FILEChooserPane extends BasicPane {
((DefaultListModel) subFileList.getModel()).removeAllElements();
for (int i = 0; i < res_array.length; i++) {
if (filter == null || filter.accept(res_array[i])) {
((DefaultListModel) subFileList.getModel()).addElement(res_array[i]);
((DefaultListModel) subFileList.getModel()).addElement( res_array[i]);
}
}
String[] name_array = new String[res_array.length];

4
designer-base/src/com/fr/file/FILEFactory.java

@ -31,7 +31,7 @@ public class FILEFactory {
return new FileNodeFILE(new FileNode(path.substring(envPath.length() + 1), false));
} else if (path.startsWith(WEBREPORT_PREFIX)) {
return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), false),
FRContext.getCommonOperator().getWebReportPath());
FRContext.getCommonOperator().getWebRootPath());
} else if (path.startsWith(FILE_PREFIX)) {
return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length())));
} else {
@ -48,7 +48,7 @@ public class FILEFactory {
return new FileNodeFILE(new FileNode(path.substring(ENV_PREFIX.length()), true));
} else if (path.startsWith(WEBREPORT_PREFIX)) {
return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), true),
FRContext.getCommonOperator().getWebReportPath());
FRContext.getCommonOperator().getWebRootPath());
} else if (path.startsWith(FILE_PREFIX)) {
return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length())));
} else {

138
designer-base/src/com/fr/file/FileNodeFILE.java

@ -20,12 +20,14 @@ import java.io.InputStream;
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()) {
@ -33,119 +35,131 @@ public class FileNodeFILE implements FILE {
} else {
parentDir = fn.getParent();
}
this.node = new FileNode(StableUtils.pathJoin(parentDir, name), isDir);
this.envPath = WorkContext.getCurrent().getPath();
}
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;
}
/**
* prefix 后缀
*
* @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;
}
/**
* @return
*/
public String getEnvPath() {
return this.envPath;
}
/**
* 是否是目录
*
* @return 是则返回true
*/
public boolean isDirectory() {
return ComparatorUtils.equals(node, null) ? true : node.isDirectory();
}
/**
* @return
*/
public String getName() {
if (node == null) {
return null;
}
if (ComparatorUtils.equals(node.getEnvPath(), ProjectConstants.REPORTLETS_NAME)) {
return Inter.getLocText("Utils-Report_Runtime_Env");
} else {
return node.getName();
}
}
/**
* @return
*/
public Icon getIcon() {
if (node == null) {
return null;
}
if (ComparatorUtils.equals(node.getEnvPath(), ProjectConstants.REPORTLETS_NAME)) {
return BaseUtils.readIcon("/com/fr/base/images/oem/logo.png");
} else {
return FileTreeIcon.getIcon(node);
}
}
/**
* @return
*/
public String getPath() {
if (node == null) {
return "";
}
return node.getEnvPath();
}
/**
* @param path
*/
public void setPath(String path) {
node.setEnvPath(path);
}
/**
* @return
*/
public FILE getParent() {
if (node == null) {
return null;
}
return new FileNodeFILE(new FileNode(node.getParent(), true));
}
/**
* 文件
*
* @return 文件组
*/
public FILE[] listFiles() {
if (ComparatorUtils.equals(node, null)) {
node = new FileNode(CoreConstants.SEPARATOR, true);
//return new FILE[0];
@ -153,24 +167,24 @@ public class FileNodeFILE implements FILE {
if (!node.isDirectory()) {
return new FILE[]{this};
}
try {
FileNode[] node_array;
node_array = listFile(node.getEnvPath());
java.util.Arrays.sort(node_array, new FileNodeComparator());
FILE[] res_array = new FILE[node_array.length];
for (int i = 0; i < node_array.length; i++) {
res_array[i] = new FileNodeFILE(node_array[i], envPath);
}
return res_array;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return new FILE[0];
}
}
/**
* 根目录文件地址
*
@ -178,14 +192,20 @@ 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,10 +213,11 @@ public class FileNodeFILE implements FILE {
* @return 创建成功返回true
*/
public boolean createFolder(String name) {
if (ComparatorUtils.equals(node, null) || !node.isDirectory()) {
return false;
}
try {
return WorkContext.getWorkResource().createFile(StableUtils.pathJoin(node.getEnvPath(), name));
} catch (Exception e) {
@ -204,17 +225,18 @@ public class FileNodeFILE implements FILE {
return false;
}
}
/**
* 是否锁住
*
* @return 文件被锁返回true
*/
public boolean isLocked() {
if (node == null) {
return false;
}
try {
return FRContext.getCommonOperator().fileLocked(node.getEnvPath());
} catch (Exception e) {
@ -222,13 +244,14 @@ public class FileNodeFILE implements FILE {
return false;
}
}
/**
* 是否存在
*
* @return 文件存在返回 true
*/
public boolean exists() {
if (node == null) {
return false;
}
@ -236,7 +259,7 @@ public class FileNodeFILE implements FILE {
if (!isCurrentEnv()) {
return false;
}
try {
return WorkContext.getWorkResource().exist(node.getEnvPath());
} catch (Exception e) {
@ -244,26 +267,28 @@ public class FileNodeFILE implements FILE {
return false;
}
}
/**
* 是否是当前环境
*
* @return 是报表当前环境返回true
*/
public boolean isCurrentEnv() {
return ComparatorUtils.equals(WorkContext.getCurrent().getPath(), envPath);
}
/**
* 创建文件
*
* @return 成功返回true
*/
public boolean mkfile() {
if (node == null) {
return false;
}
try {
return WorkContext.getWorkResource().createFile(node.getEnvPath());
} catch (Exception e) {
@ -271,7 +296,7 @@ public class FileNodeFILE implements FILE {
return false;
}
}
/**
* 作为输入流
*
@ -279,10 +304,11 @@ public class FileNodeFILE implements FILE {
* @throws Exception
*/
public InputStream asInputStream() throws Exception {
if (node == null) {
return null;
}
String envPath = node.getEnvPath();
// envPath必须以reportlets开头
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
@ -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,68 +328,73 @@ public class FileNodeFILE implements FILE {
* @throws Exception
*/
public OutputStream asOutputStream() throws Exception {
if (ComparatorUtils.equals(node, null)) {
return null;
}
String envPath = node.getEnvPath();
// envPath必须以reportlets开头
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
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
);
}
/**
* 关闭模板
*
* @throws Exception
*/
public void closeTemplate() throws Exception {
if (node == null) {
return;
}
String envPath = node.getEnvPath();
// envPath必须以reportlets开头
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
return;
}
FRContext.getCommonOperator().unlockTemplate(
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1));
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1));
}
/**
* 得到环境的全名
*
* @return
*/
public String getEnvFullName() {
return this.node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
}
/**
* 是否是内存文件
*
* @return 是则返回true
*/
public boolean isMemFile() {
return false;
}
/**
* 是否是环境文件
*
* @return 是则返回true
*/
public boolean isEnvFile() {
return true;
}
/**
* 是佛相同
*
@ -371,31 +402,34 @@ public class FileNodeFILE implements FILE {
* @return
*/
public boolean equals(Object obj) {
if (!(obj instanceof FileNodeFILE)) {
return false;
}
return ComparatorUtils.equals(this.envPath, ((FileNodeFILE) obj).envPath) && ComparatorUtils.equals(this.node, ((FileNodeFILE) obj).node);
}
/**
* 返回hash码
*
* @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);
return hash;
}
/**
* 作为字符串返回
*
* @return String 字符串
*/
public String toString() {
return prefix() + (this.node != null ? this.node.getEnvPath() : "");
}
}
Loading…
Cancel
Save