List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:net.sf.ehcache.config.BeanHandler.java
/** * Sets an attribute./* w w w . ja v a2 s . c o m*/ */ private void setAttribute(final ElementInfo element, final String attrName, final String attrValue) throws SAXException { try { // Look for a set<name> method final Class objClass = element.bean.getClass(); final Method method = findSetMethod(objClass, "set", attrName); if (method != null) { final Object realValue = convert(method.getParameterTypes()[0], attrValue); method.invoke(element.bean, new Object[] { realValue }); return; } else { //allow references to an XML schema but do not use it if (element.elementName.equals("ehcache")) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring ehcache attribute " + attrName); } return; } } } catch (final InvocationTargetException e) { throw new SAXException(getLocation() + ": Could not set attribute \"" + attrName + "\"." + ". Message was: " + e.getTargetException()); } catch (final Exception e) { throw new SAXException(getLocation() + ": Could not set attribute \"" + attrName + "\"."); } throw new SAXException(getLocation() + ": Element <" + element.elementName + "> does not allow attribute \"" + attrName + "\"."); }
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * SAX2-Callback - Outputs XML-Deklaration with encoding. *//* w w w . ja v a 2 s .c o m*/ public void startDocument() throws SAXException { if (propOmitXmlDeclaration) return; try { writer.write("<?xml version=\""); writer.write(propVersion); writer.write("\" encoding=\""); writer.write(encoding); if (propStandalone) writer.write("\" standalone=\"yes"); writer.write("\"?>\n"); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } }
From source file:com.amalto.core.util.Util.java
public static Document parse(String xmlString) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory; factory = getDocumentBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); SAXErrorHandler seh = new SAXErrorHandler(); builder.setErrorHandler(seh);//from ww w .j a v a2 s . co m Document d = builder.parse(new InputSource(new StringReader(xmlString))); // check if document parsed correctly against the schema String errors = seh.getErrors(); if (errors.length() != 0) { String err = "Document did not parse against schema: \n" + errors + "\n" + xmlString.substring(0, Math.min(100, xmlString.length())); throw new SAXException(err); } return d; }
From source file:com.granule.json.utils.internal.JSONSAXHandler.java
/** * Internal method to end the JSON generation and to write out the resultant JSON text * and reset the internal state of the hander. *///from w w w.j a va 2 s . c o m private void endJSON() throws SAXException { if (logger.isLoggable(Level.FINER)) logger.entering(className, "endJSON()"); try { this.head.writeObject(this.osWriter, 0, true, this.compact); this.head = null; this.current = null; this.previousObjects.clear(); } catch (Exception ex) { SAXException saxEx = new SAXException(ex); saxEx.initCause(ex); throw saxEx; } if (logger.isLoggable(Level.FINER)) logger.exiting(className, "endJSON()"); }
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * SAX2-Callback - Flushes the output writer */// w ww . j av a 2 s . c o m public void endDocument() throws SAXException { processLastElement(false); try { writer.write("\n"); writer.flush(); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } }
From source file:fr.lip6.move.coloane.projects.its.io.ModelHandler.java
/** * Parse a concept description/*from ww w . j a v a 2 s. c o m*/ * @param attributes the attributes of the concept in XML * @throws SAXException any parse error */ private void handleConcept(Attributes attributes) throws SAXException { String name = attributes.getValue("name"); //$NON-NLS-1$ int idEffective = Integer.parseInt(attributes.getValue("effective")); //$NON-NLS-1$ int idParent = Integer.parseInt(attributes.getValue("parent")); //$NON-NLS-1$ if (idEffective == -1) { // concept is not assigned return; } // Get parent with maximum safeguards CompositeTypeDeclaration parent; try { parent = (CompositeTypeDeclaration) ids.get(idParent); } catch (ClassCastException e) { throw new SAXException( "Corrupted XML file, id " + idParent + " should refer to a composite type declaration"); } if (parent == null) { throw new SAXException( "Corrupted XML file, Dangling parent type id " + idParent + " in concept " + name); } // Get effective with maximum safeguards ITypeDeclaration effective; try { effective = (ITypeDeclaration) ids.get(idEffective); } catch (ClassCastException e) { throw new SAXException( "Corrupted XML file, effective id " + idEffective + " should refer to a type declaration"); } if (effective == null) { throw new SAXException( "Corrupted XML file, Dangling Effective type id " + idEffective + " in concept " + name); } // get the concept Concept concept = parent.getConcept(name); if (concept == null) { logger.warning("Concept effective definition which should belong to CompositeType " + parent + " does not exist in the actual model file. Ignoring Concept setting."); } else { concept.setEffective(effective); } }
From source file:com.atlassian.jira.action.admin.OfbizImportHandler.java
@Override public void endDocument() throws SAXException { if (hasRootElement) { throw new SAXException("XML file ended too early. There was no </entity-engine-xml> tag."); }/* ww w . j a v a 2s . c om*/ createBuildNumber(); createVersionString(); createMinimumDowngradeVersionString(); createLicenseString(); createIndexDefault(); createAttachmentDefault(); createIndexPath(); createAttachmentPath(); log.debug("Ending Document"); }
From source file:eu.annocultor.converter.ConverterHandler.java
List<ObjectRule> findRule(String namespaceURI, String localName, Attributes atts) throws SAXException { try {//from ww w. j ava 2 s . com Path parent = tagPath.isEmpty() ? null : tagPath.peek(); tagPath.push(new Path(parent, namespaceURI, localName, atts)); return task.getRuleForSourcePath(tagPath.peek()); } catch (Exception e) { throw new SAXException(e); } }
From source file:eu.annocultor.converter.ConverterHandler.java
@Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { try {/* ww w.ja v a 2s. co m*/ if (startRawFilter(namespaceURI + localName)) { return; } List<ObjectRule> rules = findRule(namespaceURI, localName, atts); if (rules.size() > 1) throw new SAXException("Multiple rules found on path: " + tagPath.peek()); if (rules.size() == 1) { // If a data object rule is found then the current tag // starts a new object that is pushed to stack. ObjectRule rule = rules.get(0); // new element-object. Searching for its parent // first instance of the parent ObjectMap is the parent instance DataObject parent = null; for (DataObject part : partsNotYetCompleted) { if (rule.getParent() == part.getDataObjectRule()) { parent = part; break; } } DataObject newObject = makeDataObjectForNewRecord(tagPath.peek(), rule, parent); partsNotYetCompleted.push(newObject); if (partsNotYetCompleted.size() > 1000) { throw new SAXException( "Data object has more than 1000 parts. This suggests that the record separating XML path is incorrect"); } } } catch (Exception e) { throw new SAXException("Exception on starting tag " + namespaceURI + localName, e); } }
From source file:net.sf.joost.stx.TransformerHandlerResolverImpl.java
/** * Resolve given method via searching for a plugin providing implementation * for it./*from www . j a v a 2s. c o m*/ * @return TransformerHandler for that method or throws exception. */ public TransformerHandler resolve(String method, String href, String base, URIResolver uriResolver, ErrorListener errorListener, Hashtable params) throws SAXException { Hashtable externalParams = createExternalParameters(params); if (customResolver != null) { TransformerHandler handler = customResolver.resolve(method, href, base, uriResolver, errorListener, externalParams); if (handler != null) return handler; } if (notInitializedYet) init(); TransformerHandlerResolver impl = (TransformerHandlerResolver) plugins.get(method); if (impl == null) throw new SAXException("Undefined filter implementation for method '" + method + "'"); return impl.resolve(method, href, base, uriResolver, errorListener, externalParams); }