private String finishCharacters() { // common case -- no characters or only whitespace if (this.characters == null || this.characters.length() == 0) { return null; } if (allWhiteSpace(this.characters)) { this.characters.setLength(0); return null; } // process the characters try { String trimmedChars = this.characters.toString().trim(); if (trimmedChars.length() == 0) { // this shouldn't happen due to the test for allWhiteSpace above System.err.println("Unexpected non-whitespace characters: " //$NON-NLS-1$ + trimmedChars); return null; } processCharacters(trimmedChars); return trimmedChars; } finally { this.characters.setLength(0); } }
public void endElement(String namespaceURI, String localName, String qName) { // TODO: throw a bad state error if makeSimpleName(localName, qName) != elementHandled finishCharacters(); finished(); // Restore the parent content handler xmlReader.setContentHandler(parentHandler); }
public void unexpectedCharacterData(AbstractHandler handler, String cdata) { if (Tracing.DEBUG_PARSE_PROBLEMS) Tracing.debug("Unexpected character data in element " + handler.getName() + ": " + cdata.trim()); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * In p2 1.0 we stored URLs, in 1.1 and later we store URIs. This method will * first check for a URI, and then resort to looking for a URL attribute for * backwards compatibility. * @param attributes The attributes to parse * @param required If true, an exception is thrown if no URI or URL attribute is present */ protected URI parseURIAttribute(Attributes attributes, boolean required) { String location = parseOptionalAttribute(attributes, URI_ATTRIBUTE); try { if (location != null) return new URI(location); if (required) location = parseRequiredAttributes(attributes, new String[] {URL_ATTRIBUTE})[0]; else location = parseOptionalAttribute(attributes, URL_ATTRIBUTE); if (location == null) return null; return URIUtil.toURI(new URL(location)); } catch (MalformedURLException e) { invalidAttributeValue(elementHandled, URL_ATTRIBUTE, location, e); } catch (URISyntaxException e) { invalidAttributeValue(elementHandled, URL_ATTRIBUTE, location, e); } return null; }
private String finishCharacters() { // common case -- no characters or only whitespace if (this.characters == null || this.characters.length() == 0) { return null; } if (allWhiteSpace(this.characters)) { this.characters.setLength(0); return null; } // process the characters try { String trimmedChars = this.characters.toString().trim(); if (trimmedChars.length() == 0) { // this shouldn't happen due to the test for allWhiteSpace above System.err.println("Unexpected non-whitespace characters: " //$NON-NLS-1$ + trimmedChars); return null; } processCharacters(trimmedChars); return trimmedChars; } finally { this.characters.setLength(0); } }
private URI constructURI(Attributes attributes, boolean required, String location) { try { if (location != null) return new URI(location); if (required) location = parseRequiredAttributes(attributes, new String[] {URL_ATTRIBUTE})[0]; else location = parseOptionalAttribute(attributes, URL_ATTRIBUTE); if (location == null) return null; return URIUtil.toURI(new URL(location)); } catch (MalformedURLException e) { invalidAttributeValue(elementHandled, URL_ATTRIBUTE, location, e); } catch (URISyntaxException e) { invalidAttributeValue(elementHandled, URL_ATTRIBUTE, location, e); } return null; }
/** * In p2 1.0 we stored URLs, in 1.1 and later we store URIs. This method will * first check for a URI, and then resort to looking for a URL attribute for * backwards compatibility. * @param attributes The attributes to parse * @param required If true, an exception is thrown if no URI or URL attribute is present */ protected URI parseURIAttribute(Attributes attributes, boolean required) { String location = parseOptionalAttribute(attributes, URI_ATTRIBUTE); URI uri = location == null ? null : XMLParser.this.uris.get(location); if (uri == null) { uri = constructURI(attributes, required, location); if (uri != null) { XMLParser.this.uris.put(location, uri); } } return uri; }
public abstract void startElement(String name, Attributes attributes) throws SAXException;
public abstract void startElement(String name, Attributes attributes) throws SAXException;
public void unexpectedElement(AbstractHandler handler, String element, Attributes attributes) { if (Tracing.DEBUG_PARSE_PROBLEMS) Tracing.debug("Unexpected element in element " + handler.getName() + ": <" + element + toString(attributes) + '>'); //$NON-NLS-1$ //$NON-NLS-2$ }
public void unexpectedElement(AbstractHandler handler, String element, Attributes attributes) { if (Tracing.DEBUG_PARSE_PROBLEMS) Tracing.debug("Unexpected element in element " + handler.getName() + ": <" + element + toString(attributes) + '>'); //$NON-NLS-1$ //$NON-NLS-2$ }
public void unexpectedCharacterData(AbstractHandler handler, String cdata) { if (Tracing.DEBUG_PARSE_PROBLEMS) Tracing.debug("Unexpected character data in element " + handler.getName() + ": " + cdata.trim()); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Parse the attributes of an element with only required attributes. */ protected String[] parseRequiredAttributes(Attributes attributes, String[] required) { return parseAttributes(attributes, required, noAttributes); }
/** * Parse the attributes of an element with only required attributes. */ protected String[] parseRequiredAttributes(Attributes attributes, String[] required) { return parseAttributes(attributes, required, noAttributes); }
public void duplicateElement(AbstractHandler handler, String element, Attributes attributes) { addError(IStatus.WARNING, NLS.bind(Messages.XMLParser_Duplicate_Element, new Object[] {handler.getName(), element, toString(attributes)}), null); //ignore the duplicate element entirely because we have already logged it new IgnoringHandler(handler); }
public void duplicateElement(AbstractHandler handler, String element, Attributes attributes) { addError(IStatus.WARNING, NLS.bind(Messages.XMLParser_Duplicate_Element, new Object[] {handler.getName(), element, toString(attributes)}), null); //ignore the duplicate element entirely because we have already logged it new IgnoringHandler(handler); }
/** * Parse the attributes of an element with a single optional attribute. */ protected String parseOptionalAttribute(Attributes attributes, String name) { return parseAttributes(attributes, noAttributes, new String[] {name})[0]; }
public void endElement(String namespaceURI, String localName, String qName) { // TODO: throw a bad state error if makeSimpleName(localName, qName) != elementHandled finishCharacters(); finished(); // Restore the parent content handler xmlReader.setContentHandler(parentHandler); }
/** * Parse the attributes of an element with a single optional attribute. */ protected String parseOptionalAttribute(Attributes attributes, String name) { return parseAttributes(attributes, noAttributes, new String[] {name})[0]; }