Java tutorial
/* * Copyright 2005-2015 shopxx.net. All rights reserved. * Support: http://3936242.01p.com/ * License: http://3936242.01p.com/license */ package net.shopxx.plugin.localStorage; import java.io.File; import java.io.IOException; import javax.servlet.ServletContext; import net.shopxx.Setting; import net.shopxx.plugin.StoragePlugin; import net.shopxx.util.SystemUtils; import org.apache.commons.io.FileUtils; import org.springframework.stereotype.Component; import org.springframework.web.context.ServletContextAware; @Component("localStoragePlugin") public class LocalStoragePlugin extends StoragePlugin implements ServletContextAware { private ServletContext servletContext; public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; } @Override public String getName() { return ""; } @Override public String getVersion() { return "1.0"; } @Override public String getAuthor() { return "xiaohe"; } @Override public String getSiteUrl() { return "http://3936242.01p.com/"; } @Override public String getInstallUrl() { return null; } @Override public String getUninstallUrl() { return null; } @Override public String getSettingUrl() { return "local_storage/setting.jhtml"; } @Override public void upload(String path, File file, String contentType) { File destFile = new File(servletContext.getRealPath(path)); try { FileUtils.moveFile(file, destFile); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } } @Override public String getUrl(String path) { Setting setting = SystemUtils.getSetting(); return setting.getSiteUrl() + path; } }