Search in sources :

Example 1 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class LaunchHelper method save.

public void save(File file) throws CoreException {
    BufferedWriter writer = null;
    try {
        // ensure it exists
        file.createNewFile();
        writer = new BufferedWriter(new FileWriter(file));
        PipelineDefinition pdef = new PipelineDefinition();
        for (Iterator<?> iter = attributes.getAttributes().iterator(); iter.hasNext(); ) {
            LaunchAttribute att = (LaunchAttribute) iter.next();
            pdef.addAttribute(new TypedValue(att.uri, TypedValue.TYPE_STRING, att.value));
        }
        for (Iterator<?> iter = pipeline.getTransformDefs().iterator(); iter.hasNext(); ) {
            LaunchTransform lt = (LaunchTransform) iter.next();
            TransformDefinition tdef = new TransformDefinition();
            URL url = pathToURL(lt.getLocation());
            tdef.setStylesheetURL(url.toExternalForm());
            tdef.setResolverClass(lt.getResolver());
            for (Iterator<?> iterator = lt.getParameters().iterator(); iterator.hasNext(); ) {
                LaunchAttribute att = (LaunchAttribute) iterator.next();
                tdef.addParameter(new TypedValue(att.uri, TypedValue.TYPE_STRING, att.getResolvedValue()));
            }
            // set the output props for the LAST transform only
            if (!iter.hasNext()) {
                for (Map.Entry<String, String> entry : outputProperties.getProperties().entrySet()) {
                    String name = entry.getKey();
                    String value = entry.getValue();
                    if (name != null && value != null)
                        tdef.setOutputProperty(name, value);
                }
            }
            pdef.addTransformDef(tdef);
        }
        Document doc = pdef.toXML();
        String s = PreferenceUtil.serializeDocument(doc);
        writer.write(s);
    } catch (FileNotFoundException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, Messages.LaunchHelper_0, e));
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, Messages.LaunchHelper_1, e));
    } catch (ParserConfigurationException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, "ParserConfigurationException", // $NON-NLS-1$
        e));
    } catch (TransformerException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, "TransformerException", // $NON-NLS-1$
        e));
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                JAXPLaunchingPlugin.log(e);
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TransformDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) PipelineDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition) IOException(java.io.IOException) Document(org.w3c.dom.Document) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute) URL(java.net.URL) BufferedWriter(java.io.BufferedWriter) CoreException(org.eclipse.core.runtime.CoreException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Map(java.util.Map) TransformerException(javax.xml.transform.TransformerException) TypedValue(org.eclipse.wst.xsl.jaxp.debug.invoker.TypedValue)

Example 2 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class LaunchAttributes method fromXML.

public static LaunchAttributes fromXML(InputStream inputStream) throws CoreException {
    Document doc = PreferenceUtil.getDocument(inputStream);
    LaunchAttributes pdef = new LaunchAttributes();
    Element attributesEl = doc.getDocumentElement();
    // $NON-NLS-1$
    NodeList attributeEls = attributesEl.getElementsByTagName("Attribute");
    for (int i = 0; i < attributeEls.getLength(); i++) {
        Element attributeEl = (Element) attributeEls.item(i);
        // $NON-NLS-1$
        String name = attributeEl.getAttribute("name");
        // $NON-NLS-1$
        String type = attributeEl.getAttribute("type");
        // $NON-NLS-1$
        String value = attributeEl.getAttribute("value");
        pdef.addAttribute(new LaunchAttribute(name, type, value));
    }
    return pdef;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute)

Example 3 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class LaunchAttributes method toXML.

public String toXML() throws ParserConfigurationException, IOException, TransformerException {
    Document doc = PreferenceUtil.getDocument();
    // $NON-NLS-1$
    Element attributesEl = doc.createElement("Attributes");
    doc.appendChild(attributesEl);
    for (Iterator<LaunchAttribute> iter = attributes.iterator(); iter.hasNext(); ) {
        LaunchAttribute attribute = iter.next();
        // $NON-NLS-1$
        Element attributeEl = doc.createElement("Attribute");
        // $NON-NLS-1$
        attributeEl.setAttribute("name", attribute.uri);
        // $NON-NLS-1$
        attributeEl.setAttribute("type", attribute.type);
        // $NON-NLS-1$
        attributeEl.setAttribute("value", attribute.value);
        attributesEl.appendChild(attributeEl);
    }
    return PreferenceUtil.serializeDocument(doc);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute)

Example 4 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class AddParameterAction method run.

@Override
public void run() {
    MultipleInputDialog dialog = new MultipleInputDialog(getShell(), Messages.AddParameterAction_Dialog);
    String namelabel = Messages.AddParameterAction_Dialog_Name;
    dialog.addTextField(namelabel, null, false);
    String variableslabel = Messages.AddParameterAction_Dialog_Value;
    dialog.addVariablesField(variableslabel, null, false);
    dialog.open();
    if (dialog.getReturnCode() == Window.OK) {
        String name = dialog.getStringValue(namelabel);
        String value = dialog.getStringValue(variableslabel);
        LaunchAttribute parameter = null;
        if (// $NON-NLS-1$
        value != null && value.indexOf("${") > -1)
            parameter = new LaunchAttribute(name, null, value);
        else
            parameter = new LaunchAttribute(name, null, value);
        getViewer().addParameter(parameter);
    }
}
Also used : LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute)

Example 5 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class RemoveParameterAction method run.

@Override
public void run() {
    IStructuredSelection sel = getStructuredSelection();
    if (sel.size() > 0) {
        LaunchAttribute[] entries = new LaunchAttribute[sel.size()];
        int i = 0;
        for (Iterator<?> iter = sel.iterator(); iter.hasNext(); i++) {
            LaunchAttribute att = (LaunchAttribute) iter.next();
            entries[i] = att;
        }
        getViewer().removeEntries(entries);
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute)

Aggregations

LaunchAttribute (org.eclipse.wst.xsl.launching.config.LaunchAttribute)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Document (org.w3c.dom.Document)3 Map (java.util.Map)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Table (org.eclipse.swt.widgets.Table)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 LaunchAttributes (org.eclipse.wst.xsl.jaxp.launching.LaunchAttributes)2 Element (org.w3c.dom.Element)2 BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1