private void checkQuote (String name, char value) { if (value != '"' && value != '\'') throw new XMLParseException ("The quote for "+name+" must be '\"' or '\\'': ["+value+"]"); }
public XMLParseException (String message, Node node) { super (message); if (node instanceof Element) { setElement ((Element)node); } else if (node instanceof BasicNode) { BasicNode n = (BasicNode)node; setToken (n.getToken ()); } }
/** * Verify an entity. If no entityResolver is installed, this does nothing. */ protected void verifyEntity (int start, int end) { if (entityResolver == null) return; String entity = source.substring (start, end); try { entityResolver.validateEntity (entity); } catch (IllegalArgumentException e) { throw new XMLParseException (e.getMessage (), e).setSource (source, start); } }
XMLParseException ex = new XMLParseException (e.getMessageWithoutLocation (), e); if (pi.getToken () == null) ex.setNode (this, pi); else ex.setSource (pi.getToken ().getSource (), pi.getStartOffset () + e.getOffset ()); throw ex;
throw new XMLParseException ("Entity "+entity+" is not defined", entityToken); throw new XMLParseException ("Expansion of "+entity+" leads to infinite recursion", entityToken); throw new XMLParseException ("Error while expanding entity "+entity+": "+e.getMessage (), e) .setToken (entityToken); return; throw new XMLParseException ("Expanded entity "+entity+" is not well-formed since it contains the end-token for '"+parent.getName ()+"'", entityToken);
private TargetDefinitionFile(File source, IncludeSourceMode includeSourceMode) throws TargetDefinitionSyntaxException { try { this.origin = source; this.fileContentHash = computeFileContentHash(source); this.includeSourceMode = includeSourceMode; FileInputStream input = new FileInputStream(source); try { this.document = parser.parse(new XMLIOSource(source)); this.dom = document.getRootElement(); } finally { input.close(); } } catch (XMLParseException e) { throw new TargetDefinitionSyntaxException("Target definition is not well-formed XML: " + e.getMessage(), e); } catch (IOException e) { throw new TargetDefinitionSyntaxException( "I/O error while reading target definition file: " + e.getMessage(), e); } }
public XMLParseException (String message, XMLSource source, int offset) { super (message); setSource (source, offset); }
public XMLParseException (String message, Element e) { super (message); setElement (e); }
public XMLParseException (String message, Document doc, Node node) { super (message); setNode (doc, node); }
throw new XMLParseException ("Expected '<?xml'", source, 0); throw new XMLParseException ("Expected '?>'", source, end); throw new XMLParseException ("Expecting whitespace between attributes of XML declaration", source, pos); throw new XMLParseException ("Found a second version attribute", source, pos); versionSpace = text.substring (spaceStart, pos); pos += 7; throw new XMLParseException ("Found a second encoding attribute", source, pos); if (version == null) throw new XMLParseException ("Version must be before encoding", source, pos); encodingSpace = text.substring (spaceStart, pos); pos += 8; throw new XMLParseException ("Found a second standalone attribute", source, pos); sawStandalone = true; standaloneSpace = text.substring (spaceStart, pos); throw new XMLParseException ("Expected 'version', 'encoding' or 'standalone'", source, pos); throw new XMLParseException ("Expected '=' after "+attrName, source, pos); pos ++; throw new XMLParseException ("Expected value for "+attrName, source, pos); throw new XMLParseException ("Expected single or double quotes around value of "+attrName+" but found '"+quoteChar+"' ("+Integer.toString (quoteChar, 16)+")", source, pos);
private TargetDefinitionFile(File source, IncludeSourceMode includeSourceMode) throws TargetDefinitionSyntaxException { try { this.origin = source; this.fileContentHash = computeFileContentHash(source); this.includeSourceMode = includeSourceMode; FileInputStream input = new FileInputStream(source); try { this.document = parser.parse(new XMLIOSource(source)); this.dom = document.getRootElement(); } finally { input.close(); } } catch (XMLParseException e) { throw new TargetDefinitionSyntaxException("Target definition is not well-formed XML: " + e.getMessage(), e); } catch (IOException e) { throw new TargetDefinitionSyntaxException("I/O error while reading target definition file: " + e.getMessage(), e); } }
public XMLParseException setToken (Token token) { this.token = token; if (token != null) { setSource (token.getSource (), token.getStartOffset ()); } return this; }
protected void checkEquals (String name, String value) { if (value == null) throw new XMLParseException ("equal sign after " + name + " field can't be null"); if (value.length () == 0) throw new XMLParseException ("equal sign after " + name + " field can't be empty"); if (!"=".equals (value.trim ())) throw new XMLParseException ("equal sign after " + name + " field must only contain whitespace and a single '=': ["+value+"]"); }
throw new XMLParseException ("Error parsing XML declaration: "+e.getMessage (), e) .setSource (source, 0); throw new XMLParseException ("UTF 32 Little Endian not supported, yet. Patches welcome."); throw new XMLParseException ("UTF 32 Big Endian not supported, yet. Patches welcome."); throw new XMLParseException ("Error parsing XML declaration: Unsupported encoding "+e.getMessage (), e); //@COBEX throw new XMLParseException ("Found illegal character in XML header: '"+(char)c+"'") .setSource (source, pos); throw new XMLParseException ("Error parsing XML declaration: Unsupported encoding "+e.getMessage (), e); //@COBEX throw new XMLParseException ("Missing version in XML declaration") .setSource (new XMLStringSource (s), pos); int c = s.charAt (pos); if (c != '\'' && c != '"') throw new XMLParseException ("Missing opening quote for encoding") .setSource (new XMLStringSource (s), pos); throw new XMLParseException ("Missing closing quote for encoding") .setSource (new XMLStringSource (s), pos); throw new XMLParseException ("Error parsing XML declaration: Unsupported encoding '"+javaEncoding+"'", e) .setSource (new XMLStringSource (s), encodingOffset);
protected void checkSpace (String name, String value) { if (value == null) throw new XMLParseException ("space before " + name + " field can't be null"); if (value.length () == 0) throw new XMLParseException ("space before " + name + " field can't be empty"); if (value.trim ().length () != 0) throw new XMLParseException ("space before " + name + " field must contain only whitespace: ["+value+"]"); }
public Comment setText (String text) { if (text == null || text.length () == 0) text = " "; if (text.contains ("--")) throw new XMLParseException ("The text of a comment must not contain '--': ["+text+"]"); setValue ("<!--" + text + "-->"); this.text = text; return this; }
protected void nextChars (String expected, int startPos, String errorMessage) { int len = expected.length () - (pos - startPos); if (pos + len > source.length ()) throw new XMLParseException (errorMessage, source, startPos); String s = source.substring (startPos, startPos + expected.length ()); if (!expected.equals (s)) throw new XMLParseException (errorMessage, source, startPos); pos += len; }
public XMLDeclaration setPostSpace (String postSpace) { if (postSpace == null) postSpace = ""; else if (postSpace.trim ().length () != 0) throw new XMLParseException ("Space after the last field must not contain anything but whitespace"); this.postSpace = postSpace; updateText (); return this; }
private void expect (XMLSource source, int pos, String expected) { int end = Math.min (pos + expected.length (), source.length ()); String s = source.substring (pos, end); if (!expected.equals (s)) throw new XMLParseException ("Expected '"+expected+"' but found '"+s+"'", source, pos); }