public boolean createFiles(EObject endpoint, String name, String fileURI1, String fileURI2) { /* Resource diagram; String basePath = "platform:/resource/" + currentProject.getName() + "/" + COMPLEX_ENDPOINT_RESOURCE_DIR + "/";*/ IProject currentProject = getActiveProject(); /* IFile file = currentProject.getFile(COMPLEX_ENDPOINT_RESOURCE_DIR + "/" + fileURI1);*/ IFile fileTobeOpened = null; // if (!file.exists()) { try { IFolder iFolder = currentProject.getFolder(SYNAPSE_CONFIG_DIR + "/complex-endpoints/"); if (!iFolder.exists()) { iFolder.create(IResource.NONE, true, null); } fileTobeOpened = iFolder.getFile( name + ".xml"); // currentProject.getFile(SYNAPSE_CONFIG_DIR + "/complex-endpoints/" + // name + ".xml"); if (fileTobeOpened.exists()) { OpenEditorUtils oeUtils = new OpenEditorUtils(); oeUtils.openSeparateEditor(fileTobeOpened); } else { String path = fileTobeOpened.getParent().getFullPath() + "/"; ArtifactTemplate complexEndpointArtifactTemplate = null; ArtifactTemplate[] endpointTemplates = getEndpointTemplates(); if (endpoint instanceof FailoverEndPoint) { complexEndpointArtifactTemplate = endpointTemplates[4]; } else if (endpoint instanceof LoadBalanceEndPoint) { complexEndpointArtifactTemplate = endpointTemplates[5]; } else if (endpoint instanceof RecipientListEndPoint) { complexEndpointArtifactTemplate = endpointTemplates[6]; } fileTobeOpened.create( complexEndpointArtifactTemplate.getTemplateDataStream(), true, new NullProgressMonitor()); String source = org.wso2.developerstudio.eclipse.utils.file.FileUtils.getContentAsString( complexEndpointArtifactTemplate.getTemplateDataStream()); source = source.replaceAll("\\{", "<").replaceAll("\\}", ">"); source = StringUtils.replace(source, "<ep.name>", name); source = MessageFormat.format(source, name); Openable openable = ESBGraphicalEditor.getOpenable(); openable.editorOpen( fileTobeOpened.getName(), ArtifactType.ENDPOINT.getLiteral(), path, source); } } catch (Exception e) { log.error("Cannot open file " + fileTobeOpened, e); return false; } String path = fileTobeOpened.getParent().getFullPath() + "/"; /* diagram = EsbDiagramEditorUtil.createResource( URI.createURI(basePath + fileURI1), URI.createURI(basePath + fileURI2), new NullProgressMonitor(), "complex_endpoint", name, null);*/ /* String source; try { source = FileUtils.readFileToString(fileTobeOpened.getLocation().toFile()); Openable openable = ESBGraphicalEditor.getOpenable(); openable.editorOpen(fileTobeOpened.getName(), ArtifactType.COMPLEX_ENDPOINT.getLiteral(), path, source); } catch (IOException e1) { log.error("Error while reading the file : "+fileTobeOpened, e1); return false; } catch (Exception e) { log.error("Error while opening the file : "+fileTobeOpened, e); return false; } */ /* try { EsbDiagramEditorUtil.openDiagram(diagram); } catch (PartInitException e) { log.error("Cannot init editor", e); }*/ return true; // } /* else { IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IEditorDescriptor desc = PlatformUI.getWorkbench() .getEditorRegistry().getDefaultEditor(file.getName()); try { page.openEditor(new FileEditorInput(file), desc.getId()); } catch (PartInitException e) { log.error("Cannot init editor", e); } return true; }*/ }
private boolean createSequenceArtifact(TemplateModel sequenceModel) throws Exception { boolean isNewArtifact = true; IContainer location = project.getFolder( "src" + File.separator + "main" + File.separator + "synapse-config" + File.separator + "templates"); esbProjectArtifact = new ESBProjectArtifact(); esbProjectArtifact.fromFile(project.getFile("artifact.xml").getLocation().toFile()); File pomfile = project.getFile("pom.xml").getLocation().toFile(); getModel().getMavenInfo().setPackageName("synapse/template"); if (!pomfile.exists()) { createPOM(pomfile); } updatePom(); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); String groupId = getMavenGroupId(pomfile); groupId += ".template"; if (getModel().getSelectedOption().equals("import.template")) { IFile sequence = location.getFile(new Path(getModel().getImportFile().getName())); if (sequence.exists()) { if (!MessageDialog.openQuestion( getShell(), "WARNING", "Do you like to override exsiting project in the workspace")) { return false; } isNewArtifact = false; } copyImportFile(location, isNewArtifact, groupId); } else { String templateContent = ""; String template = ""; ArtifactTemplate selectedTemplate = templateModel.getSelectedTemplate(); templateContent = FileUtils.getContentAsString(selectedTemplate.getTemplateDataStream()); if (selectedTemplate.getName().equals("Address Endpoint Template")) { template = createEPTemplate(templateContent, "Address Endpoint Template"); } else if (selectedTemplate.getName().equals("WSDL Endpoint Template")) { template = createEPTemplate(templateContent, "WSDL Endpoint Template"); } else if (selectedTemplate.getName().equals("Default Endpoint Template")) { template = createEPTemplate(templateContent, "Default Endpoint Template"); } else if (selectedTemplate.getName().equals("Sequence Template")) { template = createEPTemplate(templateContent, "Sequence Template"); } else if (selectedTemplate.getName().equals("HTTP Endpoint Template")) { template = createEPTemplate(templateContent, "HTTP Endpoint Template"); } else { template = createEPTemplate(templateContent, ""); } File destFile = new File(location.getLocation().toFile(), sequenceModel.getTemplateName() + ".xml"); FileUtils.createFile(destFile, template); fileLst.add(destFile); ESBArtifact artifact = new ESBArtifact(); artifact.setName(sequenceModel.getTemplateName()); artifact.setVersion(version); if ("Sequence Template".equals(selectedTemplate.getName())) { artifact.setType("synapse/sequenceTemplate"); } else { artifact.setType("synapse/endpointTemplate"); } artifact.setServerRole("EnterpriseServiceBus"); artifact.setGroupId(groupId); artifact.setFile( FileUtils.getRelativePath( project.getLocation().toFile(), new File( location.getLocation().toFile(), sequenceModel.getTemplateName() + ".xml")) .replaceAll(Pattern.quote(File.separator), "/")); esbProjectArtifact.addESBArtifact(artifact); } esbProjectArtifact.toFile(); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); return true; }