Changed the class name Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/commit/a246f817 Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/tree/a246f817 Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/diff/a246f817
Branch: refs/heads/master Commit: a246f8176019cb92a537d001eccd270a94ca29d3 Parents: db163a6 Author: menaka121 <menaka12...@gmail.com> Authored: Thu Jun 11 16:06:49 2015 +0530 Committer: Stian Soiland-Reyes <st...@apache.org> Committed: Thu Jun 11 17:33:29 2015 +0100 ---------------------------------------------------------------------- .../tools/convert/Scufl2Convert.java | 191 +++++++++++++++++++ .../commandline/tools/convert/ToWfbundle.java | 190 ------------------ 2 files changed, 191 insertions(+), 190 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/a246f817/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java ---------------------------------------------------------------------- diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java new file mode 100644 index 0000000..863c7c0 --- /dev/null +++ b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/Scufl2Convert.java @@ -0,0 +1,191 @@ +package org.apache.tavlang.commandline.tools.convert; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.apache.taverna.scufl2.api.container.WorkflowBundle; +import org.apache.taverna.scufl2.api.io.ReaderException; +import org.apache.taverna.scufl2.api.io.WorkflowBundleIO; +import org.apache.taverna.scufl2.api.io.WriterException; +import org.apache.tavlang.commandline.tools.Tools.ConvertionTools; +import org.apache.tavlang.commandline.tools.validate.Validate; + + +/* + * Converts + * .t2flow --> .wfbundle + * .t2flow --> .structure + * .wfbundle --> .structure + * two constructors. + * Scufl2Convert(List<String> list, String out) --> will save the converted files in 'out folder or a directory named /converted in the same folder. + * Scufl2Convert(String in, String out) --> Will convert all the files in the 'in' folder and save them in 'out' folder --> -r must be true. + * + * */ +public class Scufl2Convert{ + + private ConvertionTools t; + private String MEDIA_TYPE; + private String input; + private String output; + private String type; + private List<String> filesList; + + public Scufl2Convert(String type, List<String> files, String out){ + this.filesList = files; + this.output = out; + this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type; + this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t); + this.convert(); + } + + //When recursive case is on.... + public Scufl2Convert(String type, String in, String out){ + this.input = in; + this.output = out; + this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type; + this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t); //Determine the writer media type + + this.createdir(); + } + + //Create the dir if not exists + public void createdir(){ + if(output == null){ + File outFile = new File(this.input, "converted"); + try { + FileUtils.forceMkdir(outFile); + this.output = outFile.getAbsolutePath(); + } catch (IOException e1) { + // TODO Auto-generated catch block + System.err.println("Error creating the directory...!!!!"); + e1.printStackTrace(); + } + }else{ + File outFile = new File(this.output); + try { + FileUtils.forceMkdir(outFile); + + } catch (IOException e1) { + // TODO Auto-generated catch block + System.err.println("Error creating the directory...!!!!"); + e1.printStackTrace(); + } + } + this.rec_convert(this.input); + } + + //Convert the given file. Return in case of an exception. + public boolean convert(){ + + boolean check = false; + // If the output folder is given, save the converted files in to that folder. + + if(this.filesList.size()>0 && this.output != null){ + File outFile = new File(this.output); + try { + FileUtils.forceMkdir(outFile); + } catch (IOException e1) { + System.err.println("Error creating the directory...!!!"); + } + for(String file : this.filesList){ + File t2File = new File(file); + + convertFile(t2File, outFile); + + } + + } + + /* If the output file is not given, save the converted files in + * '/converted' folder. + */ + + else if(this.filesList.size()>0 && this.output == null){ + for(String file : this.filesList){ + File t2File = new File(file); + + File outFile = new File(t2File.getParentFile(), "converted"); + try { + FileUtils.forceMkdir(outFile); + } catch (IOException e1) { + System.err.println("Error creating the directory...!!!"); + } + + convertFile(t2File, outFile); + + } + }else{ + System.err.println("Argument mismatch"); + check = false; + } + + return check; + } + + //Convert the files in a given directory and save the converted files in to specified dir or /converted folder. + //Recursive conversion + public void rec_convert(String dir){ + + File parent = new File(this.input); + if(!parent.exists()){ + System.err.println("Input directory not found"); + }else{ + for(File file : parent.listFiles()){ + if(file.isDirectory()) + rec_convert(file.getAbsolutePath()); + else{ + File outFile = new File(this.output); + convertFile(file, outFile); + } + } + } + } + + //Convert the file + public void convertFile(File t2File, File outFile){ + WorkflowBundleIO wfbio = new WorkflowBundleIO(); + String filename = t2File.getName(); + filename = filename.replaceFirst("\\..*", this.type); +// System.out.println(filename); + File scufl2File = new File(outFile.getAbsolutePath(), filename); + + WorkflowBundle wfBundle; + try { + wfBundle = wfbio.readBundle(t2File, null);// null --> will guess the media type for reading. + wfbio.writeBundle(wfBundle, scufl2File, this.MEDIA_TYPE); + System.out.println(scufl2File.getPath() + " is created."); + }catch (ReaderException e){ + System.err.println(e.getLocalizedMessage()); +// e.printStackTrace(); + }catch(IOException e){ + System.err.println(e.getLocalizedMessage()); +// e.printStackTrace(); + }catch(WriterException e) { + System.err.println(e.getLocalizedMessage()); +// e.printStackTrace(); + } + } + + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/a246f817/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToWfbundle.java ---------------------------------------------------------------------- diff --git a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToWfbundle.java b/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToWfbundle.java deleted file mode 100644 index 0127506..0000000 --- a/taverna-language-commandline/src/main/java/org/apache/tavlang/commandline/tools/convert/ToWfbundle.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.apache.tavlang.commandline.tools.convert; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.io.ReaderException; -import org.apache.taverna.scufl2.api.io.WorkflowBundleIO; -import org.apache.taverna.scufl2.api.io.WriterException; -import org.apache.tavlang.commandline.tools.Tools.ConvertionTools; - - -/* - * Converts - * .t2flow --> .wfbundle - * .t2flow --> .structure - * .wfbundle --> .structure - * two constructors. - * ToWfbundle(List<String> list, String out) --> will save the converted files in 'out folder or a directory named /converted in the same folder. - * ToWfbundle(String in, String out) --> Will convert all the files in the 'in' folder and save them in 'out' folder --> -r must be true. - * - * */ -public class ToWfbundle{ - - private ConvertionTools t; - private String MEDIA_TYPE; - private String input; - private String output; - private String type; - private List<String> filesList; - - public ToWfbundle(String type, List<String> files, String out){ - this.filesList = files; - this.output = out; - this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type; - this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t); - this.convert(); - } - - //When recursive case is on.... - public ToWfbundle(String type, String in, String out){ - this.input = in; - this.output = out; - this.type = type.equals("wfdesc")?".wfdesc.ttl":"."+type; - this.MEDIA_TYPE = ConvertionTools.valueOf(type).getMediaType(t); //Determine the writer media type - - this.createdir(); - } - - //Create the dir if not exists - public void createdir(){ - if(output == null){ - File outFile = new File(this.input, "converted"); - try { - FileUtils.forceMkdir(outFile); - this.output = outFile.getAbsolutePath(); - } catch (IOException e1) { - // TODO Auto-generated catch block - System.err.println("Error creating the directory...!!!!"); - e1.printStackTrace(); - } - }else{ - File outFile = new File(this.output); - try { - FileUtils.forceMkdir(outFile); - - } catch (IOException e1) { - // TODO Auto-generated catch block - System.err.println("Error creating the directory...!!!!"); - e1.printStackTrace(); - } - } - this.rec_convert(this.input); - } - - //Convert the given file. Return in case of an exception. - public boolean convert(){ - - boolean check = false; - // If the output folder is given, save the converted files in to that folder. - - if(this.filesList.size()>0 && this.output != null){ - File outFile = new File(this.output); - try { - FileUtils.forceMkdir(outFile); - } catch (IOException e1) { - System.err.println("Error creating the directory...!!!"); - } - for(String file : this.filesList){ - File t2File = new File(file); - - convertFile(t2File, outFile); - - } - - } - - /* If the output file is not given, save the converted files in - * '/converted' folder. - */ - - else if(this.filesList.size()>0 && this.output == null){ - for(String file : this.filesList){ - File t2File = new File(file); - - File outFile = new File(t2File.getParentFile(), "converted"); - try { - FileUtils.forceMkdir(outFile); - } catch (IOException e1) { - System.err.println("Error creating the directory...!!!"); - } - - convertFile(t2File, outFile); - - } - }else{ - System.err.println("Argument mismatch"); - check = false; - } - - return check; - } - - //Convert the files in a given directory and save the converted files in to specified dir or /converted folder. - //Recursive conversion - public void rec_convert(String dir){ - - File parent = new File(this.input); - if(!parent.exists()){ - System.err.println("Input directory not found"); - }else{ - for(File file : parent.listFiles()){ - if(file.isDirectory()) - rec_convert(file.getAbsolutePath()); - else{ - File outFile = new File(this.output); - convertFile(file, outFile); - } - } - } - } - - //Convert the file - public void convertFile(File t2File, File outFile){ - WorkflowBundleIO wfbio = new WorkflowBundleIO(); - String filename = t2File.getName(); - filename = filename.replaceFirst("\\..*", this.type); - System.out.println(filename); - File scufl2File = new File(outFile.getAbsolutePath(), filename); - - WorkflowBundle wfBundle; - try { - wfBundle = wfbio.readBundle(t2File, null); // null --> will guess the media type for reading. - wfbio.writeBundle(wfBundle, scufl2File, this.MEDIA_TYPE); - System.out.println(scufl2File.getPath() + " is created."); - }catch (ReaderException e){ - System.err.println("Error reading the file"); - e.printStackTrace(); - }catch(IOException e){ - System.err.println("Error reading the file"); - e.printStackTrace(); - }catch(WriterException e) { - System.err.println("Error writing the file"); - e.printStackTrace(); - } - } - - -}