public GoConfigValidity saveXml(String xmlPartial, String expectedMd5) { GoConfigValidity hasValidRequest = checkValidity(); if (!hasValidRequest.isValid()) { return hasValidRequest; } try { return GoConfigValidity.valid(updatePartial(xmlPartial, expectedMd5)); } catch (JDOMParseException jsonException) { return GoConfigValidity.invalid(String.format("%s - %s", INVALID_CRUISE_CONFIG_XML, jsonException.getMessage())).fromConflict(); } catch (ConfigMergePreValidationException e) { return invalid(e).mergePreValidationError(); } catch (Exception e) { if (e.getCause() instanceof ConfigMergePostValidationException) { return GoConfigValidity.invalid(e.getCause().getMessage()).mergePostValidationError(); } if (e.getCause() instanceof ConfigMergeException) { return GoConfigValidity.invalid(e.getCause().getMessage()).mergeConflict(); } return GoConfigValidity.invalid(e).fromConflict(); } }
@Test public void shouldNotAllowEmptyAuthInApproval() throws Exception { CruiseConfig cruiseConfig = ConfigMigrator.load(ConfigFileFixture.ONE_PIPELINE); StageConfig stageConfig = com.thoughtworks.go.helper.StageConfigMother.custom("newStage", new AuthConfig()); cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1")).add(stageConfig); try { xmlWriter.write(cruiseConfig, output, false); assertThat("Should not allow approval with empty auth", output.toString().contains("<auth"), is(false)); } catch (JDOMParseException expected) { assertThat(expected.getMessage(), containsString("The content of element 'auth' is not complete")); } }
/** * Returns an XML Document, parsed strictly if possible, or sloppily. * Exceptions during strict parsing will be ignored. * * This method does NOT strip the XML declaration and add a wrapper * tag with namespaces. That must be done beforehand. * * @see net.vhati.modmanager.core.EmptyAwareSAXHandlerFactory * @see net.vhati.modmanager.core.SloppyXMLParser */ public static Document parseStrictOrSloppyXML( CharSequence srcSeq, String srcDescription ) throws IOException, JDOMException { Document doc = null; try { SAXBuilder strictParser = new SAXBuilder(); strictParser.setSAXHandlerFactory( new EmptyAwareSAXHandlerFactory() ); doc = strictParser.build( new StringReader( srcSeq.toString() ) ); } catch ( JDOMParseException e ) { // Ignore the error, and do a sloppy parse instead. try { SloppyXMLParser sloppyParser = new SloppyXMLParser(); doc = sloppyParser.build( srcSeq ); } catch ( JDOMParseException f ) { throw new JDOMException( String.format( "While processing \"%s\", strict parsing failed, then sloppy parsing failed: %s", srcDescription, f.getMessage() ), f ); } } return doc; }
/** * Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * * @param is W3C SAX InputSource to read to create the WireFeed. * @return the WireFeed read from the W3C SAX InputSource. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the * underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(final InputSource is) throws IllegalArgumentException, FeedException { final SAXBuilder saxBuilder = createSAXBuilder(); try { final Document document = saxBuilder.build(is); return this.build(document); } catch (final JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (final IllegalArgumentException ex) { throw ex; } catch (final Exception ex) { throw new ParsingFeedException("Invalid XML", ex); } }
/** * Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * @param is W3C SAX InputSource to read to create the WireFeed. * @return the WireFeed read from the W3C SAX InputSource. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(InputSource is) throws IllegalArgumentException,FeedException { SAXBuilder saxBuilder = createSAXBuilder(); try { Document document = saxBuilder.build(is); return build(document); } catch (JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (IllegalArgumentException ex) { throw ex; } catch (Exception ex) { throw new ParsingFeedException("Invalid XML",ex); } }
/** * Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * * @param is W3C SAX InputSource to read to create the WireFeed. * @return the WireFeed read from the W3C SAX InputSource. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the * underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(final InputSource is) throws IllegalArgumentException, FeedException { final SAXBuilder saxBuilder = createSAXBuilder(); try { final Document document = saxBuilder.build(is); return this.build(document); } catch (final JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (final IllegalArgumentException ex) { throw ex; } catch (final Exception ex) { throw new ParsingFeedException("Invalid XML", ex); } }
/** * Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * @param is W3C SAX InputSource to read to create the WireFeed. * @return the WireFeed read from the W3C SAX InputSource. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(InputSource is) throws IllegalArgumentException,FeedException { SAXBuilder saxBuilder = createSAXBuilder(); try { Document document = saxBuilder.build(is); return build(document); } catch (JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (IllegalArgumentException ex) { throw ex; } catch (Exception ex) { throw new ParsingFeedException("Invalid XML",ex); } }
/** * Builds an WireFeed (RSS or Atom) from an Reader. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * * @param reader Reader to read to create the WireFeed. * @return the WireFeed read from the Reader. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the * underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(Reader reader) throws IllegalArgumentException, FeedException { final SAXBuilder saxBuilder = createSAXBuilder(); try { if (xmlHealerOn) { reader = new XmlFixerReader(reader); } final Document document = saxBuilder.build(reader); return this.build(document); } catch (final JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (final IllegalArgumentException ex) { throw ex; } catch (final Exception ex) { throw new ParsingFeedException("Invalid XML", ex); } }
/** * Builds an WireFeed (RSS or Atom) from an Reader. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * * @param reader Reader to read to create the WireFeed. * @return the WireFeed read from the Reader. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the * underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(Reader reader) throws IllegalArgumentException, FeedException { final SAXBuilder saxBuilder = createSAXBuilder(); try { if (xmlHealerOn) { reader = new XmlFixerReader(reader); } final Document document = saxBuilder.build(reader); return this.build(document); } catch (final JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (final IllegalArgumentException ex) { throw ex; } catch (final Exception ex) { throw new ParsingFeedException("Invalid XML", ex); } }
/** * Builds an WireFeed (RSS or Atom) from an Reader. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * @param reader Reader to read to create the WireFeed. * @return the WireFeed read from the Reader. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(Reader reader) throws IllegalArgumentException,FeedException { SAXBuilder saxBuilder = createSAXBuilder(); try { if (_xmlHealerOn) { reader = new XmlFixerReader(reader); } Document document = saxBuilder.build(reader); return build(document); } catch (JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (IllegalArgumentException ex) { throw ex; } catch (Exception ex) { throw new ParsingFeedException("Invalid XML",ex); } }
/** * Builds an WireFeed (RSS or Atom) from an Reader. * <p> * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. * <p> * @param reader Reader to read to create the WireFeed. * @return the WireFeed read from the Reader. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(Reader reader) throws IllegalArgumentException,FeedException { SAXBuilder saxBuilder = createSAXBuilder(); try { if (_xmlHealerOn) { reader = new XmlFixerReader(reader); } Document document = saxBuilder.build(reader); return build(document); } catch (JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); } catch (IllegalArgumentException ex) { throw ex; } catch (Exception ex) { throw new ParsingFeedException("Invalid XML",ex); } }