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