Browse Source

完成OSS文件上传下载

pull/1/head
richie 6 years ago
parent
commit
82bd320934
  1. 8
      build.xml
  2. BIN
      lib/aliyun-java-sdk-core-3.4.0.jar
  3. BIN
      lib/aliyun-java-sdk-ecs-4.2.0.jar
  4. BIN
      lib/aliyun-java-sdk-ram-3.0.0.jar
  5. BIN
      lib/aliyun-java-sdk-sts-3.0.0.jar
  6. BIN
      lib/aliyun-sdk-oss-3.3.0.jar
  7. BIN
      lib/commons-codec-1.9.jar
  8. BIN
      lib/commons-logging-1.2.jar
  9. BIN
      lib/httpclient-4.4.1.jar
  10. BIN
      lib/httpcore-4.4.1.jar
  11. BIN
      lib/jaxb-impl-2.2.3-1.jar
  12. BIN
      lib/jdom-1.1.jar
  13. BIN
      lib/jersey-core-1.9.jar
  14. BIN
      lib/jersey-json-1.9.jar
  15. BIN
      lib/stax-api-1.0.1.jar
  16. 16
      plugin.xml
  17. 20
      pom.xml
  18. 39
      src/main/java/com/fr/plugin/file/submit/oss/OssHyperlink4Download.java
  19. 19
      src/main/java/com/fr/plugin/file/submit/oss/OssHyperlinkJavaScriptHandler.java
  20. 4
      src/main/java/com/fr/plugin/file/submit/oss/OssJavaScriptActionBridge.java
  21. 14
      src/main/java/com/fr/plugin/file/submit/oss/OssRequestHandler.java
  22. 24
      src/main/java/com/fr/plugin/file/submit/oss/OssSubmitUIBridge.java
  23. 14
      src/main/java/com/fr/plugin/file/submit/oss/OssURLAliasProvider.java
  24. 91
      src/main/java/com/fr/plugin/file/submit/oss/conf/FileSubmitOssServerConfig.java
  25. 6
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssConstants.java
  26. 68
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssHttpHandler.java
  27. 109
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssSubmitTarget.java
  28. 69
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssSubmitTargetConfig.java
  29. 118
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssVariableValue.java
  30. 133
      src/main/java/com/fr/plugin/file/submit/oss/job/OssSubmitJob.java
  31. 110
      src/main/java/com/fr/plugin/file/submit/oss/script/OssDownloadHyperlink.java
  32. 34
      src/main/java/com/fr/plugin/file/submit/oss/script/OssSubmitJavaScript.java
  33. 41
      src/main/java/com/fr/plugin/file/submit/oss/server/OssSubmitJob.java
  34. 19
      src/main/java/com/fr/plugin/file/submit/oss/ui/Editors.java
  35. 11
      src/main/java/com/fr/plugin/file/submit/oss/ui/OssHyperlin4Dowload.java
  36. 69
      src/main/java/com/fr/plugin/file/submit/oss/ui/OssHyperlink4DownloadPane.java
  37. 49
      src/main/java/com/fr/plugin/file/submit/oss/ui/OssPathConfigPane.java
  38. 33
      src/main/java/com/fr/plugin/file/submit/oss/ui/OssSubmitJavaScriptPane.java
  39. 275
      src/main/java/com/fr/plugin/file/submit/oss/ui/OssSubmitPathTableModel.java
  40. 9
      src/main/resources/com/fr/plugin/file/submit/oss/submit.properties
  41. 9
      src/main/resources/com/fr/plugin/file/submit/oss/submit_zh_CN.properties
  42. 19
      src/main/resources/com/fr/plugin/file/submit/oss/web/oss.js
  43. 1
      src/main/resources/com/fr/plugin/file/submit/oss/web/oss.tpl

8
build.xml

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="plugin">
<!-- JDK路径,根据自己机器上实际位置修改-->
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/JDK1.8/Contents/Home"/>
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home"/>
<property name="libs" value="${basedir}/lib"/>
<property name="publicLibs" value=""/>
<property name="reportLibs" value="${basedir}/../webroot/WEB-INF/lib"/>
<property name="reportLibs" value="${basedir}/lib/report"/>
<property name="destLoc" value="."/>
<property name="classes" value="classes"/>
<xmlproperty file="${basedir}/plugin.xml"/>
@ -14,7 +14,7 @@
<!-- 插件版本-->
<property name="plugin-version" value="${current-version}"/>
<!-- 插件名字-->
<property name="plugin-name" value="oss-file-submit"/>
<property name="plugin-name" value="file-submit-oss"/>
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/>
<target name="prepare">
@ -127,4 +127,4 @@
</zip>
<move file="${plugin-folder}.zip" todir="${destLoc}/install"/>
</target>
</project>
</project>

BIN
lib/aliyun-java-sdk-core-3.4.0.jar

Binary file not shown.

BIN
lib/aliyun-java-sdk-ecs-4.2.0.jar

Binary file not shown.

BIN
lib/aliyun-java-sdk-ram-3.0.0.jar

Binary file not shown.

BIN
lib/aliyun-java-sdk-sts-3.0.0.jar

Binary file not shown.

BIN
lib/aliyun-sdk-oss-3.3.0.jar

Binary file not shown.

BIN
lib/commons-codec-1.9.jar

Binary file not shown.

BIN
lib/commons-logging-1.2.jar

Binary file not shown.

BIN
lib/httpclient-4.4.1.jar

Binary file not shown.

BIN
lib/httpcore-4.4.1.jar

Binary file not shown.

BIN
lib/jaxb-impl-2.2.3-1.jar

Binary file not shown.

BIN
lib/jdom-1.1.jar

Binary file not shown.

BIN
lib/jersey-core-1.9.jar

Binary file not shown.

BIN
lib/jersey-json-1.9.jar

Binary file not shown.

BIN
lib/stax-api-1.0.1.jar

Binary file not shown.

16
plugin.xml

