コード例 #1
0
 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);
   }
 }
コード例 #2
0
  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;
    }*/
  }