Search in sources :

Example 21 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method initFileContent.

/*
     * same as XmlFileOutputStep2Form.initXmlTreeData()
     */
private String initFileContent(XmlFileConnection connection) throws IOException {
    byte[] bytes = connection.getFileContent();
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = null;
    try {
        fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
    } catch (PersistenceException e2) {
        ExceptionHandler.process(e2);
    }
    if (fsProject == null) {
        return null;
    }
    String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp";
    String fileName = "";
    String pathStr = connection.getXmlFilePath();
    if (connection.isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection, true);
        pathStr = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, pathStr));
    }
    if (pathStr != null && XmlUtil.isXMLFile(pathStr)) {
        fileName = StringUtil.TMP_XML_FILE;
    } else if (pathStr != null && XmlUtil.isXSDFile(pathStr)) {
        fileName = StringUtil.TMP_XSD_FILE;
    } else if (pathStr != null && XmlUtil.isWSDLFile(pathStr)) {
        fileName = StringUtil.TMP_WSDL_FILE;
    } else if (pathStr.contains(".zip")) {
        fileName = new Path(pathStr).lastSegment();
    } else {
        return null;
    }
    File temfile = new File(temPath + File.separator + fileName);
    if (!temfile.exists()) {
        temfile.createNewFile();
    }
    FileOutputStream outStream;
    outStream = new FileOutputStream(temfile);
    outStream.write(bytes);
    outStream.close();
    return temfile.getPath();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) FileOutputStream(java.io.FileOutputStream) PersistenceException(org.talend.commons.exception.PersistenceException) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 22 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class JSONUtil method changeJsonToXml.

public static String changeJsonToXml(String jsonPath) {
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = null;
    try {
        fsProject = ResourceUtils.getProject(project);
    } catch (PersistenceException e2) {
        ExceptionHandler.process(e2);
    }
    if (fsProject == null) {
        return jsonPath;
    }
    String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "jsonwizard" + File.separator;
    ConvertJSONString convertJSON = new ConvertJSONString();
    de.odysseus.staxon.json.JsonXMLConfig jsonConfig = new de.odysseus.staxon.json.JsonXMLConfigBuilder().multiplePI(false).build();
    de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory = new de.odysseus.staxon.json.JsonXMLInputFactory(jsonConfig);
    javax.xml.stream.XMLOutputFactory xmlOutputFactory = javax.xml.stream.XMLOutputFactory.newInstance();
    java.io.ByteArrayOutputStream outStream = new java.io.ByteArrayOutputStream();
    InputStream inStream = null;
    File file = new File(jsonPath);
    // String filename = file.getName().replaceAll("\\.", "_");
    // filename = "tempTest";
    boolean isFromUrl = false;
    boolean illegalURL = false;
    InputStream input = null;
    if (file.exists()) {
        if (file.isDirectory()) {
            return "";
        }
        try {
            input = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            ExceptionHandler.process(e);
        }
    } else {
        isFromUrl = true;
        try {
            input = new URL(jsonPath).openStream();
        } catch (MalformedURLException e) {
            illegalURL = true;
        } catch (IOException e) {
            illegalURL = true;
        }
        if (illegalURL) {
            return "";
        }
    }
    try {
        String jsonStr = IOUtils.toString(input);
        convertJSON.setJsonString(jsonStr);
        convertJSON.generate();
        jsonStr = convertJSON.getJsonString4XML();
        inStream = new ByteArrayInputStream(jsonStr.getBytes());
        javax.xml.stream.XMLEventReader xmlEventReader = jsonXMLInputFactory.createXMLEventReader(inStream);
        javax.xml.stream.XMLEventWriter xmLEventWriter = xmlOutputFactory.createXMLEventWriter(outStream);
        xmLEventWriter.add(xmlEventReader);
        String xmlStr = outStream.toString();
        File xmlFolder = new File(temPath);
        if (!xmlFolder.exists()) {
            xmlFolder.mkdirs();
        }
        temPath = temPath + TMP_JSON_FILE;
        FileWriter writer = new FileWriter(temPath);
        writer.write(xmlStr);
        writer.flush();
        writer.close();
        xmLEventWriter.close();
        xmlEventReader.close();
        if (isFromUrl) {
            tempJSONXsdPath = temPath;
        }
    } catch (java.lang.Exception e) {
        ExceptionHandler.process(e);
    } finally {
        try {
            outStream.close();
            if (inStream != null) {
                inStream.close();
            }
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
    }
    return temPath;
}
Also used : MalformedURLException(java.net.MalformedURLException) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) FileInputStream(java.io.FileInputStream) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) PersistenceException(org.talend.commons.exception.PersistenceException) File(java.io.File)