@ -4,7 +4,7 @@
<active>yes</active>
<version>1.0</version>
<env-version>10.0</env-version>
<jartime>2018-10-31</jartime>
<jartime>2018-11-02</jartime>
<vendor>author</vendor>
<description><![CDATA[文件上传至阿里云的OSS中。]]></description>
<change-notes><![CDATA[
@ -13,5 +13,17 @@
<extra-core>
<LocaleFinder class="com.fr.plugin.file.submit.oss.OssLocaleFinder"/>
</extra-core>
<function-recorder class="com.fr.plugin.file.submit.oss.server.OssSubmitJob"/>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.file.submit.oss.OssRequestHandler"/>
<URLAliasProvider class="com.fr.plugin.file.submit.oss.OssURLAliasProvider"/>
</extra-decision>
<extra-report>
<JavaScriptFileHandler class="com.fr.plugin.file.submit.oss.OssHyperlinkJavaScriptHandler"/>
</extra-report>
<extra-designer>
<SubmitProvider class="com.fr.plugin.file.submit.oss.OssSubmitUIBridge"/>
<JavaScriptActionProvider class="com.fr.plugin.file.submit.oss.OssJavaScriptActionBridge"/>
<HyperlinkProvider class="com.fr.plugin.file.submit.oss.OssHyperlink4Download"/>
</extra-designer>
<function-recorder class="com.fr.plugin.file.submit.oss.job.OssSubmitJob"/>
</plugin>

20
pom.xml

@ -5,12 +5,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.plugin</groupId>
<artifactId>starter</artifactId>
<version>10.0</version>
<groupId>com.fr.maven</groupId>
<artifactId>finereport-maven</artifactId>
<version>10.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>file.submit.oss</artifactId>
<artifactId>plugin-file-submit-oss</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss -->
<dependency>
@ -18,9 +18,19 @@
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.fr.report</groupId>
<artifactId>fine-report-designer</artifactId>
<version>10.0</version>
</dependency>
<dependency>
<groupId>com.fr.report</groupId>
<artifactId>designer-base</artifactId>
<version>10.0</version>
</dependency>
</dependencies>
<build>
<!---如果要更改调试插件,改这里的配置就可以了-->
<outputDirectory>${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.file.submit.oss-1.0/classes</outputDirectory>
<outputDirectory>${web-inf-path}/plugins/plugin-com.fr.plugin.file.submit.oss-1.0/classes</outputDirectory>
</build>
</project>

39
src/main/java/com/fr/plugin/file/submit/oss/OssHyperlink4Download.java

@ -0,0 +1,39 @@
package com.fr.plugin.file.submit.oss;
import com.fr.design.fun.impl.AbstractHyperlinkProvider;
import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.i18n.Toolkit;
import com.fr.plugin.file.submit.oss.script.OssDownloadHyperlink;
import com.fr.plugin.file.submit.oss.ui.OssHyperlink4DownloadPane;
import com.fr.stable.AssistUtils;
public class OssHyperlink4Download extends AbstractHyperlinkProvider {
private NameableCreator nameableCreator;
public OssHyperlink4Download() {
nameableCreator = new NameObjectCreator(
Toolkit.i18nText("Plugin-File_Download_Oss"),
OssDownloadHyperlink.class,
OssHyperlink4DownloadPane.class);
}
@Override
public NameableCreator createHyperlinkCreator() {
return nameableCreator;
}
@Override
public boolean equals(Object o) {
return o instanceof OssHyperlink4Download
&& AssistUtils.equals(((OssHyperlink4Download) o).nameableCreator, nameableCreator);
}
@Override
public int hashCode() {
return this.nameableCreator.menuName().hashCode();
}
}

19
src/main/java/com/fr/plugin/file/submit/oss/OssHyperlinkJavaScriptHandler.java

@ -0,0 +1,19 @@
package com.fr.plugin.file.submit.oss;
import com.fr.base.TemplateUtils;
import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler;
public class OssHyperlinkJavaScriptHandler extends AbstractJavaScriptFileHandler {
@Override
public String[] pathsForFiles() {
try {
String text = TemplateUtils.render("${fineServletURL}");
System.out.println(text);
} catch (Exception e) {
e.printStackTrace();
}
return new String[]{
"/com/fr/plugin/file/submit/oss/web/oss.js"
};
}
}

4
src/main/java/com/fr/plugin/file/submit/oss/ui/OssJavaScriptActionImpl.java → src/main/java/com/fr/plugin/file/submit/oss/OssJavaScriptActionBridge.java

@ -1,11 +1,11 @@
package com.fr.plugin.file.submit.oss.ui;
package com.fr.plugin.file.submit.oss;
import com.fr.design.beans.FurtherBasicBeanPane;
import com.fr.design.fun.impl.AbstractJavaScriptActionProvider;
import com.fr.js.JavaScript;
public class OssJavaScriptActionImpl extends AbstractJavaScriptActionProvider {
public class OssJavaScriptActionBridge extends AbstractJavaScriptActionProvider {
@Override
public FurtherBasicBeanPane<? extends JavaScript> getJavaScriptActionPane() {
return null;

14
src/main/java/com/fr/plugin/file/submit/oss/OssRequestHandler.java

@ -0,0 +1,14 @@
package com.fr.plugin.file.submit.oss;
import com.fr.decision.webservice.plugin.handler.AbstractHttpHandlerProvider;
import com.fr.decision.webservice.plugin.handler.HttpHandler;
import com.fr.plugin.file.submit.oss.fun.OssHttpHandler;
public class OssRequestHandler extends AbstractHttpHandlerProvider {
@Override
public HttpHandler[] registerHandlers() {
return new HttpHandler[] {
new OssHttpHandler()
};
}
}

24
src/main/java/com/fr/plugin/file/submit/oss/OssSubmitUIBridge.java

@ -0,0 +1,24 @@
package com.fr.plugin.file.submit.oss;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.fun.impl.AbstractSubmitProvider;
import com.fr.design.i18n.Toolkit;
import com.fr.plugin.file.submit.oss.fun.OssConstants;
import com.fr.plugin.file.submit.oss.ui.OssPathConfigPane;
public class OssSubmitUIBridge extends AbstractSubmitProvider {
@Override
public BasicBeanPane appearanceForSubmit() {
return new OssPathConfigPane();
}
@Override
public String dataForSubmit() {
return Toolkit.i18nText("Plugin-File_Submit_Oss");
}
@Override
public String keyForSubmit() {
return OssConstants.KEY;
}
}

14
src/main/java/com/fr/plugin/file/submit/oss/OssURLAliasProvider.java

@ -0,0 +1,14 @@
package com.fr.plugin.file.submit.oss;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
import com.fr.decision.webservice.url.provider.AbstractURLAliasProvider;
public class OssURLAliasProvider extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/oss/download", "/oss/download", true)
};
}
}

91
src/main/java/com/fr/plugin/file/submit/oss/conf/FileSubmitOssServerConfig.java

@ -0,0 +1,91 @@
package com.fr.plugin.file.submit.oss.conf;
import com.fr.config.ConfigContext;
import com.fr.config.DefaultConfiguration;
import com.fr.config.Identifier;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.config.holder.impl.ColConf;
import com.fr.config.holder.impl.ObjConf;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* OSS文件上传下载所使用的OSS配置
*/
public class FileSubmitOssServerConfig extends DefaultConfiguration {
private static volatile FileSubmitOssServerConfig instance = null;
public static FileSubmitOssServerConfig getInstance() {
if (instance == null) {
instance = ConfigContext.getConfigInstance(FileSubmitOssServerConfig.class);
}
return instance;
}
// 地域节点配置信息
@Identifier("endPoint")
private Conf<String> endPoint = Holders.simple(StringUtils.EMPTY);
@Identifier("accessKeyId")
private Conf<String> accessKeyId = Holders.simple(StringUtils.EMPTY);
@Identifier("accessKeySecret")
private Conf<String> accessKeySecret = Holders.simple(StringUtils.EMPTY);
@Identifier("buckets")
private ColConf<Collection<String>> buckets = Holders.collection(new ArrayList<String>(), String.class);
public String getEndPoint() {
return endPoint.get();
}
public void setEndPoint(String endPoint) {
this.endPoint.set(endPoint);
}
public String getAccessKeyId() {
return accessKeyId.get();
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId.set(accessKeyId);
}
public String getAccessKeySecret() {
return accessKeySecret.get();
}
public void setAccessKeySecret(String accessKeySecret) {
this.accessKeySecret.set(accessKeySecret);
}
public String[] getBuckets() {
Collection<String> collection = buckets.get();
return collection.toArray(new String[0]);
}
public void setBuckets(String[] buckets) {
if (buckets != null) {
for (String bucket : buckets) {
this.buckets.add(bucket);
}
}
}
@Override
public Object clone() throws CloneNotSupportedException {
FileSubmitOssServerConfig cloned = (FileSubmitOssServerConfig) super.clone();
cloned.endPoint = (Conf<String>) endPoint.clone();
cloned.accessKeyId = (Conf<String>) accessKeyId.clone();
cloned.accessKeySecret = (Conf<String>) accessKeySecret.clone();
return cloned;
}
}

6
src/main/java/com/fr/plugin/file/submit/oss/fun/OssConstants.java

@ -0,0 +1,6 @@
package com.fr.plugin.file.submit.oss.fun;
public class OssConstants {
public static final String KEY = "OssSubmit";
}

68
src/main/java/com/fr/plugin/file/submit/oss/fun/OssHttpHandler.java

@ -0,0 +1,68 @@
package com.fr.plugin.file.submit.oss.fun;
import com.aliyun.oss.HttpMethod;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.utils.DateUtil;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import com.fr.data.NetworkHelper;
import com.fr.decision.webservice.plugin.handler.HttpHandler;
import com.fr.general.DateUtils;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.stable.StableUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class OssHttpHandler implements HttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/oss/download";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String bucket = NetworkHelper.getHTTPRequestParameter(req, "bucket");
String directory = NetworkHelper.getHTTPRequestParameter(req, "directory");
String fileName = NetworkHelper.getHTTPRequestParameter(req, "fileName");
PrintWriter writer = WebUtils.createPrintWriter(res);
writer.write(createDownloadUrl(bucket, directory, fileName));
writer.flush();
writer.close();
}
private String createDownloadUrl(String bucket, String directory, String fileName) throws Exception {
// 创建OSSClient实例。
OSSClient ossClient = new OSSClient(
FileSubmitOssServerConfig.getInstance().getEndPoint(),
FileSubmitOssServerConfig.getInstance().getAccessKeyId(),
FileSubmitOssServerConfig.getInstance().getAccessKeySecret());
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);
Date expiration = calendar.getTime();
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, StableUtils.pathJoin(directory, fileName), HttpMethod.GET);
// 设置过期时间。
request.setExpiration(expiration);
// 生成签名URL(HTTP GET请求)。
URL signedUrl = ossClient .generatePresignedUrl(request);
ossClient.shutdown();
return signedUrl.toString();
}
}

