Java tutorial
/* * Copyright 2012-2014 sammyun.com.cn. All rights reserved. * Support: http://www.sammyun.com.cn * License: http://www.sammyun.com.cn/license */ package com.sammyun.plugin; import java.io.File; import java.util.List; import javax.annotation.Resource; import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.springframework.stereotype.Component; import com.sammyun.FileInfo; import com.sammyun.entity.PluginConfig; import com.sammyun.service.PluginConfigService; /** * Plugin - * * @author Sencloud Team * @version 3.0 */ public abstract class StoragePlugin implements Comparable<StoragePlugin> { @Resource(name = "pluginConfigServiceImpl") private PluginConfigService pluginConfigService; /** * ?ID * * @return ID */ public final String getId() { return getClass().getAnnotation(Component.class).value(); } /** * ??? * * @return ?? */ public abstract String getName(); /** * ? * * @return */ public abstract String getVersion(); /** * ? * * @return */ public abstract String getAuthor(); /** * ?? * * @return ? */ public abstract String getSiteUrl(); /** * ?URL * * @return URL */ public abstract String getInstallUrl(); /** * ??URL * * @return ?URL */ public abstract String getUninstallUrl(); /** * ?URL * * @return URL */ public abstract String getSettingUrl(); /** * ?? * * @return ? */ public boolean getIsInstalled() { return pluginConfigService.pluginIdExists(getId()); } /** * ??? * * @return ?? */ public PluginConfig getPluginConfig() { return pluginConfigService.findByPluginId(getId()); } /** * ??? * * @return ?? */ public boolean getIsEnabled() { PluginConfig pluginConfig = getPluginConfig(); return pluginConfig != null ? pluginConfig.getIsEnabled() : false; } /** * ? * * @param name ?? * @return */ public String getAttribute(String name) { PluginConfig pluginConfig = getPluginConfig(); return pluginConfig != null ? pluginConfig.getAttribute(name) : null; } /** * ?? * * @return ? */ public Integer getOrder() { PluginConfig pluginConfig = getPluginConfig(); return pluginConfig != null ? pluginConfig.getOrder() : null; } /** * * * @param path * @param file * @param contentType */ public abstract void upload(String path, File file, String contentType); /** * ?URL * * @param path * @return URL */ public abstract String getUrl(String path); /** * ? * * @param path ? * @return ? */ public abstract List<FileInfo> browser(String path); @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } if (this == obj) { return true; } StoragePlugin other = (StoragePlugin) obj; return new EqualsBuilder().append(getId(), other.getId()).isEquals(); } @Override public int hashCode() { return new HashCodeBuilder(17, 37).append(getId()).toHashCode(); } public int compareTo(StoragePlugin storagePlugin) { return new CompareToBuilder().append(getOrder(), storagePlugin.getOrder()) .append(getId(), storagePlugin.getId()).toComparison(); } }