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(); } }
throw new JDOMParseException("Error on line " + e.getLineNumber() + " of document " + systemId + ": " + e.getMessage(), e, doc); throw new JDOMParseException("Error on line " + e.getLineNumber() + ": " + e.getMessage(), e, doc); } catch (final SAXException e) { throw new JDOMParseException("Error in building: " + e.getMessage(), e, saxHandler.getDocument()); } finally {
/** * Returns the column number of the end of the text where the * parse error occurred. * <p> * The first column in a line is position 1.</p> * * @return an integer representing the column number, or -1 * if the information is not available. */ public int getColumnNumber() { return (getCause() instanceof SAXParseException)? ((SAXParseException)getCause()).getColumnNumber(): -1; } }
/** * Returns the line number of the end of the text where the parse error occurred. * <p> * The first line in the document is line 1. * </p> * * @return an integer representing the line number, or -1 if the information is not available. */ public int getLineNumber() { if (getCause() instanceof JDOMParseException) { return ((JDOMParseException) getCause()).getLineNumber(); } else { return -1; } }
int lineNum = e.getLineNumber(); if ( lineNum != -1 ) { int badStart = -1; String msg = String.format( "Fix this and try again:\n%s", e.toString() ); msg += "\n"; msg += "~ ~ ~ ~ ~\n";
/** * Returns the column number of the end of the text where the * parse error occurred. * <p> * The first column in a line is position 1.</p> * * @return an integer representing the column number, or -1 * if the information is not available. */ public int getColumnNumber() { return (getCause() instanceof JDOMParseException)? ((JDOMParseException)getCause()).getColumnNumber(): -1; }
/** * Returns the line number of the end of the text where the parse error occurred. * <p> * The first line in the document is line 1. * </p> * * @return an integer representing the line number, or -1 if the information is not available. */ public int getLineNumber() { if (getCause() instanceof JDOMParseException) { return ((JDOMParseException) getCause()).getLineNumber(); } else { return -1; } }
int lineNum = e.getLineNumber(); if ( lineNum != -1 ) { int badStart = -1; String msg = String.format( "Fix this and try again:\n%s", e.toString() ); msg += "\n"; msg += "~ ~ ~ ~ ~\n";
/** * Returns the column number of the end of the text where the * parse error occurred. * <p> * The first column in a line is position 1.</p> * * @return an integer representing the column number, or -1 * if the information is not available. */ public int getColumnNumber() { return (getCause() instanceof JDOMParseException)? ((JDOMParseException)getCause()).getColumnNumber(): -1; }
@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 the line number of the end of the text where the * parse error occurred. * <p> * The first line in the document is line 1.</p> * * @return an integer representing the line number, or -1 * if the information is not available. */ public int getLineNumber() { return (getCause() instanceof JDOMParseException)? ((JDOMParseException)getCause()).getLineNumber(): -1; }
/** * Returns the column number of the end of the text where the parse error occurred. * <p> * The first column in a line is position 1. * </p> * * @return an integer representing the column number, or -1 if the information is not available. */ public int getColumnNumber() { if (getCause() instanceof JDOMParseException) { return ((JDOMParseException) getCause()).getColumnNumber(); } else { return -1; } }
throw new JDOMParseException( String.format( "Error on line %d: %s", lineNum, cause.getMessage() ), cause ); throw new JDOMParseException( String.format( "Error on line %d: %s", lineNum, cause.getMessage() ), cause ); throw new JDOMParseException( String.format( "Error on line %d: %s", lineNum, cause.getMessage() ), cause );
/** * Returns the system identifier of the entity where the * parse error occurred. * * @return a string containing the system identifier, or * <code>null</code> if the information is not available. */ public String getSystemId() { return (getCause() instanceof SAXParseException)? ((SAXParseException)getCause()).getSystemId(): null; }
/** * 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; }
/** * Returns the line number of the end of the text where the * parse error occurred. * <p> * The first line in the document is line 1.</p> * * @return an integer representing the line number, or -1 * if the information is not available. */ public int getLineNumber() { return (getCause() instanceof JDOMParseException)? ((JDOMParseException)getCause()).getLineNumber(): -1; }
/** * Returns the column number of the end of the text where the parse error occurred. * <p> * The first column in a line is position 1. * </p> * * @return an integer representing the column number, or -1 if the information is not available. */ public int getColumnNumber() { if (getCause() instanceof JDOMParseException) { return ((JDOMParseException) getCause()).getColumnNumber(); } else { return -1; } }
/** * Returns the line number of the end of the text where the * parse error occurred. * <p> * The first line in the document is line 1.</p> * * @return an integer representing the line number, or -1 * if the information is not available. */ public int getLineNumber() { return (getCause() instanceof SAXParseException)? ((SAXParseException)getCause()).getLineNumber(): -1; }
/** * 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); } }
private PluginCreator loadDescriptorFromDescriptorFile(@NotNull String descriptorPath, @NotNull File pluginDirectory, @NotNull File descriptorFile, boolean validateDescriptor) { try { URL documentUrl = URLUtil.fileToUrl(descriptorFile); Document document = JDOMUtil.loadDocument(documentUrl); return new PluginCreator(descriptorPath, validateDescriptor, document, documentUrl, myPathResolver, pluginDirectory); } catch (JDOMParseException e) { int lineNumber = e.getLineNumber(); String message = lineNumber != -1 ? "unexpected element on line " + lineNumber : "unexpected elements"; return new PluginCreator(descriptorPath, new UnexpectedDescriptorElements(descriptorPath, message), pluginDirectory); } catch (Exception e) { LOG.debug("Unable to read plugin descriptor " + descriptorPath + " of plugin " + descriptorFile, e); return new PluginCreator(descriptorPath, new UnableToReadDescriptor(descriptorPath), pluginDirectory); } }