Version Differences for Miscellaneous Scripts

(AHPSCRIPTS-103)
(AHPSCRIPTS-111)
Line 2124:
  }     }  
  }</pre>    }</pre> 
       
    + = Export Project Configuration to XML Using Beanshell or Remoting Script =  
       
    + ==== AHPSCRIPTS-9 ====  
       
    + <pre>import org.w3c.dom.Document;  
    + import com.urbancode.anthill3.domain.project.Project;  
    + import com.urbancode.anthill3.domain.project.ProjectFactory;  
    + import com.urbancode.anthill3.domain.xml.XMLImporterExporter;  
    + import com.urbancode.commons.xml.DOMUtils;  
       
    + String PROJECT_NAME = ".....";  
       
    + Project project = ProjectFactory.getInstance().restoreForName(PROJECT_NAME);  
    + Document doc = XMLImporterExporter.exportXML(project, "project");  
    + String xmlString = DOMUtils.documentToString(doc);</pre>  
       
    + * A working case that is based off of having a workflow property entered at run-time which the user can specify a project name to export. Needs thrown in an evaluate step:  
    + <pre>/*------------------------------------------------------*/  
    + /* Set this script up as an an evaluate script step in */  
    + /* an operational workflow within an operational */  
    + /* project. You will then need to set up a property on */  
    + /* the workflow called 'ProjectName' to pass in the */  
    + /* project you would like to export. Finally, this */  
    + /* script's output will be placed in the */  
    + /* %SERVER_HOME%\bin directory unless otherwise noted */  
    + /* by setting a working directory */  
    + /*------------------------------------------------------*/  
       
    + import org.w3c.dom.Document;  
    + import com.urbancode.anthill3.runtime.scripting.helpers.*;  
    + import com.urbancode.anthill3.domain.project.Project;  
    + import com.urbancode.anthill3.domain.project.ProjectFactory;  
    + import com.urbancode.anthill3.domain.xml.XMLImporterExporter;  
    + import com.urbancode.commons.xml.DOMUtils;  
    + import java.io.*;  
       
    + //Set a property on the operational workflow called 'ProjectName'  
    + //so that you can input which project name you want to run this  
    + //script on. Alternatively, you could remove the references to  
    + //a property and just substitute in a string.  
    + String PROJECT_NAME = PropertyLookup.getValue("ProjectName");  
       
    + //Restores the property and writes to a string  
    + Project project = ProjectFactory.getInstance().restoreForName(PROJECT_NAME);  
    + Document doc = XMLImporterExporter.exportXML(project, "project");  
    + String xmlString = DOMUtils.documentToString(doc);  
       
    + //Writes the xmlString to a file determined by the project name  
    + //and appends '.xml' to the export.  
    + FileWriter outFile = new FileWriter(PathHelper.makeSafe(PropertyLookup.getValue("ProjectName"))+".xml");  
    + BufferedWriter buffer = new BufferedWriter(outFile);  
    + PrintWriter out = new PrintWriter(buffer);  
    + out.println(xmlString);  
    + out.flush();  
    + out.close();</pre>  
       
    + * This should export the dependencies to an XML file.  
    + <pre>/*------------------------------------------------------*/  
    + /* Set this script up as an an evaluate script step in */  
    + /* an operational workflow within an operational */  
    + /* project. You will then need to set up a property on */  
    + /* the workflow called 'ProjectName' to pass in the */  
    + /* project you would like to export. Finally, this */  
    + /* script's output will be placed in the */  
    + /* %SERVER_HOME%\bin directory unless otherwise noted */  
    + /* by setting a working directory. This script will */  
    + /* export the dependency configuration on the current */  
    + /* project. */  
    + /*------------------------------------------------------*/  
       
    + import org.w3c.dom.Document;  
    + import com.urbancode.anthill3.runtime.scripting.helpers.*;  
    + import com.urbancode.anthill3.domain.project.*;  
    + import com.urbancode.anthill3.domain.xml.XMLImporterExporter;  
    + import com.urbancode.anthill3.domain.xml.*;  
    + import com.urbancode.commons.xml.*;  
    + import com.urbancode.anthill3.domain.profile.*;  
    + import com.urbancode.anthill3.domain.workflow.*;  
    + import java.io.*;  
       
    + //Set a property on the operational workflow called 'ProjectName'  
    + //so that you can input which project name you want to run this  
    + //script on. Alternatively, you could remove the references to  
    + //a property and just substitute in a string.  
    + String PROJECT_NAME = PropertyLookup.getValue("ProjectName");  
       
    + //Restores the property and writes to a string  
    + Project project = ProjectFactory.getInstance().restoreForName(PROJECT_NAME);  
    + Document doc = XMLImporterExporter.exportXML(project, "project");  
    + String xmlString = DOMUtils.documentToString(doc);  
       
    + //Writes the xmlString to a file determined by the project name  
    + //and appends '.xml' to the export.  
    + DependencyXml depXml = new DependencyXml();  
    + String pDep = depXml.exportDependencies(project);  
       
    + FileWriter outFile = new FileWriter(PathHelper.makeSafe(PropertyLookup.getValue("ProjectName"))+"_dependencies.xml");  
    + BufferedWriter buffer = new BufferedWriter(outFile);  
    + PrintWriter out = new PrintWriter(buffer);  
    + out.println(pDep);  
    + out.flush();  
    + out.close();</pre>