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