109
src/main/java/com/fr/plugin/file/submit/oss/fun/OssSubmitTarget.java

@ -0,0 +1,109 @@
package com.fr.plugin.file.submit.oss.fun;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.stable.AssistUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
public class OssSubmitTarget implements XMLable {
public static final String XML_TAG = "OssSubmitTarget";
private String bucket;
private OssVariableValue directory;
private OssVariableValue file;
private OssVariableValue name;
public OssSubmitTarget() {
}
public OssSubmitTarget(final String bucket, final OssVariableValue directory, final OssVariableValue file, final OssVariableValue name) {
this.bucket = bucket;
this.directory = directory;
this.file = file;
this.name = name;
}
public String getBucket() {
return this.bucket;
}
public void setBucket(final String bucket) {
this.bucket = bucket;
}
public OssVariableValue getDirectory() {
return directory;
}
public void setDirectory(OssVariableValue directory) {
this.directory = directory;
}
public OssVariableValue getName() {
return this.name;
}
public void setName(final OssVariableValue name) {
this.name = name;
}
public OssVariableValue getFile() {
return this.file;
}
public void setFile(final OssVariableValue file) {
this.file = file;
}
public void readXML(final XMLableReader reader) {
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if ("Bucket".equals(tagName)) {
this.bucket = reader.getElementValue();
} else if ("Directory".equals(tagName)) {
this.directory = (OssVariableValue) GeneralXMLTools.readXMLable(reader);
} else if ("Name".equals(tagName)) {
this.name = (OssVariableValue) GeneralXMLTools.readXMLable(reader);
} else if ("File".equals(tagName)) {
this.file = (OssVariableValue) GeneralXMLTools.readXMLable(reader);
}
}
}
public void writeXML(final XMLPrintWriter writer) {
if (StringUtils.isNotEmpty(bucket)) {
writer.startTAG("Bucket").textNode(bucket).end();
}
if (directory != null) {
GeneralXMLTools.writeXMLable(writer, directory, "Directory");
}
if (name != null) {
GeneralXMLTools.writeXMLable(writer, name, "Name");
}
if (file != null) {
GeneralXMLTools.writeXMLable(writer, file, "File");
}
}
@Override
public boolean equals(final Object o) {
return o instanceof OssSubmitTarget
&& AssistUtils.equals(((OssSubmitTarget) o).bucket, bucket)
&& AssistUtils.equals(((OssSubmitTarget) o).directory, directory)
&& AssistUtils.equals(((OssSubmitTarget) o).name, name)
&& AssistUtils.equals(((OssSubmitTarget) o).file, file);
}
public Object clone() throws CloneNotSupportedException {
OssSubmitTarget cloned = (OssSubmitTarget) super.clone();
cloned.bucket = bucket;
cloned.directory = (OssVariableValue) directory.clone();
cloned.name = (OssVariableValue) name.clone();
cloned.file = (OssVariableValue) file.clone();
return cloned;
}
}

