Search in sources :

Example 1 with LaunchTransform

use of org.eclipse.wst.xsl.launching.config.LaunchTransform 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 LaunchTransform

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

the class XSLLaunchShortcut method promptForStylesheet.

private void promptForStylesheet() {
    // prompt for input xml file
    final LaunchPipeline promptedPipeline = new LaunchPipeline();
    StatusDialog dialog = new StatusDialog(getShell()) {

        private TransformsBlock transformsBlock = new TransformsBlock();

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite comp = (Composite) super.createDialogArea(parent);
            comp.setFont(parent.getFont());
            GridLayout layout = new GridLayout(1, false);
            comp.setLayout(layout);
            Label label = new Label(comp, SWT.NONE);
            label.setFont(comp.getFont());
            GridData gd = new GridData();
            gd.horizontalIndent = 5;
            gd.verticalIndent = 5;
            gd.widthHint = 380;
            label.setLayoutData(gd);
            label.setText(Messages.XSLLaunchShortcut_7);
            promptedPipeline.setTransformDefs(new ArrayList<LaunchTransform>());
            transformsBlock.setPipeline(promptedPipeline);
            transformsBlock.createControl(comp);
            transformsBlock.initializeFrom(null);
            return comp;
        }

        @Override
        protected void okPressed() {
            savePipeline();
            super.okPressed();
        }

        private void savePipeline() {
            pipeline = promptedPipeline;
        }
    };
    dialog.setHelpAvailable(false);
    dialog.setStatusLineAboveButtons(true);
    dialog.setTitle(Messages.XSLLaunchShortcut_1);
    dialog.open();
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) Composite(org.eclipse.swt.widgets.Composite) LaunchPipeline(org.eclipse.wst.xsl.launching.config.LaunchPipeline) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) StatusDialog(org.eclipse.jface.dialogs.StatusDialog) TransformsBlock(org.eclipse.wst.xsl.internal.debug.ui.tabs.main.TransformsBlock)

Example 3 with LaunchTransform

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

the class XSLTSourcePathComputerDelegate method computeSourceContainers.

public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
    List<ISourceContainer> containers = new ArrayList<ISourceContainer>();
    String sourceFileExpr = configuration.getAttribute(XSLLaunchConfigurationConstants.ATTR_INPUT_FILE, (String) null);
    IPath sourceFile = getSubstitutedPath(sourceFileExpr);
    LaunchPipeline pipeline = hydratePipeline(configuration);
    // TODO have some way of knowing whether it is an IResource or not
    containers.add(new DirectorySourceContainer(sourceFile, false));
    for (Iterator<?> iter = pipeline.getTransformDefs().iterator(); iter.hasNext(); ) {
        LaunchTransform transform = (LaunchTransform) iter.next();
        IPath path = transform.getPath();
        ISourceContainer sourceContainer = null;
        if (transform.getPathType().equals(LaunchTransform.RESOURCE_TYPE)) {
            IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
            IContainer container = resource.getParent();
            if (container.getType() == IResource.PROJECT) {
                sourceContainer = new ProjectSourceContainer((IProject) container, false);
            } else if (container.getType() == IResource.FOLDER) {
                sourceContainer = new FolderSourceContainer(container, false);
            }
        } else {
            sourceContainer = new DirectorySourceContainer(path, false);
        }
        containers.add(sourceContainer);
    }
    return containers.toArray(new ISourceContainer[0]);
}
Also used : LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IPath(org.eclipse.core.runtime.IPath) LaunchPipeline(org.eclipse.wst.xsl.launching.config.LaunchPipeline) FolderSourceContainer(org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer) ArrayList(java.util.ArrayList) DirectorySourceContainer(org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer) ProjectSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer) IProject(org.eclipse.core.resources.IProject) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 4 with LaunchTransform

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

the class StylesheetContentProvider method addEntries.

public void addEntries(LaunchTransform[] res, Object beforeElement) {
    for (LaunchTransform transform : res) {
        pipeline.addTransformDef(transform);
    }
    tableViewer.add(res);
    // select the first new one
    tableViewer.setSelection(new StructuredSelection(res[0]), true);
}
Also used : LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 5 with LaunchTransform

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

the class XSLMainTab method setDefaults.

@Override
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
    LaunchPipeline lp = new LaunchPipeline();
    IResource[] resourceContext = getContext();
    IFile[] stylesheets = getXSLStylesheets(resourceContext);
    for (IFile file : stylesheets) {
        LaunchTransform lt = new LaunchTransform(file.getFullPath().toPortableString(), LaunchTransform.RESOURCE_TYPE);
        lp.addTransformDef(lt);
    }
    savePipeline(configuration, lp);
    super.setDefaults(configuration);
}
Also used : LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IFile(org.eclipse.core.resources.IFile) LaunchPipeline(org.eclipse.wst.xsl.launching.config.LaunchPipeline) IResource(org.eclipse.core.resources.IResource)

Aggregations

LaunchTransform (org.eclipse.wst.xsl.launching.config.LaunchTransform)11 IResource (org.eclipse.core.resources.IResource)4 CoreException (org.eclipse.core.runtime.CoreException)4 IPath (org.eclipse.core.runtime.IPath)4 LaunchPipeline (org.eclipse.wst.xsl.launching.config.LaunchPipeline)4 IFile (org.eclipse.core.resources.IFile)3 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 IContainer (org.eclipse.core.resources.IContainer)1 IProject (org.eclipse.core.resources.IProject)1 IStatus (org.eclipse.core.runtime.IStatus)1