/** * <copyright> * </copyright> * * */ package robot.resource.robot.mopp; public class RobotNewFileContentProvider { public robot.resource.robot.IRobotMetaInformation getMetaInformation() { return new robot.resource.robot.mopp.RobotMetaInformation(); } public String getNewFileContent(String newFileName) { return getExampleContent(new org.eclipse.emf.ecore.EClass[] { robot.robot.RobotPackage.eINSTANCE.getProgramUnit(), }, getMetaInformation().getClassesWithSyntax(), newFileName); } protected String getExampleContent(org.eclipse.emf.ecore.EClass[] startClasses, org.eclipse.emf.ecore.EClass[] allClassesWithSyntax, String newFileName) { String content = ""; for (org.eclipse.emf.ecore.EClass next : startClasses) { content = getExampleContent(next, allClassesWithSyntax, newFileName); if (content.trim().length() > 0) { break; } } return content; } protected String getExampleContent(org.eclipse.emf.ecore.EClass eClass, org.eclipse.emf.ecore.EClass[] allClassesWithSyntax, String newFileName) { // create a minimal model org.eclipse.emf.ecore.EObject root = new robot.resource.robot.util.RobotMinimalModelHelper().getMinimalModel(eClass, allClassesWithSyntax, newFileName); if (root == null) { // could not create a minimal model. returning an empty document is the best we // can do. return ""; } // use printer to get text for model java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream(); robot.resource.robot.IRobotTextPrinter printer = getPrinter(buffer); try { printer.print(root); } catch (java.io.IOException e) { new robot.resource.robot.util.RobotRuntimeUtil().logError("Exception while generating example content.", e); } return buffer.toString(); } public robot.resource.robot.IRobotTextPrinter getPrinter(java.io.OutputStream outputStream) { return getMetaInformation().createPrinter(outputStream, new robot.resource.robot.mopp.RobotResource()); } }