net.osxx.plugin.StoragePlugin.java Source code

Java tutorial

Introduction

Here is the source code for net.osxx.plugin.StoragePlugin.java

Source

/*
 * Copyright 2005-2013 klarclm.com. All rights reserved.
 * Support: http://www.klarclm.com
 * License: http://www.klarclm.com/license
 */
package net.osxx.plugin;

import java.io.File;
import java.util.List;

import javax.annotation.Resource;

import net.osxx.FileInfo;
import net.osxx.entity.PluginConfig;
import net.osxx.service.PluginConfigService;

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;

/**
 * Plugin - 
 * 
 * @author Operate System
 * @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();
    }

}