use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class ExpressionFileOperation method importExpressionFromFile.
/**
* yzhang Comment method "getExpressionFromFile".
*
* @param file
* @return
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
*/
public List importExpressionFromFile(File file, Shell shell) throws IOException, ParserConfigurationException, SAXException {
if (file != null) {
List list = new ArrayList();
if (!file.isFile()) {
openDialog(shell);
return list;
} else {
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
final Bundle b = Platform.getBundle(PLUGIN_ID);
final URL url = FileLocator.toFileURL(FileLocator.find(b, new Path(SCHEMA_XSD), null));
final File schema = new File(url.getPath());
final Document document = XSDValidator.checkXSD(file, schema);
final NodeList expressionNodes = document.getElementsByTagName(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.expression"));
if (expressionNodes.getLength() == 1) {
Node expressionNode = expressionNodes.item(0);
NamedNodeMap epxressionAttrs = expressionNode.getAttributes();
Node contentNode = epxressionAttrs.getNamedItem(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.content"));
list.add(contentNode.getNodeValue());
}
final NodeList variableNodes = document.getElementsByTagName(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.variable"));
for (int i = 0; i < variableNodes.getLength(); i++) {
Node variableNode = variableNodes.item(i);
NamedNodeMap varAttrs = variableNode.getAttributes();
//$NON-NLS-1$
Node nameNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.name"));
//$NON-NLS-1$
Node valueNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.value"));
Node talendTypeNode = varAttrs.getNamedItem(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.talendType"));
//$NON-NLS-1$
Node nullableNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.nullable"));
Variable variable = new Variable();
variable.setName(nameNode.getNodeValue());
variable.setValue(valueNode.getNodeValue());
variable.setTalendType(talendTypeNode.getNodeValue());
String s = nullableNode.getNodeValue();
Boolean boo = Boolean.valueOf(s);
if (boo == null) {
boo = false;
}
variable.setNullable(boo);
list.add(variable);
}
return list;
}
}
return null;
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class ExpressionFileOperation method saveExpressionToFile.
/**
* yzhang Comment method "savingExpression".
*
* @return
* @throws IOException
* @throws ParserConfigurationException
*/
public boolean saveExpressionToFile(File file, List<Variable> variables, String expressionContent) throws IOException, ParserConfigurationException {
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
final Bundle b = Platform.getBundle(PLUGIN_ID);
final URL url = FileLocator.toFileURL(FileLocator.find(b, new Path(SCHEMA_XSD), null));
final File schema = new File(url.getPath());
//$NON-NLS-1$
fabrique.setAttribute(SCHEMA_LANGUAGE, "http://www.w3.org/2001/XMLSchema");
fabrique.setAttribute(SCHEMA_VALIDATOR, schema);
fabrique.setValidating(true);
final DocumentBuilder analyseur = fabrique.newDocumentBuilder();
analyseur.setErrorHandler(new ErrorHandler() {
public void error(final SAXParseException exception) throws SAXException {
throw exception;
}
public void fatalError(final SAXParseException exception) throws SAXException {
throw exception;
}
public void warning(final SAXParseException exception) throws SAXException {
throw exception;
}
});
Document document = analyseur.newDocument();
//$NON-NLS-1$
Element expressionElement = document.createElement("expression");
document.appendChild(expressionElement);
//$NON-NLS-1$
Attr content = document.createAttribute(Messages.getString("ExpressionFileOperation.content"));
content.setNodeValue(expressionContent);
expressionElement.setAttributeNode(content);
for (Variable variable : variables) {
//$NON-NLS-1$
Element variableElement = document.createElement("variable");
expressionElement.appendChild(variableElement);
//$NON-NLS-1$
Attr name = document.createAttribute(Messages.getString("ExpressionFileOperation.name"));
name.setNodeValue(variable.getName());
variableElement.setAttributeNode(name);
//$NON-NLS-1$
Attr value = document.createAttribute(Messages.getString("ExpressionFileOperation.value"));
value.setNodeValue(variable.getValue());
variableElement.setAttributeNode(value);
//$NON-NLS-1$
Attr talendType = document.createAttribute(Messages.getString("ExpressionFileOperation.talendType"));
//$NON-NLS-1$
talendType.setNodeValue(variable.getTalendType());
variableElement.setAttributeNode(talendType);
//$NON-NLS-1$
Attr nullable = document.createAttribute(Messages.getString("ExpressionFileOperation.nullable"));
//$NON-NLS-1$
nullable.setNodeValue(String.valueOf(variable.isNullable()));
variableElement.setAttributeNode(nullable);
}
// use specific Xerces class to write DOM-data to a file:
XMLSerializer serializer = new XMLSerializer();
OutputFormat outputFormat = new OutputFormat();
outputFormat.setIndenting(true);
serializer.setOutputFormat(outputFormat);
FileWriter writer = new FileWriter(file);
serializer.setOutputCharStream(writer);
serializer.serialize(document);
writer.close();
return true;
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method init.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.MultiPageEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
*/
@Override
public void init(final IEditorSite site, IEditorInput editorInput) throws PartInitException {
setSite(site);
setInput(editorInput);
if (!(editorInput instanceof JobEditorInput)) {
return;
}
site.setSelectionProvider(new MultiPageTalendSelectionProvider(this));
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
// Lock the process :
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
processEditorInput = (JobEditorInput) editorInput;
final IProcess2 currentProcess = processEditorInput.getLoadedProcess();
if (!currentProcess.isReadOnly()) {
try {
Property property = processEditorInput.getItem().getProperty();
propertyInformation = new ArrayList(property.getInformations());
property.eAdapters().add(dirtyListener);
repFactory.lock(currentProcess);
boolean locked = repFactory.getStatus(currentProcess) == ERepositoryStatus.LOCK_BY_USER;
if (!locked) {
setReadOnly(true);
}
revisionChanged = true;
} catch (PersistenceException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (BusinessException e) {
// Nothing to do
ExceptionHandler.process(e);
}
} else {
setReadOnly(true);
Bundle bundle = FrameworkUtil.getBundle(AbstractMultiPageTalendEditor.class);
final Display display = getSite().getShell().getDisplay();
this.lockService = bundle.getBundleContext().registerService(EventHandler.class.getName(), new EventHandler() {
@Override
public void handleEvent(Event event) {
String lockTopic = Constant.REPOSITORY_ITEM_EVENT_PREFIX + Constant.ITEM_LOCK_EVENT_SUFFIX;
if (lockTopic.equals(event.getTopic())) {
Object o = event.getProperty(Constant.ITEM_EVENT_PROPERTY_KEY);
if (o != null && o instanceof Item) {
Item item = (Item) o;
String itemId = item.getProperty().getId();
if (itemId.equals(currentProcess.getId())) {
if (currentProcess.isReadOnly()) {
boolean readOnly = currentProcess.checkReadOnly();
boolean orginalReadOnlyStatus = designerEditor.isReadOnly();
setReadOnly(readOnly);
if (!readOnly) {
display.asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
}
});
if (orginalReadOnlyStatus == true) {
// refresh to the given item version, nomally it is the latest
// version,
// means the editor/process will be refreshed to the latest version
refreshProcess(item, false);
}
Property property = processEditorInput.getItem().getProperty();
propertyInformation = new ArrayList(property.getInformations());
property.eAdapters().add(dirtyListener);
}
}
}
}
}
}
}, new Hashtable<String, String>(Collections.singletonMap(EventConstants.EVENT_TOPIC, //$NON-NLS-1$
Constant.REPOSITORY_ITEM_EVENT_PREFIX + "*")));
revisionChanged = true;
}
// setTitleImage(ImageProvider.getImage(getEditorTitleImage()));
updateTitleImage(processEditorInput.getItem().getProperty());
getSite().getWorkbenchWindow().getPartService().addPartListener(partListener);
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class MapperComponentDocumentation method getHTMLFile.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.process.IComponentDocumentation#getHTMLFile()
*/
public URL getHTMLFile() {
String xmlFilepath = this.tempFolderPath + File.separatorChar + this.componentName + IHTMLDocConstants.XML_FILE_SUFFIX;
String htmlFilePath = this.tempFolderPath + File.separatorChar + this.componentName + IHTMLDocConstants.HTML_FILE_SUFFIX;
final Bundle b = Platform.getBundle(PluginUtils.PLUGIN_ID);
URL xslFileUrl = null;
try {
xslFileUrl = FileLocator.toFileURL(FileLocator.find(b, new Path(IHTMLDocConstants.TMAP_XSL_FILE_PATH), null));
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
ExceptionHandler.process(e);
}
String xslFilePath = xslFileUrl.getPath();
generateXMLInfo(getExternalNode());
XMLHandler.generateXMLFile(tempFolderPath, xmlFilepath, document);
HTMLHandler.generateHTMLFile(this.tempFolderPath, xslFilePath, xmlFilepath, htmlFilePath);
File htmlFile = new File(htmlFilePath);
if (htmlFile.exists()) {
try {
return htmlFile.toURL();
} catch (MalformedURLException e) {
ExceptionHandler.process(e);
}
}
return null;
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class DefaultRunProcessService method createJavaProcessor.
/**
* DOC xue Comment method "createJavaProcessor".
*
* @param process
* @param filenameFromLabel
* @return
*/
protected IProcessor createJavaProcessor(IProcess process, Property property, boolean filenameFromLabel) {
boolean isTestContainer = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null && property != null && property.getItem() != null) {
isTestContainer = testContainerService.isTestContainerItem(property.getItem());
}
}
if (isTestContainer) {
return new MavenJavaProcessor(process, property, filenameFromLabel);
}
// check for ESB Runtime
if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBRunContainerService.class)) {
IESBRunContainerService runContainerService = (IESBRunContainerService) GlobalServiceRegister.getDefault().getService(IESBRunContainerService.class);
if (runContainerService != null) {
IProcessor processor = runContainerService.createJavaProcessor(process, property, filenameFromLabel);
if (processor != null) {
return processor;
}
}
}
if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType())) {
return new MapReduceJavaProcessor(process, property, filenameFromLabel);
} else if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType())) {
return new SparkJavaProcessor(process, property, filenameFromLabel);
} else if (ComponentCategory.CATEGORY_4_STORM.getName().equals(process.getComponentsType())) {
return new StormJavaProcessor(process, property, filenameFromLabel);
} else if (ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
return new SparkJavaProcessor(process, property, filenameFromLabel);
} else if (ComponentCategory.CATEGORY_4_CAMEL.getName().equals(process.getComponentsType())) {
Bundle bundle = Platform.getBundle(PluginChecker.EXPORT_ROUTE_PLUGIN_ID);
if (bundle != null) {
try {
Class camelJavaProcessor = bundle.loadClass("org.talend.resources.export.maven.runprocess.CamelJavaProcessor");
Constructor constructor = camelJavaProcessor.getConstructor(IProcess.class, Property.class, boolean.class);
return (MavenJavaProcessor) constructor.newInstance(process, property, filenameFromLabel);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
return new MavenJavaProcessor(process, property, filenameFromLabel);
} else {
return new MavenJavaProcessor(process, property, filenameFromLabel);
}
}
Aggregations