/** Updates Job by its XML definition. */ public void updateByXml(Source source) throws IOException { checkPermission(CONFIGURE); StringWriter out = new StringWriter(); try { // this allows us to use UTF-8 for storing data, // plus it checks any well-formedness issue in the submitted // data Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(source, new StreamResult(out)); out.close(); } catch (TransformerException e) { throw new IOException("Failed to persist configuration.xml", e); } // try to reflect the changes by reloading InputStream in = new BufferedInputStream(new ByteArrayInputStream(out.toString().getBytes("UTF-8"))); try { // Do not allow overwriting view name as it might collide with another // view in same ViewGroup and might not satisfy Jenkins.checkGoodName. String oldname = name; Jenkins.XSTREAM.unmarshal(new XppDriver().createReader(in), this); name = oldname; } catch (StreamException e) { throw new IOException("Unable to read", e); } catch (ConversionException e) { throw new IOException("Unable to read", e); } catch (Error e) { // mostly reflection errors throw new IOException("Unable to read", e); } finally { in.close(); } save(); }