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();
}
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;
}
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();
}
}
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);
}
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);
}
}
}
}
Aggregations