package com.systemincloud.modeler.upgrade.v0_5_3.to.v0_6_0;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import javax.xml.transform.TransformerException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;

import com.systemincloud.ext.vip.modeler.upgrade.v0_3_4.to.v0_3_5.VipExecute;
import com.systemincloud.modeler.upgrade.common.AbstractExecute;

public class Execute extends AbstractExecute {

	@Override
	public boolean execute(File file) {
		String xml;
		try {
			xml = readFile(file);
			xml = super.executeOnSic(xml);
			
			xml = updateTaskVerEmbeddedTask(xml, "0.3.0");
			xml = updateTaskVerJavaTask    (xml, "0.3.0");
			
			xml = addOnlyLocalAttribute(xml);
			
			xml = new VipExecute().executeOnFile(xml);
			//
			//
			//
			super.writeFile(file, xml);
		} catch (Exception e) { return false; }
		return true;
	}

	public String addOnlyLocalAttribute(String xml) throws TransformerException, IOException {
		return transform(xml, IOUtils.toString(Execute.class.getResourceAsStream("only-local.xsl"), "UTF-8"), null);
	}

	@Override
	public boolean execute(String root) {
		super.executeOnRoot(root);
		Collection<File> files = FileUtils.listFiles(new File(root), new RegexFileFilter("^(.*?(\\.sict))"), DirectoryFileFilter.DIRECTORY);
		for(File f : files) {
			String p = f.getAbsolutePath();
			f.renameTo(new File(p.substring(0, p.length() - 5) + ".sic"));
		}
		return true;
	}

	@Override
	protected String executeOnPom(String pom) throws TransformerException {
		return pom;
	}

	@Override
	protected String getVersion() {
		return "0.6.0";
	}
}

@@ -697,32 +697,191 @@
 OnSic(xml);%0A%09%09%09%0A
+%09%09%09xml = updateTaskVerConsole        (xml, %220.1.5%22);%0A%09%09%09xml = updateTaskVerConstant       (xml, %220.2.4%22);%0A%09%09%09xml = updateTaskVerDemux          (xml, %220.1.3%22);%0A
 %09%09%09xml = updateT
@@ -898,16 +898,19 @@
 ddedTask
+   
 (xml, %220
@@ -913,24 +913,289 @@
 , %220.3.0%22);%0A
+%09%09%09xml = updateTaskVerAnd            (xml, %220.1.3%22);%0A%09%09%09xml = updateTaskVerNot            (xml, %220.1.3%22);%0A%09%09%09xml = updateTaskVerXor            (xml, %220.1.3%22);%0A%09%09%09xml = updateTaskVerOr             (xml, %220.1.3%22);%0A%09%09%09xml = updateTaskVerInspect        (xml, %220.1.1%22);%0A
 %09%09%09xml = upd
@@ -1212,24 +1212,27 @@
 JavaTask    
+  
+ 
 (xml, %220.3.0
@@ -1235,16 +1235,175 @@
 .3.0%22);%0A
+%09%09%09xml = updateTaskVerMux            (xml, %220.1.3%22);%0A%09%09%09xml = updateTaskVerRandomGenerator(xml, %220.2.4%22);%0A%09%09%09xml = updateTaskVerSipo           (xml, %220.1.3%22);%0A
 %09%09%09%0A%09%09%09x

upgrade tasks versions