69
src/main/java/com/fr/plugin/file/submit/oss/fun/OssSubmitTargetConfig.java

@ -0,0 +1,69 @@
package com.fr.plugin.file.submit.oss.fun;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
import java.util.ArrayList;
import java.util.List;
public class OssSubmitTargetConfig implements XMLable {
public static final String XML_TAG = "OssSubmitTargetConfig";
private List<OssSubmitTarget> targets = new ArrayList<OssSubmitTarget>();
public void addSubmitTarget(OssSubmitTarget target) {
targets.add(target);
}
public void clearSubmitTargets() {
targets.clear();
}
public void removeSubmitTarget(OssSubmitTarget target) {
targets.remove(target);
}
public OssSubmitTarget[] getSubmitTargets() {
return targets.toArray(new OssSubmitTarget[0]);
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader xmLableReader) {
if (xmLableReader.isChildNode()) {
String tagName = xmLableReader.getTagName();
if (OssSubmitTarget.XML_TAG.equals(tagName)) {
OssSubmitTarget target = (OssSubmitTarget)GeneralXMLTools.readXMLable(xmLableReader);
targets.add(target);
}
}
}
});
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
for (OssSubmitTarget target : targets) {
GeneralXMLTools.writeXMLable(writer, target, OssSubmitTarget.XML_TAG);
}
}
@Override
public Object clone() throws CloneNotSupportedException {
OssSubmitTargetConfig cloned = (OssSubmitTargetConfig) super.clone();
List<OssSubmitTarget> list = new ArrayList<OssSubmitTarget>();
for (OssSubmitTarget target : targets) {
list.add((OssSubmitTarget) target.clone());
}
cloned.targets = list;
return cloned;
}
}

118
src/main/java/com/fr/plugin/file/submit/oss/fun/OssVariableValue.java

@ -0,0 +1,118 @@
package com.fr.plugin.file.submit.oss.fun;
import com.fr.base.BaseFormula;
import com.fr.general.GeneralUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.CommonUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.UtilEvalError;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
public class OssVariableValue implements XMLable {
public static final String XML_TAG = "OssVariableValue";
private Type type;
private Object value;
public OssVariableValue() {
}
public OssVariableValue(Object value) {
if (value instanceof BaseFormula) {
type = Type.FORMULA;
this.value = value;
} else {
String content = GeneralUtils.objectToString(value);
if (CommonUtils.canBeFormula(content)) {
type = Type.FORMULA;
this.value = BaseFormula.createFormulaBuilder().build(content);
} else {
type = Type.PLAIN;
this.value = content;
}
}
}
public Object getValue() {
return value;
}
public String getResult(CalculatorProvider cal) {
Object result = value;
if (type == Type.FORMULA) {
try {
result = ((BaseFormula)value).evalValue(cal);
} catch (UtilEvalError u) {
FineLoggerFactory.getLogger().error(u.getMessage(), u);
}
}
return GeneralUtils.objectToString(result);
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if ("Attr".equals(tagName)) {
type = Type.parse(reader.getAttrAsInt("type", 0));
if (type == Type.FORMULA) {
value = BaseFormula.createFormulaBuilder().build(reader.getAttrAsString("value", StringUtils.EMPTY));
} else {
value = reader.getAttrAsString("value", StringUtils.EMPTY);
}
}
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG("Attr");
if (value instanceof BaseFormula) {
writer.attr("type", Type.FORMULA.getIndex()).attr("value", ((BaseFormula) value).getPureContent());
} else {
writer.attr("type", Type.PLAIN.getIndex()).attr("value", GeneralUtils.objectToString(value));
}
writer.end();
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
public String toString() {
return value == null ? StringUtils.EMPTY : GeneralUtils.objectToString(value);
}
public enum Type {
PLAIN(0), FORMULA(1);
private int index;
Type(int index) {
this.index = index;
}
public int getIndex() {
return index;
}
public static Type parse(int index) {
for (Type type : values()) {
if (type.index == index) {
return type;
}
}
return Type.PLAIN;
}
}
}

133
src/main/java/com/fr/plugin/file/submit/oss/job/OssSubmitJob.java

@ -0,0 +1,133 @@
package com.fr.plugin.file.submit.oss.job;
import com.aliyun.oss.OSSClient;
import com.fr.cache.Attachment;
import com.fr.data.AbstractSubmitTask;
import com.fr.general.FArray;
import com.fr.general.GeneralUtils;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.file.submit.oss.fun.OssConstants;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTargetConfig;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.FRFile;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import java.io.ByteArrayInputStream;
import java.io.File;
/**
* 提交到OSS的任务
*/
@EnableMetrics
public class OssSubmitJob extends AbstractSubmitTask {
private OSSClient ossClient = null;
private OssSubmitTargetConfig submitTargetConfig;
public OssSubmitTargetConfig getSubmitTargetConfig() {
return submitTargetConfig;
}
public void setSubmitTargetConfig(OssSubmitTargetConfig submitTargetConfig) {
this.submitTargetConfig = submitTargetConfig;
}
@Override
public String getJobType() {
return OssConstants.KEY;
}
@Override
@Focus(id = "com.fr.plugin.file.submit.oss", text = "Plugin-File_Submit_OSS", source = Original.PLUGIN)
public void doJob(Calculator calculator) throws Exception {
ossClient = new OSSClient(
FileSubmitOssServerConfig.getInstance().getEndPoint(),
FileSubmitOssServerConfig.getInstance().getAccessKeyId(),
FileSubmitOssServerConfig.getInstance().getAccessKeySecret());
OssSubmitTarget[] submitTargets = submitTargetConfig.getSubmitTargets();
for (OssSubmitTarget target : submitTargets) {
OssVariableValue fileObject = target.getFile();
Object file = calculator.evalValue(GeneralUtils.objectToString(fileObject));
uploadFile(target.getBucket(), file,
target.getDirectory() == null ? null : target.getDirectory().getResult(calculator),
target.getName() == null ? null : target.getName().getResult(calculator));
}
}
@Override
public void doFinish(Calculator calculator) throws Exception {
ossClient.shutdown();
}
private void uploadFile(String bucket, Object file, String directory, String newFileName) {
if (file instanceof FRFile) {
ossClient.putObject(bucket, directory + "/" + combineName(((FRFile) file).getFileName(), newFileName), new ByteArrayInputStream(((FRFile) file).getBytes()));
} else if (file instanceof FArray && ((FArray) file).length() != 0) {
FArray array = (FArray)file;
for (int i = 0; i < array.length(); i++) {
Object element = array.elementAt(i);
if (!(element instanceof Attachment)) {
if (element instanceof FArray) {
uploadFile(bucket, element, directory, newFileName);
}
} else {
ossClient.putObject(bucket, directory + "/" + combineName(((Attachment) element).getFilename(), newFileName), new ByteArrayInputStream(((Attachment) element).getBytes()));
}
}
}
}
/*
* 这里的逻辑是
* 1如果没有设置文件名就用上传的文件的名字
* 2如果设置了文件名且带有文件后缀就用设置的文件名
* 3其他情况都用原文件名
*/
private String combineName(String fileName, String myFileName) {
String realFileName;
if (StringUtils.isBlank(fileName)) {
fileName = "unnamed.png";
}
if (StringUtils.isNotEmpty(myFileName)) {
int index = myFileName.lastIndexOf(".");
if (index == -1) {
realFileName = fileName;
} else {
realFileName = myFileName;
}
} else {
realFileName = fileName;
}
return realFileName;
}
@Override
public void readXML(final XMLableReader reader) {
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if (OssSubmitTargetConfig.XML_TAG.equals(tagName)) {
OssSubmitTargetConfig config = new OssSubmitTargetConfig();
config.readXML(reader);
submitTargetConfig = config;
}
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
if (submitTargetConfig != null) {
GeneralXMLTools.writeXMLable(writer, submitTargetConfig, OssSubmitTargetConfig.XML_TAG);
}
}
}

110
src/main/java/com/fr/plugin/file/submit/oss/script/OssDownloadHyperlink.java

@ -0,0 +1,110 @@
package com.fr.plugin.file.submit.oss.script;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.js.Hyperlink;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.stable.AssistUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
public class OssDownloadHyperlink extends Hyperlink {
private String bucket;
private OssVariableValue directory;
private OssVariableValue fileName;
public String getBucket() {
return bucket;
}
public void setBucket(String bucket) {
this.bucket = bucket;
}
public OssVariableValue getDirectory() {
return directory;
}
public void setDirectory(OssVariableValue directory) {
this.directory = directory;
}
public OssVariableValue getFileName() {
return fileName;
}
public void setFileName(OssVariableValue fileName) {
this.fileName = fileName;
}
@Override
protected String actionJS(Repository repository) {
JSONObject data = JSONObject.create();
try {
data.put("bucket", bucket);
if (directory != null) {
data.put("directory", directory.getResult(repository.getCalculator()));
}
if (fileName != null) {
data.put("fileName", fileName.getResult(repository.getCalculator()));
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return "FR.doHyperlinkByOssDownload(" + data.toString() + ");";
}
public void readXML(final XMLableReader reader) {
super.readXML(reader);
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if ("Bucket".equals(tagName)) {
this.bucket = reader.getElementValue();
} else if ("Directory".equals(tagName)) {
this.directory = (OssVariableValue) GeneralXMLTools.readXMLable(reader);
} else if ("FileName".equals(tagName)) {
this.fileName = (OssVariableValue) GeneralXMLTools.readXMLable(reader);
}
}
}
public void writeXML(final XMLPrintWriter writer) {
writer.startTAG("JavaScript").attr("class", this.getClass().getName());
super.writeXML(writer);
if (StringUtils.isNotEmpty(bucket)) {
writer.startTAG("Bucket").textNode(bucket).end();
}
if (directory != null) {
GeneralXMLTools.writeXMLable(writer, directory, "Directory");
}
if (fileName != null) {
GeneralXMLTools.writeXMLable(writer, fileName, "FileName");
}
writer.end();
}
@Override
public boolean equals(Object o) {
return o instanceof OssDownloadHyperlink
&& AssistUtils.equals(((OssDownloadHyperlink) o).bucket, bucket)
&& AssistUtils.equals(((OssDownloadHyperlink) o).directory, directory)
&& AssistUtils.equals(((OssDownloadHyperlink) o).fileName, fileName);
}
@Override
public Object clone() throws CloneNotSupportedException {
OssDownloadHyperlink cloned = (OssDownloadHyperlink) super.clone();
if (directory != null) {
cloned.directory = (OssVariableValue) directory.clone();
}
if (fileName != null) {
cloned.fileName = (OssVariableValue) fileName.clone();
}
return cloned;
}
}

34
src/main/java/com/fr/plugin/file/submit/oss/script/OssSubmitJavaScript.java

@ -0,0 +1,34 @@
package com.fr.plugin.file.submit.oss.script;
import com.fr.js.AbstractJavaScript;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
public class OssSubmitJavaScript extends AbstractJavaScript {
@Override
protected String actionJS(Repository repository) {
return null;
}
@Override
public void writeXML(XMLPrintWriter xmlPrintWriter) {
super.writeXML(xmlPrintWriter);
}
@Override
public void readXML(XMLableReader xmLableReader) {
super.readXML(xmLableReader);
}
@Override
public boolean equals(Object o) {
return super.equals(o);
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}

41
src/main/java/com/fr/plugin/file/submit/oss/server/OssSubmitJob.java

@ -1,41 +0,0 @@
package com.fr.plugin.file.submit.oss.server;
import com.fr.data.AbstractSubmitTask;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.Calculator;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
/**
* 提交到OSS的任务
*/
@EnableMetrics
public class OssSubmitJob extends AbstractSubmitTask {
@Override
public String getJobType() {
return null;
}
@Override
@Focus(id="com.fr.plugin.file.submit.oss", text = "Plugin-File_Submit_OSS", source = Original.PLUGIN)
public void doJob(Calculator calculator) throws Exception {
}
@Override
public void doFinish(Calculator calculator) throws Exception {
}
@Override
public void readXML(XMLableReader xmLableReader) {
}
@Override
public void writeXML(XMLPrintWriter xmlPrintWriter) {
}
}

19
src/main/java/com/fr/plugin/file/submit/oss/ui/Editors.java

@ -0,0 +1,19 @@
package com.fr.plugin.file.submit.oss.ui;
import com.fr.design.editor.ValueEditorPane;
import com.fr.design.editor.ValueEditorPaneFactory;
import com.fr.design.editor.editor.Editor;
import com.fr.design.editor.editor.FormulaEditor;
import com.fr.design.editor.editor.TextEditor;
import com.fr.design.i18n.Toolkit;
public class Editors {
public static ValueEditorPane createValueEditorPane() {
return ValueEditorPaneFactory.createValueEditorPane(new Editor[]{
new TextEditor(),
new FormulaEditor(Toolkit.i18nText("Plugin-File_Submit_Oss_Editor_Formula")),
});
}
}

11
src/main/java/com/fr/plugin/file/submit/oss/ui/OssHyperlin4Dowload.java

@ -1,11 +0,0 @@
package com.fr.plugin.file.submit.oss.ui;
import com.fr.design.fun.impl.AbstractHyperlinkProvider;
import com.fr.design.gui.controlpane.NameableCreator;
public class OssHyperlin4Dowload extends AbstractHyperlinkProvider {
@Override
public NameableCreator createHyperlinkCreator() {
return null;
}
}

69
src/main/java/com/fr/plugin/file/submit/oss/ui/OssHyperlink4DownloadPane.java

@ -0,0 +1,69 @@
package com.fr.plugin.file.submit.oss.ui;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.editor.ValueEditorPane;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.general.GeneralUtils;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.plugin.file.submit.oss.script.OssDownloadHyperlink;
import javax.swing.*;
import java.awt.*;
public class OssHyperlink4DownloadPane extends BasicBeanPane<OssDownloadHyperlink> {
private UIComboBox bucketComboBox;
private ValueEditorPane directoryValuePane;
private ValueEditorPane fileNameValuePane;
public OssHyperlink4DownloadPane() {
initComponents();
}
private void initComponents() {
this.setLayout(new BorderLayout());
this.bucketComboBox = new UIComboBox(FileSubmitOssServerConfig.getInstance().getBuckets());
this.directoryValuePane = Editors.createValueEditorPane();
this.fileNameValuePane = Editors.createValueEditorPane();
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] rowSize = {p, p, p};
double[] columnSize = {p, f};
JPanel centerPane = TableLayoutHelper.createTableLayoutPane(
new Component[][] {
{new UILabel(Toolkit.i18nText("Plugin-File_Submit_Oss_Bucket_Name") + ":"), bucketComboBox},
{new UILabel(Toolkit.i18nText("Plugin-File_Submit_Oss_Directory") + ":"), directoryValuePane},
{new UILabel(Toolkit.i18nText("Plugin-File_Submit_Oss_File_Name") + ":"), fileNameValuePane}
}, rowSize, columnSize);
this.add(centerPane, BorderLayout.CENTER);
}
@Override
public void populateBean(OssDownloadHyperlink hyperlink) {
if (hyperlink == null) {
return;
}
bucketComboBox.setSelectedItem(hyperlink.getBucket());
directoryValuePane.populate(hyperlink.getDirectory() == null ? null : hyperlink.getDirectory().getValue());
fileNameValuePane.populate(hyperlink.getFileName() == null ? null : hyperlink.getFileName().getValue());
}
@Override
public OssDownloadHyperlink updateBean() {
OssDownloadHyperlink hyperlink = new OssDownloadHyperlink();
hyperlink.setBucket(GeneralUtils.objectToString(bucketComboBox.getSelectedItem()));
hyperlink.setDirectory(new OssVariableValue(directoryValuePane.update()));
hyperlink.setFileName(new OssVariableValue(fileNameValuePane.update()));
return hyperlink;
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Plugin-File_Download_Hyperlink");
}
}

49
src/main/java/com/fr/plugin/file/submit/oss/ui/OssPathConfigPane.java

@ -0,0 +1,49 @@
package com.fr.plugin.file.submit.oss.ui;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTargetConfig;
import com.fr.plugin.file.submit.oss.job.OssSubmitJob;
import java.awt.*;
public class OssPathConfigPane extends BasicBeanPane<OssSubmitJob> {
private UITableEditorPane<OssSubmitTarget> tableEditorPane;
public OssPathConfigPane() {
setLayout(new BorderLayout());
this.tableEditorPane = new UITableEditorPane<OssSubmitTarget>(new OssSubmitPathTableModel());
this.add(tableEditorPane, BorderLayout.CENTER);
}
@Override
public void populateBean(OssSubmitJob job) {
if (job != null) {
OssSubmitTargetConfig submitTargetConfig = job.getSubmitTargetConfig();
if (submitTargetConfig != null) {
OssSubmitTarget[] targets = submitTargetConfig.getSubmitTargets();
this.tableEditorPane.populate(targets);
}
}
}
@Override
public OssSubmitJob updateBean() {
OssSubmitJob submitJob = new OssSubmitJob();
OssSubmitTargetConfig submitTargetConfig = new OssSubmitTargetConfig();
java.util.List<OssSubmitTarget> targetList = tableEditorPane.update();
for (OssSubmitTarget target : targetList) {
submitTargetConfig.addSubmitTarget(target);
}
submitJob.setSubmitTargetConfig(submitTargetConfig);
return submitJob;
}
@Override
protected String title4PopupWindow() {
return "Path";
}
}

33
src/main/java/com/fr/plugin/file/submit/oss/ui/OssSubmitJavaScriptPane.java

@ -0,0 +1,33 @@
package com.fr.plugin.file.submit.oss.ui;
import com.fr.design.beans.FurtherBasicBeanPane;
import com.fr.design.i18n.Toolkit;
import com.fr.plugin.file.submit.oss.script.OssSubmitJavaScript;
public class OssSubmitJavaScriptPane extends FurtherBasicBeanPane<OssSubmitJavaScript> {
@Override
public boolean accept(Object o) {
return o instanceof OssSubmitJavaScript;
}
@Override
public void reset() {
populateBean(null);
}
@Override
public void populateBean(OssSubmitJavaScript ossSubmitJavaScript) {
}
@Override
public OssSubmitJavaScript updateBean() {
return null;
}
@Override
public String title4PopupWindow() {
return Toolkit.i18nText("Plugin-File_Submit_OSS");
}
}

275
src/main/java/com/fr/plugin/file/submit/oss/ui/OssSubmitPathTableModel.java

@ -0,0 +1,275 @@
package com.fr.plugin.file.submit.oss.ui;
import com.fr.design.editor.ValueEditorPane;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itableeditorpane.UITableEditAction;
import com.fr.design.gui.itableeditorpane.UITableModelAdapter;
import com.fr.design.i18n.Toolkit;
import com.fr.general.GeneralUtils;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellEditor;
import java.awt.*;
import java.awt.event.ActionEvent;
public class OssSubmitPathTableModel extends UITableModelAdapter<OssSubmitTarget> {
public OssSubmitPathTableModel() {
super(new String[]{
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_Bucket_Name"),
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_Directory"),
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_File"),
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_File_Name")});
this.setColumnClass(new Class[]{BucketEditor.class, DirectoryEditor.class, FileSelectEditor.class, FileNameEditor.class});
this.setDefaultEditor(BucketEditor.class, new BucketEditor());
this.setDefaultRenderer(BucketEditor.class, new SimpleRenderer());
this.setDefaultEditor(DirectoryEditor.class, new DirectoryEditor());
this.setDefaultRenderer(DirectoryEditor.class, new CurrentValueRenderer());
this.setDefaultEditor(FileSelectEditor.class, new FileSelectEditor());
this.setDefaultRenderer(FileSelectEditor.class, new CurrentValueRenderer());
this.setDefaultEditor(FileNameEditor.class, new FileNameEditor());
this.setDefaultRenderer(FileNameEditor.class, new CurrentValueRenderer());
}
public Object getValueAt(final int row, final int column) {
final OssSubmitTarget target = this.getList().get(row);
switch (column) {
case 0: {
return target.getBucket();
}
case 1: {
return target.getDirectory() == null ? null : target.getDirectory().getValue();
}
case 2: {
return target.getFile() == null ? null : target.getFile().getValue();
}
case 3: {
return target.getName() == null ? null : target.getName().getValue();
}
default: {
return null;
}
}
}
public boolean isCellEditable(final int row, final int column) {
return true;
}
public UITableEditAction[] createAction() {
return new UITableEditAction[]{
new AddPathAction(),
new UITableModelAdapter.DeleteAction(),
new UITableModelAdapter.MoveUpAction(),
new UITableModelAdapter.MoveDownAction()};
}
private void addPath() {
this.addRow(new OssSubmitTarget());
this.fireTableDataChanged();
this.table.getSelectionModel().setSelectionInterval(this.table.getRowCount() - 1, this.table.getRowCount() - 1);
}
private class BucketEditor extends AbstractCellEditor implements TableCellEditor {
private static final long serialVersionUID = 1L;
private UIComboBox bucketComboBox;
public BucketEditor() {
bucketComboBox = new UIComboBox(FileSubmitOssServerConfig.getInstance().getBuckets());
this.addCellEditorListener(new CellEditorListener() {
@Override
public void editingCanceled(final ChangeEvent changeEvent) {
}
@Override
public void editingStopped(final ChangeEvent changeEvent) {
if (table.getSelectedRow() == -1) {
return;
}
OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
submitTarget.setBucket(GeneralUtils.objectToString(getCellEditorValue()));
fireTableDataChanged();
}
});
}
@Override
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
bucketComboBox.setSelectedItem(o);
return this.bucketComboBox;
}
@Override
public Object getCellEditorValue() {
return this.bucketComboBox.getSelectedItem();
}
}
public class DirectoryEditor extends AbstractCellEditor implements TableCellEditor {
private ValueEditorPane textField;
public DirectoryEditor() {
this.textField = Editors.createValueEditorPane();
this.addCellEditorListener(new CellEditorListener() {
@Override
public void editingCanceled(final ChangeEvent changeEvent) {
}
@Override
public void editingStopped(final ChangeEvent changeEvent) {
if (table.getSelectedRow() == -1) {
return;
}
final OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
submitTarget.setDirectory(new OssVariableValue(getCellEditorValue()));
fireTableDataChanged();
}
});
}
@Override
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
this.textField.populate((o == null) ? StringUtils.EMPTY : o);
return this.textField;
}
@Override
public Object getCellEditorValue() {
return this.textField.update();
}
}
public class FileSelectEditor extends AbstractCellEditor implements TableCellEditor {
private ValueEditorPane textField;
public FileSelectEditor() {
this.textField = Editors.createValueEditorPane();
this.addCellEditorListener(new CellEditorListener() {
@Override
public void editingCanceled(final ChangeEvent changeEvent) {
}
@Override
public void editingStopped(final ChangeEvent changeEvent) {
if (table.getSelectedRow() == -1) {
return;
}
final OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
submitTarget.setFile(new OssVariableValue(getCellEditorValue()));
fireTableDataChanged();
}
});
}
@Override
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
this.textField.populate((o == null) ? StringUtils.EMPTY : o);
return this.textField;
}
@Override
public Object getCellEditorValue() {
return this.textField.update();
}
}
public class FileNameEditor extends AbstractCellEditor implements TableCellEditor {
private ValueEditorPane textField;
public FileNameEditor() {
this.textField = Editors.createValueEditorPane();
this.addCellEditorListener(new CellEditorListener() {
@Override
public void editingCanceled(final ChangeEvent changeEvent) {
}
@Override
public void editingStopped(final ChangeEvent changeEvent) {
if (table.getSelectedRow() == -1) {
return;
}
final OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
submitTarget.setName(new OssVariableValue(getCellEditorValue()));
fireTableDataChanged();
}
});
}
@Override
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
this.textField.populate((o == null) ? StringUtils.EMPTY : o);
return this.textField;
}
@Override
public Object getCellEditorValue() {
return this.textField.update();
}
}
private class SimpleRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.setText(GeneralUtils.objectToString(value));
return this;
}
}
private class CurrentValueRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
private ValueEditorPane editor;
private UILabel disableLabel;
public CurrentValueRenderer() {
this(Editors.createValueEditorPane());
}
public CurrentValueRenderer(ValueEditorPane valueEditorPane) {
disableLabel = new UILabel(Toolkit.i18nText("Plugin-File_Submit_Oss_Disable"));
disableLabel.setForeground(Color.pink);
disableLabel.setHorizontalAlignment(SwingConstants.CENTER);
editor = valueEditorPane;
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (table.isCellEditable(row, column)) {
if (value == null) {
editor.populate(StringUtils.EMPTY);
} else {
if (value instanceof OssVariableValue) {
editor.populate(((OssVariableValue) value).getValue());
} else {
editor.populate(value);
}
}
return editor;
} else {
return disableLabel;
}
}
}
private class AddPathAction extends UITableModelAdapter.AddTableRowAction {
public AddPathAction() {
super();
}
public void actionPerformed(final ActionEvent actionEvent) {
super.actionPerformed(actionEvent);
OssSubmitPathTableModel.this.addPath();
}
}
}

