public void openEditor(File file) {
   try {
     refreshDistProjects();
     OMElement documentElement = new StAXOMBuilder(new FileInputStream(file)).getDocumentElement();
     OMElement firstElement = documentElement.getFirstElement();
     String templateType = "template.sequence";
     if ("endpoint".equals(firstElement.getLocalName())) {
       templateType = "template.endpoint";
       String localName = firstElement.getFirstElement().getLocalName();
       if ("address".equals(localName)) {
         templateType = templateType + "-1";
       } else if ("wsdl".equals(localName)) {
         templateType = templateType + "-2";
       } else {
         templateType = templateType + "-0";
       }
     }
     IFile dbsFile =
         ResourcesPlugin.getWorkspace()
             .getRoot()
             .getFileForLocation(Path.fromOSString(file.getAbsolutePath()));
     String path = dbsFile.getParent().getFullPath() + "/";
     String source = FileUtils.getContentAsString(file);
     Openable openable = ESBGraphicalEditor.getOpenable();
     openable.editorOpen(file.getName(), templateType, path + "template_", source);
   } catch (Exception e) {
     log.error("Cannot open the editor", e);
   }
 }
  @Override
  protected File processTokenReplacement(Artifact artifact) {
    File file = artifact.getFile();
    if (file.exists()) {
      String fileContent;
      StringBuffer sb = new StringBuffer();
      try {
        fileContent =
            org.wso2.developerstudio.eclipse.utils.file.FileUtils.getContentAsString(file);
        // StringTokenizer st=new StringTokenizer(fileContent,
        // CAppMavenUtils.REPLACER_DEFAULT_DELIMETER);

        Properties mavenProperties = getProject().getModel().getProperties();
        // Check whether the content actually has tokens and Properties section should define them.
        // Otherwise skip.
        // By default there are 2 such properties. So size check is 2.
        /*if (st.countTokens()>1 && mavenProperties.size()>1) {
        	while (st.hasMoreTokens()) {
        		String nextToken = st.nextToken();
        		if (mavenProperties.containsKey(nextToken)) {
        			String originalToken = nextToken;
        			nextToken = (String) mavenProperties.get(nextToken);
        			getLog().info("Replacing the token: "+originalToken+" with value: "+nextToken);
        		}
        		sb.append(nextToken);
        	}
        }else{
        	sb.append(fileContent);
        }*/

        String newFileContent = replaceTokens(fileContent, mavenProperties);
        File tempFile = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createTempFile();
        // org.wso2.developerstudio.eclipse.utils.file.FileUtils.writeContent(tempFile,
        // sb.toString());
        org.wso2.developerstudio.eclipse.utils.file.FileUtils.writeContent(
            tempFile, newFileContent);
        return tempFile;
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return file;
  }
  public void openEditor(File file) {
    try {
      refreshDistProjects();
      OMElement documentElement = new StAXOMBuilder(new FileInputStream(file)).getDocumentElement();
      String templateType = "";

      if (documentElement.getChildrenWithName(new QName("endpoint")) != null
          && documentElement.getChildrenWithName(new QName("endpoint")).hasNext()) {
        // Endpoint template.
        templateType = ArtifactType.TEMPLATE_ENDPOINT.getLiteral();
        OMElement endpoint =
            (OMElement) documentElement.getChildrenWithName(new QName("endpoint")).next();
        String localName = endpoint.getFirstElement().getLocalName();
        if ("address".equals(localName)) {
          // Address endpoint template.
          templateType = ArtifactType.TEMPLATE_ENDPOINT_ADDRESS.getLiteral();
        } else if ("wsdl".equals(localName)) {
          // WSDL endpoint template.
          templateType = ArtifactType.TEMPLATE_ENDPOINT_WSDL.getLiteral();
        } else if ("http".equals(localName)) {
          // HTTP endpoint template.
          templateType = ArtifactType.TEMPLATE_ENDPOINT_HTTP.getLiteral();
        } else {
          // Default endpoint template.
          templateType = ArtifactType.TEMPLATE_ENDPOINT_DEFAULT.getLiteral();
        }
      } else {
        // Sequence template.
        templateType = ArtifactType.TEMPLATE_SEQUENCE.getLiteral();
      }

      IFile dbsFile =
          ResourcesPlugin.getWorkspace()
              .getRoot()
              .getFileForLocation(Path.fromOSString(file.getAbsolutePath()));
      String path = dbsFile.getParent().getFullPath() + "/";
      String source = FileUtils.getContentAsString(file);
      Openable openable = ESBGraphicalEditor.getOpenable();
      openable.editorOpen(file.getName(), templateType, path, source);
    } catch (Exception e) {
      log.error("Cannot open the editor", e);
    }
  }
  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;
  }