Search in sources :

Example 36 with Bundle

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;
}
Also used : Path(org.eclipse.core.runtime.Path) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) Bundle(org.osgi.framework.Bundle) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) URL(java.net.URL) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) File(java.io.File)

Example 37 with Bundle

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;
}
Also used : Path(org.eclipse.core.runtime.Path) ErrorHandler(org.xml.sax.ErrorHandler) XMLSerializer(com.sun.org.apache.xml.internal.serialize.XMLSerializer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) Bundle(org.osgi.framework.Bundle) Element(org.w3c.dom.Element) FileWriter(java.io.FileWriter) OutputFormat(com.sun.org.apache.xml.internal.serialize.OutputFormat) Document(org.w3c.dom.Document) URL(java.net.URL) Attr(org.w3c.dom.Attr) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) File(java.io.File)

Example 38 with Bundle

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);
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) EventHandler(org.osgi.service.event.EventHandler) IRepositoryService(org.talend.repository.model.IRepositoryService) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) BusinessException(org.talend.commons.exception.BusinessException) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) Event(org.osgi.service.event.Event) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Display(org.eclipse.swt.widgets.Display)

Example 39 with Bundle

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;
}
Also used : Path(org.eclipse.core.runtime.Path) MalformedURLException(java.net.MalformedURLException) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 40 with Bundle

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);
    }
}
Also used : StormJavaProcessor(org.talend.designer.runprocess.storm.StormJavaProcessor) MavenJavaProcessor(org.talend.designer.runprocess.maven.MavenJavaProcessor) MapReduceJavaProcessor(org.talend.designer.runprocess.mapreduce.MapReduceJavaProcessor) Bundle(org.osgi.framework.Bundle) Constructor(java.lang.reflect.Constructor) SparkJavaProcessor(org.talend.designer.runprocess.spark.SparkJavaProcessor) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) CoreException(org.eclipse.core.runtime.CoreException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

Bundle (org.osgi.framework.Bundle)2527 Test (org.junit.Test)674 URL (java.net.URL)389 BundleContext (org.osgi.framework.BundleContext)319 ArrayList (java.util.ArrayList)299 File (java.io.File)298 IOException (java.io.IOException)281 BundleException (org.osgi.framework.BundleException)273 HashMap (java.util.HashMap)155 ServiceReference (org.osgi.framework.ServiceReference)152 Hashtable (java.util.Hashtable)131 Path (org.eclipse.core.runtime.Path)126 HashSet (java.util.HashSet)98 InputStream (java.io.InputStream)94 List (java.util.List)87 IStatus (org.eclipse.core.runtime.IStatus)86 Status (org.eclipse.core.runtime.Status)82 Map (java.util.Map)74 BundleWiring (org.osgi.framework.wiring.BundleWiring)74 Version (org.osgi.framework.Version)73