9
src/main/resources/com/fr/plugin/file/submit/oss/submit.properties

@ -0,0 +1,9 @@
Plugin-File_Submit_Oss=Submit to OSS
Plugin-File_Submit_Oss_Bucket_Name=Bucket name
Plugin-File_Submit_Oss_Directory=Directory
Plugin-File_Submit_Oss_File=File
Plugin-File_Submit_Oss_File_Name=File name
Plugin-File_Submit_Oss_Editor_Formula=Formula
Plugin-File_Submit_Oss_Disable=Disabled
Plugin-File_Download_Oss=Download(OSS)
Plugin-File_Download_Hyperlink=Hyperlink(OSS)

9
src/main/resources/com/fr/plugin/file/submit/oss/submit_zh_CN.properties

@ -0,0 +1,9 @@
Plugin-File_Submit_Oss=\u4E0A\u4F20\u81F3OSS
Plugin-File_Submit_Oss_Bucket_Name=Bucket\u540D\u5B57
Plugin-File_Submit_Oss_Directory=\u76EE\u5F55
Plugin-File_Submit_Oss_File=\u6587\u4EF6
Plugin-File_Submit_Oss_File_Name=\u6587\u4EF6\u540D
Plugin-File_Submit_Oss_Editor_Formula=\u516C\u5F0F
Plugin-File_Submit_Oss_Disable=\u4E0D\u53EF\u7F16\u8F91
Plugin-File_Download_Oss=\u6587\u4EF6\u4E0B\u8F7D\uFF08OSS\uFF09
Plugin-File_Download_Hyperlink=\u6587\u4EF6\u4E0B\u8F7D\uFF08OSS\uFF09

19
src/main/resources/com/fr/plugin/file/submit/oss/web/oss.js

@ -0,0 +1,19 @@
$.extend(FR, {
doHyperlinkByOssDownload: function (data) {
this.ajax({
url: FR.fineServletURL + "/url/oss/download",
async: true,
type: 'post',
data : {
sessionID: FR.SessionMgr.getSessionID(),
bucket : data.bucket,
directory : data.directory,
fileName : data.fileName
},
complete: function (res, status) {
window.open(res.responseText);
}.createDelegate(this)
});
}
});

1
src/main/resources/com/fr/plugin/file/submit/oss/web/oss.tpl

@ -0,0 +1 @@
FR.doHyperlinkByDownload();
Loading…
Cancel
Save