Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.softfobia.margiani.obi.catalog;
- import java.io.File;
- import java.util.Locale;
- import org.apache.log4j.Logger;
- import org.hibernate.SessionFactory;
- import org.riotfamily.riot.list.command.CommandContext;
- import org.riotfamily.riot.list.command.CommandResult;
- import org.riotfamily.riot.list.command.core.AbstractCommand;
- import org.riotfamily.riot.list.command.result.RefreshSiblingsResult;
- import com.softfobia.margiani.obi.catalog.CatalogFoldersList.FilderListElement;
- public class XmlToXlsCommand extends AbstractCommand {
- private final Logger logger = Logger.getLogger(this.getClass());
- public static final String ACTION_PARSE = "XmlToXls";
- private SessionFactory sessionFactory;
- private SubCategoriesAutoCreator subCategoriesAutoCreator;
- public String getAction() {
- return ACTION_PARSE;
- }
- public boolean isEnabled(CommandContext context) {
- FilderListElement file = (FilderListElement) context.getBean();
- return file==null || file.getStatus()==null || !file.getStatus().startsWith("error") || !file.getStatus().startsWith("started");
- }
- public String getConfirmationMessage(CommandContext context) {
- FilderListElement file = (FilderListElement) context.getBean();
- return context.getMessageResolver().getMessage("confirm.parse",
- new Object[] {file.getName()},
- "Do you really want to parse '"
- + file.getName() + "'?");
- }
- public CommandResult execute(CommandContext context) {
- final FilderListElement elememt = (FilderListElement) context.getBean();
- final File sourceFolder = elememt.getFile();
- new Thread(new Runnable() {
- public void run() {
- try {
- elememt.setStatus("started");
- Locale locale = Locale.ITALIAN;
- RiotProductPersister productPersister = new RiotProductPersister(XmlToXlsCommand.this.getSessionFactory());
- productPersister.setSubCategoriesAutoCreator(XmlToXlsCommand.this.getSubCategoriesAutoCreator());
- //Chiamare controller
- elememt.setStatus("done");
- } catch (Exception e) {
- logger.error(sourceFolder.getAbsolutePath(), e);
- elememt.setStatus("error: "+ e.getMessage());
- }
- }
- }).start();
- return new RefreshSiblingsResult(); // MessageResult("import started");
- }
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- public void setSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
- public SubCategoriesAutoCreator getSubCategoriesAutoCreator() {
- return subCategoriesAutoCreator;
- }
- public void setSubCategoriesAutoCreator(
- SubCategoriesAutoCreator subCategoriesAutoCreator) {
- this.subCategoriesAutoCreator = subCategoriesAutoCreator;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement