richie
6 years ago
43 changed files with 1366 additions and 65 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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(); |
||||
} |
||||
|
||||
} |
@ -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" |
||||
}; |
||||
} |
||||
} |
@ -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; |
@ -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() |
||||
}; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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) |
||||
}; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -0,0 +1,6 @@
|
||||
package com.fr.plugin.file.submit.oss.fun; |
||||
|
||||
public class OssConstants { |
||||
|
||||
public static final String KEY = "OssSubmit"; |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
|
@ -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; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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) { |
||||
|
||||
} |
||||
} |
@ -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")), |
||||
}); |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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"); |
||||
} |
||||
} |
@ -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"; |
||||
} |
||||
} |
@ -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"); |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
||||
} |
@ -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) |
@ -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 |
@ -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) |
||||
}); |
||||
} |
||||
}); |
Loading…
Reference in new issue