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 LATEST = "latest";
private static final String SHOP_SCRIPTS = "shop_scripts"; private static final String SHOP_SCRIPTS = "shop_scripts";
private static final int VERSION_8 = 8; 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 MAIN_JS_PATH = "/scripts/plugin.html";
private static final String ENV_VERSION = "ENV_VERSION"; private static final String ENV_VERSION = "ENV_VERSION";
@ -52,7 +52,7 @@ public class WebViewDlgHelper {
GeneralContext.addEnvChangedListener(new EnvChangedListener() { GeneralContext.addEnvChangedListener(new EnvChangedListener() {
@Override @Override
public void envChanged() { 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) { if (FILEChooserPane.this.showWebReport) {
// webReportFILE = new FileFILE(new // webReportFILE = new FileFILE(new
// File(FRContext.getCommonOperator().getWebReportPath())); // File(FRContext.getCommonOperator().getWebReportPath()));
webReportFILE = new FileNodeFILE(FRContext.getCommonOperator().getWebReportPath()); webReportFILE = new FileNodeFILE(FRContext.getCommonOperator().getWebRootPath());
// String webReportPath = // String webReportPath =
// FRContext.getCommonOperator().getWebReportPath(); // FRContext.getCommonOperator().getWebReportPath();
// String webReportParentPath = new // String webReportParentPath = new
@ -1108,7 +1108,7 @@ public class FILEChooserPane extends BasicPane {
((DefaultListModel) subFileList.getModel()).removeAllElements(); ((DefaultListModel) subFileList.getModel()).removeAllElements();
for (int i = 0; i < res_array.length; i++) { for (int i = 0; i < res_array.length; i++) {
if (filter == null || filter.accept(res_array[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]; 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)); return new FileNodeFILE(new FileNode(path.substring(envPath.length() + 1), false));
} else if (path.startsWith(WEBREPORT_PREFIX)) { } else if (path.startsWith(WEBREPORT_PREFIX)) {
return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), false), return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), false),
FRContext.getCommonOperator().getWebReportPath()); FRContext.getCommonOperator().getWebRootPath());
} else if (path.startsWith(FILE_PREFIX)) { } else if (path.startsWith(FILE_PREFIX)) {
return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length()))); return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length())));
} else { } else {
@ -48,7 +48,7 @@ public class FILEFactory {
return new FileNodeFILE(new FileNode(path.substring(ENV_PREFIX.length()), true)); return new FileNodeFILE(new FileNode(path.substring(ENV_PREFIX.length()), true));
} else if (path.startsWith(WEBREPORT_PREFIX)) { } else if (path.startsWith(WEBREPORT_PREFIX)) {
return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), true), return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), true),
FRContext.getCommonOperator().getWebReportPath()); FRContext.getCommonOperator().getWebRootPath());
} else if (path.startsWith(FILE_PREFIX)) { } else if (path.startsWith(FILE_PREFIX)) {
return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length()))); return new FileFILE(new java.io.File(path.substring(FILE_PREFIX.length())));
} else { } else {

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

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