Example 23 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class JSONUtil method deleteWizardTempFiles.

public static void deleteWizardTempFiles() {
    tempJSONXsdPath = null;
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = null;
    try {
        fsProject = ResourceUtils.getProject(project);
    } catch (PersistenceException e2) {
        ExceptionHandler.process(e2);
    }
    if (fsProject == null) {
        return;
    }
    String tempPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "wizard";
    File tempWizardDir = new File(tempPath);
    tempWizardDir.delete();
    String tempjsonPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "jsonwizard";
    File tempjsonWizardDir = new File(tempjsonPath);
    if (tempjsonWizardDir.exists()) {
        tempjsonWizardDir.delete();
    }
}
Also used : Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) PersistenceException(org.talend.commons.exception.PersistenceException) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 24 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class LoginFirstTimeStartupActionPage method createNewProject.

protected void createNewProject() {
    IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    Context ctx = CorePlugin.getContext();
    RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    Project project = null;
    try {
        Project projectInfor = //$NON-NLS-1$
        ProjectHelper.createProject(//$NON-NLS-1$
        newProjectName.getText().trim().replace(' ', '_'), //$NON-NLS-1$
        "", ECodeLanguage.JAVA.getName(), repositoryContext.getUser());
        project = repositoryFactory.createProject(projectInfor);
    } catch (PersistenceException e) {
        MessageDialog.openError(getShell(), Messages.getString("NewProjectWizard.failureTitle"), //$NON-NLS-1$
        Messages.getString(//$NON-NLS-1$ 
        "NewProjectWizard.failureText"));
        MessageBoxExceptionHandler.process(e);
    }
    if (project == null) {
        return;
    }
    openProject(project);
}
Also used : Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) Project(org.talend.core.model.general.Project) RepositoryContext(org.talend.core.context.RepositoryContext) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 25 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class LoginProjectPage method selectLastUsedProject.

protected void selectLastUsedProject() {
    if (projectViewer != null) {
        Project[] projects = (Project[]) projectViewer.getInput();
        Project project = null;
        if (selectedProjectBeforeRefresh != null) {
            for (Project p : projects) {
                if (selectedProjectBeforeRefresh.equals(p.getLabel())) {
                    project = p;
                    break;
                }
            }
        }
        if (project == null) {
            project = loginHelper.getLastUsedProject(projects);
        }
        if (project == null && projects.length > 0) {
            project = projects[0];
        }
        if (project != null) {
            try {
                selectProject(project);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                ExceptionHandler.process(e);
            }
        }
    }
}
Also used : Project(org.talend.core.model.general.Project) JSONException(org.talend.utils.json.JSONException)

Aggregations

Project (org.talend.core.model.general.Project)160 IProject (org.eclipse.core.resources.IProject)77 PersistenceException (org.talend.commons.exception.PersistenceException)73 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)34 ArrayList (java.util.ArrayList)24 IFolder (org.eclipse.core.resources.IFolder)23 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)23 Property (org.talend.core.model.properties.Property)21 File (java.io.File)20 Path (org.eclipse.core.runtime.Path)19 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)19 IPath (org.eclipse.core.runtime.IPath)18 IOException (java.io.IOException)17 RepositoryContext (org.talend.core.context.RepositoryContext)16 CoreException (org.eclipse.core.runtime.CoreException)14 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)14 IFile (org.eclipse.core.resources.IFile)13 Item (org.talend.core.model.properties.Item)13 User (org.talend.core.model.properties.User)13 Test (org.junit.Test)12