本文整理汇总了Java中org.jdom2.input.JDOMParseException类的典型用法代码示例。如果您正苦于以下问题:Java JDOMParseException类的具体用法?Java JDOMParseException怎么用?Java JDOMParseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JDOMParseException类属于org.jdom2.input包,在下文中一共展示了JDOMParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseStrictOrSloppyXML
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
/**
* 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;
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;
}
示例2: reportGeneralProblem
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
public void reportGeneralProblem(Exception e) {
String message;
if (e instanceof IOException || e instanceof JDOMParseException) {
message = "There was a problem parsing your input data. \n" +
"Perhaps check that the XML is well formed.";
} else if (e instanceof YQueryException) {
message = e.getMessage();
} else {
message = e.getMessage();
}
e.printStackTrace();
JOptionPane.showMessageDialog(
this,
message,
"Problem with data input",
JOptionPane.ERROR_MESSAGE);
}
示例3: findTagsNamed
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
public static ArrayList<Element> findTagsNamed( String contents, String tagName ) throws JDOMParseException
{
Document doc = null;
doc = IOUtils.parseXML( contents );
ArrayList<Element> tagList = new ArrayList<Element>();
Element root = doc.getRootElement();
if ( root.getName().equals( tagName ) ) {
tagList.add( root );
}
else {
for ( Element e : root.getChildren( tagName ) )
tagList.add( e );
}
return tagList;
}
示例4: parseFile
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
public PartialConfig parseFile(File file) {
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
return loader.fromXmlPartial(inputStream, PartialConfig.class);
} catch (JDOMParseException jdomex) {
throw new RuntimeException("Syntax error in xml file: " + file.getName(), jdomex);
} catch (IOException ioex) {
throw new RuntimeException("IO error when trying to parse xml file: " + file.getName(), ioex);
} catch (Exception ex) {
throw new RuntimeException("Failed to parse xml file: " + file.getName(), ex);
} finally {
if (inputStream != null) try {
inputStream.close();
} catch (IOException e) {
LOGGER.error("Failed to close file: {}", file, e);
}
}
}
示例5: parseStrictOrSloppyXML
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
/**
* 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;
}
示例6: suppressStackTrace
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
@Override
public boolean suppressStackTrace() {
// Don't dump the stack if the root cause is just a parse error
Throwable thrown = getThrown();
while(thrown instanceof InvalidXMLException) thrown = thrown.getCause();
return thrown == null ||
(thrown instanceof JDOMParseException) ||
super.suppressStackTrace();
}
示例7: validateXML
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
private String validateXML(String xml, SAXBuilder builder) throws JDOMException, IOException {
Reader in;
int i = 0;
xml = xml.replaceAll("\\&", "&");
while (i < 5) {
in = new StringReader(xml);
try {
builder.build(in);
break;
} catch (JDOMParseException e) {
String message = e.getMessage();
if (message.matches("^.*.The element type.*.must be terminated by the matching end-tag.*")) {
String tag = message.substring(message.lastIndexOf("type") + 6, message.lastIndexOf("must") - 2);
xml = xml.replaceAll("(?i)</" + tag + ">" , "</" + tag + ">");
} else {
break;
}
i++;
}
}
return xml;
}
示例8: saveShipModFTL
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
/**
* Saves the ship within the context of the specified database entry, as the specified file.
*
* @param destination
* the output file.
* @param entry
* the DatabaseEntry (runtime representation of an .ftl mod) within which the ship is to be saved.
* @param container
* the ShipContainer to be saved.
*/
public static void saveShipModFTL( File destination, DatabaseEntry entry, ShipContainer container )
throws IllegalArgumentException, IOException, JDOMParseException
{
if ( destination == null )
throw new IllegalArgumentException( "Destination file must not be null." );
if ( destination.isDirectory() )
throw new IllegalArgumentException( "Not a file: " + destination.getName() );
HashMap<String, byte[]> entryMap = IOUtils.readEntry( entry );
IOUtils.merge( entryMap, container );
IOUtils.writeZip( entryMap, destination );
}
示例9: saveShipModXML
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
public static void saveShipModXML( File destination, DatabaseEntry entry, ShipContainer container )
throws IllegalArgumentException, IOException, JDOMParseException
{
if ( destination == null )
throw new IllegalArgumentException( "Destination file must not be null." );
if ( !destination.isDirectory() )
throw new IllegalArgumentException( "Not a directory: " + destination.getName() );
HashMap<String, byte[]> entryMap = IOUtils.readEntry( entry );
IOUtils.merge( entryMap, container );
IOUtils.writeDir( entryMap, destination );
}
示例10: shouldNotAllowEmptyAuthInApproval
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
@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"));
}
}
示例11: shouldThrowExceptionWhenXmlIsMalformed
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
@Test
public void shouldThrowExceptionWhenXmlIsMalformed() throws Exception {
expectedException.expect(JDOMParseException.class);
expectedException.expectMessage(containsString("Error on line 1: XML document structures must start and end within the same entity"));
String xmlContent = "<foo name='invalid'";
buildXmlDocument(xmlContent, GoConfigSchema.getCurrentSchema());
}
示例12: fromJDOM
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
public static InvalidXMLException fromJDOM(JDOMParseException e, String documentPath) {
return new InvalidXMLException(e.getMessage(), null, e.getPartialDocument(), documentPath, e.getLineNumber(), e.getLineNumber(), e.getColumnNumber(), e);
}
示例13: convertHtmlTextToXhtml
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
/**
*
* @param text text to convert to HTML
* @return
*/
public static List<Element> convertHtmlTextToXhtml(String text) {
List<Element> result = null;
// if (logger.isTraceEnabled())
// logger.trace("Comment to convert: " + Database.stringToHex(text));
if (Helper.isNotNullOrEmpty(text)) {
if (!text.startsWith("<")) {
// plain text
if (logger.isTraceEnabled())logger.trace("convertHtmlTextToXhtml: plain text");
StringBuffer sb = new StringBuffer();
if (Helper.isNotNullOrEmpty(text)) {
List<String> strings = Helper.tokenize(text, "\n", true);
for (String string : strings) {
if (Helper.isNullOrEmpty(string)) {
sb.append("<p />");
} else {
sb.append("<p>");
sb.append(string);
sb.append("</p>\n");
}
}
}
text = sb.toString();
}
// tidy the text
if (logger.isTraceEnabled()) logger.trace("convertHtmlTextToXhtml: tidy the text");
try {
String noNL = text.replaceAll("\\n","");
result = tidyInputStream(new ByteArrayInputStream(noNL.getBytes("utf-8")));
// result = tidyInputStream(new ByteArrayInputStream(text.getBytes("utf-8")));
String afterTIDY = result.toString();
int dummy = 1;
} catch (JDOMParseException j) {
if (logger.isDebugEnabled()) logger.trace("convertHtmlTextToXhtml: caught JDOMParseException in the tidy process");
if (logger.isTraceEnabled()) logger.trace( "" + j);
tidyForTidyInputStream = null; // Force a new clean object to be gebnerated for next time around
} catch (Exception ee) {
if (logger.isDebugEnabled()) logger.debug("convertHtmlTextToXhtml: caught exception in the tidy process", ee);
tidyForTidyInputStream = null; // Force a new clean object to be gebnerated for next time around
} catch (Throwable t) {
logger.error("convertHtmlTextToXhtml: caught throwable in the tidy process", t);
tidyForTidyInputStream = null; // Force a new clean object to be gebnerated for next time around
}
if (result != null) {
if (logger.isTraceEnabled()) logger.trace("convertHtmlTextToXhtml: returning XHTML");
} else {
if (Helper.isNotNullOrEmpty(text)) logger.debug("convertHtmlTextToXhtml: Cannot convert comment text\n" + text);
}
}
return result;
}
示例14: findShipsWithName
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
public static ArrayList<Element> findShipsWithName( File f, String blueprintName )
throws IllegalArgumentException, JDOMParseException, IOException
{
return findShipsWithName( blueprintName, new FileInputStream( f ), f.getName() );
}
示例15: merge
import org.jdom2.input.JDOMParseException; //导入依赖的package包/类
/**
* Merges the file-byte map with the specified ShipContainer, effectively saving
* the ship in the file-byte map.
*/
public static void merge( Map<String, byte[]> base, ShipContainer container )
throws JDOMParseException, IOException
{
ShipObject ship = container.getShipController().getGameObject();
Map<String, byte[]> fileMap = ShipSaveUtils.saveShip( container );
for ( String file : fileMap.keySet() ) {
if ( base.containsKey( file ) ) {
// Mod already contains that file; need to consider further
if ( file.endsWith( ".png" ) || file.equals( ship.getLayoutTXT() ) || file.equals( ship.getLayoutXML() ) ) {
// Overwrite graphics and layout files
base.put( file, fileMap.get( file ) );
}
else if ( file.endsWith( ".xml" ) || file.endsWith( ".append" ) ||
file.endsWith( ".rawappend" ) || file.endsWith( ".rawclobber" ) ) {
// Merge XML files, while removing obscured elements
Document docBase = IOUtils.parseXML( new String( base.get( file ) ) );
Document docAdd = IOUtils.parseXML( new String( fileMap.get( file ) ) );
Element root = docBase.getRootElement();
List<Content> addList = docAdd.getContent();
for ( int i = 0; i < addList.size(); ++i ) {
Content c = addList.get( i );
if ( c instanceof Element == false )
continue;
Element e = (Element)c;
String name = e.getAttributeValue( "name" );
if ( name == null ) {
// Can't identify; just add it.
e.detach();
root.addContent( e );
}
else {
// Remove elements that are obscured, in order to prevent bloating
List<Element> baseList = root.getChildren( e.getName(), e.getNamespace() );
for ( int j = 0; j < baseList.size(); ++j ) {
Element el = baseList.get( j );
String name2 = el.getAttributeValue( "name" );
if ( name2 != null && name2.equals( name ) ) {
el.detach();
}
}
e.detach();
root.addContent( e );
}
}
base.put( file, readDocument( docBase ).getBytes() );
}
}
else {
// Doesn't exist; add it
base.put( file, fileMap.get( file ) );
}
}
}