List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * SAX2-Callback - Outputs a comment//w ww . j av a 2 s .c om */ public void comment(char[] ch, int start, int length) throws SAXException { processLastElement(false); try { writer.write("<!--"); writer.write(ch, start, length); writer.write("-->"); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } }
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * SAX2-Callback - Outputs a document type declaration *//* www. ja v a 2s . co m*/ public void startDTD(String name, String publicId, String systemId) throws SAXException { try { writer.write("<!DOCTYPE "); writer.write(name); if (publicId != null) { writer.write(" PUBLIC \""); writer.write(publicId); writer.write("\" \""); if (systemId != null) { writer.write(systemId); } writer.write("\""); } else if (systemId != null) { writer.write(" SYSTEM \""); writer.write(systemId); writer.write("\""); } // internal subset not supported yet writer.write(">\n"); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } }
From source file:co.anarquianegra.rockolappServidor.mundo.ListaReproductor.java
/** * Carga todas las canciones desde la carpeta ./data/canciones * @throws IOException/* ww w .jav a 2 s .c o m*/ * @throws SAXException * @throws TikaException */ public void cargar() throws IOException, SAXException, TikaException { try { rutasCanciones.load(Main.class.getResourceAsStream("res/canciones.properties")); capacidad = (int) (rutasCanciones.size() * .8); capacidad = (capacidad > 5) ? capacidad : 5; cancionesXartista = new TablaHashing<String, Cancion>((int) (capacidad * .5)); cancionesXnombre = new TablaHashing<String, Cancion>(capacidad); cancionesXid = new TablaHashing<String, Cancion>(capacidad); Iterator iter = rutasCanciones.keySet().iterator(); while (iter.hasNext()) { String key = (String) iter.next(); File archivo = new File(rutasCanciones.getProperty(key)); extraerCanciones(archivo); } } catch (FileNotFoundException e) { throw new FileNotFoundException("No se cargaron correctamente las canciones: \n" + e.getMessage()); } catch (IOException e) { throw new IOException("No se cargaron correctamente las canciones: \n" + e.getMessage()); } catch (SAXException e) { throw new SAXException("No se cargaron correctamente las canciones: \n" + e.getMessage()); } catch (TikaException e) { throw new TikaException("No se cargaron correctamente las canciones: \n" + e.getMessage()); } }
From source file:net.sf.joost.plugins.traxfilter.THResolver.java
/** * Creates new TH instance out of TrAX factory * @param method/*w ww . ja v a 2 s . c om*/ * @param source * @return TH */ protected TransformerHandler newTHOutOfTrAX(String method, Source source, Hashtable params, ErrorListener errorListener, URIResolver uriResolver) throws SAXException { if (DEBUG) log.debug("newTHOutOfTrAX()"); SAXTransformerFactory saxtf; if (FACTORY.getValueStr().length() > 0) { // create factory as asked by the client try { saxtf = (SAXTransformerFactory) (Class.forName(FACTORY.getValueStr())).newInstance(); if (DEBUG) log.debug("newTHOutOfTrAX(): use custom TrAX factory " + FACTORY.getValueStr()); } catch (InstantiationException e) { throw new SAXException(e); } catch (ClassNotFoundException e) { throw new SAXException(e); } catch (IllegalAccessException e) { throw new SAXException(e); } } else if (STX_METHOD.equals(method)) { saxtf = new TransformerFactoryImpl(); if (DEBUG) log.debug("newTHOutOfTrAX(): use default Joost factory " + saxtf.getClass().toString()); } else { final String TFPROP = "javax.xml.transform.TransformerFactory"; final String STXIMP = "net.sf.joost.trax.TransformerFactoryImpl"; synchronized (SYNCHRONIZE_GUARD) { String propVal = System.getProperty(TFPROP); boolean propChanged = false; String xsltFac = System.getProperty(TrAXConstants.KEY_XSLT_FACTORY); if (xsltFac != null || STXIMP.equals(propVal)) { // change this property, // otherwise we wouldn't get an XSLT transformer if (xsltFac != null) System.setProperty(TFPROP, xsltFac); else { Properties props = System.getProperties(); props.remove(TFPROP); System.setProperties(props); } propChanged = true; } saxtf = (SAXTransformerFactory) TransformerFactory.newInstance(); if (propChanged) { // reset property if (propVal != null) System.setProperty(TFPROP, propVal); else { Properties props = System.getProperties(); props.remove(TFPROP); System.setProperties(props); } } } if (DEBUG) log.debug("newTHOutOfTrAX(): use default TrAX factory " + saxtf.getClass().toString()); } // set factory attributes setTraxFactoryAttributes(saxtf, params); setupTransformerFactory(saxtf, errorListener, uriResolver); try { if (DEBUG) log.debug("newTHOutOfTrAX(): creating factory's reusable TH"); // TrAX way to create TH TransformerHandler th = saxtf.newTransformerHandler(source); setupTransformer(th.getTransformer(), errorListener, uriResolver); return th; } catch (TransformerConfigurationException ex) { throw new SAXException(ex); } }
From source file:net.sf.joost.stx.Processor.java
/** * Create an <code>XMLReader</code> object (a SAX Parser) * @throws SAXException if a SAX Parser couldn't be created *///w ww . j a v a2 s.c om public static XMLReader createXMLReader() throws SAXException { // Using pure SAX2, not JAXP XMLReader reader = null; try { // try default parser implementation reader = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { String prop = System.getProperty("org.xml.sax.driver"); if (prop != null) { // property set, but still failed throw new SAXException("Can't create XMLReader for class " + prop); // leave the method here } // try another SAX implementation String PARSER_IMPLS[] = { "org.apache.xerces.parsers.SAXParser", // Xerces "org.apache.crimson.parser.XMLReaderImpl", // Crimson "gnu.xml.aelfred2.SAXDriver" // Aelfred nonvalidating }; for (int i = 0; i < PARSER_IMPLS.length; i++) { try { reader = XMLReaderFactory.createXMLReader(PARSER_IMPLS[i]); break; // for (...) } catch (SAXException e1) { } // continuing } if (reader == null) { throw new SAXException("Can't find SAX parser implementation.\n" + "Please specify a parser class via the system property " + "'org.xml.sax.driver'"); } } // set features and properties that have been put // into the system properties (e.g. via command line) Properties sysProps = System.getProperties(); for (Enumeration e = sysProps.propertyNames(); e.hasMoreElements();) { String propKey = (String) e.nextElement(); if (propKey.startsWith(EXTERN_SAX_FEATURE_PREFIX)) { reader.setFeature(propKey.substring(EXTERN_SAX_FEATURE_PREFIX.length()), Boolean.parseBoolean(sysProps.getProperty(propKey))); continue; } if (propKey.startsWith(EXTERN_SAX_PROPERTY_PREFIX)) { reader.setProperty(propKey.substring(EXTERN_SAX_PROPERTY_PREFIX.length()), sysProps.getProperty(propKey)); continue; } } if (DEBUG) log.debug("Using " + reader.getClass().getName()); return reader; }
From source file:com.netspective.commons.xml.template.Template.java
public Map getTemplateParamsValues(NodeIdentifiers nodeIdentifiers, Attributes attributesFromCaller) throws SAXException { Set requiredParams = new HashSet(); Map templateParamsValues = new HashMap(); fillTemplateParamsRequiredAndDefaultValues(requiredParams, templateParamsValues, attributesFromCaller); for (int i = 0; i < attributesFromCaller.getLength(); i++) { String attrName = attributesFromCaller.getQName(i); if (attrName.startsWith(nodeIdentifiers.getTemplateParamAttrPrefix())) templateParamsValues.put(attrName.substring(nodeIdentifiers.getTemplateParamAttrPrefix().length()), attributesFromCaller.getValue(i)); }/*from ww w .j a v a 2 s. c o m*/ // validate that all required parameters are available for (Iterator i = requiredParams.iterator(); i.hasNext();) { Parameter param = (Parameter) i.next(); String paramValue = (String) templateParamsValues.get(param.getName()); if (paramValue == null) throw new SAXException( "Required param '" + param.getName() + "' not found. Available: " + templateParamsValues); } return templateParamsValues; }
From source file:com.polarion.alm.ws.client.internal.encoding.BeanDeserializer.java
/** * Set the bean properties that correspond to element attributes. * /*from w ww . jav a 2s . c o m*/ * This method is invoked after startElement when the element requires * deserialization (i.e. the element is not an href and the value is not * nil.) * * @param namespace * is the namespace of the element * @param localName * is the name of the element * @param prefix * is the prefix of the element * @param attributes * are the attributes on the element...used to get the type * @param context * is the DeserializationContext */ public void onStartElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { // The value should have been created or assigned already. // This code may no longer be needed. if (value == null && constructorToUse == null) { // create a value try { value = javaType.newInstance(); } catch (Exception e) { throw new SAXException(Messages.getMessage("cantCreateBean00", javaType.getName(), e.toString())); } } // If no type description meta data, there are no attributes, // so we are done. if (typeDesc == null) return; // loop through the attributes and set bean properties that // correspond to attributes for (int i = 0; i < attributes.getLength(); i++) { QName attrQName = new QName(attributes.getURI(i), attributes.getLocalName(i)); String fieldName = typeDesc.getFieldNameForAttribute(attrQName); if (fieldName == null) continue; FieldDesc fieldDesc = typeDesc.getFieldByName(fieldName); // look for the attribute property BeanPropertyDescriptor bpd = (BeanPropertyDescriptor) propertyMap.get(fieldName); if (bpd != null) { if (constructorToUse == null) { // check only if default constructor if (!bpd.isWriteable() || bpd.isIndexed()) continue; } // Get the Deserializer for the attribute Deserializer dSer = getDeserializer(fieldDesc.getXmlType(), bpd.getType(), null, context); if (dSer == null) { dSer = context.getDeserializerForClass(bpd.getType()); // The java type is an array, but the context didn't // know that we are an attribute. Better stick with // simple types.. if (dSer instanceof ArrayDeserializer) { SimpleListDeserializerFactory factory = new SimpleListDeserializerFactory(bpd.getType(), fieldDesc.getXmlType()); dSer = (Deserializer) factory.getDeserializerAs(dSer.getMechanismType()); } } if (dSer == null) throw new SAXException(Messages.getMessage("unregistered00", bpd.getType().toString())); if (!(dSer instanceof SimpleDeserializer)) throw new SAXException( Messages.getMessage("AttrNotSimpleType00", bpd.getName(), bpd.getType().toString())); // Success! Create an object from the string and set // it in the bean try { dSer.onStartElement(namespace, localName, prefix, attributes, context); Object val = ((SimpleDeserializer) dSer).makeValue(attributes.getValue(i)); if (constructorToUse == null) { bpd.set(value, val); } else { // add value for our constructor if (constructorTarget == null) { constructorTarget = new ConstructorTarget(constructorToUse, this); } constructorTarget.set(val); } } catch (Exception e) { throw new SAXException(e); } } // if } // attribute loop }
From source file:com.avalara.avatax.services.base.ser.BeanDeserializer.java
/** * Set the bean properties that correspond to element attributes. * /*from w w w . ja v a 2s.co m*/ * This method is invoked after startElement when the element requires * deserialization (i.e. the element is not an href and the value is not * nil.) * @param namespace is the namespace of the element * @param localName is the name of the element * @param prefix is the prefix of the element * @param attributes are the attributes on the element...used to get the * type * @param context is the DeserializationContext */ public void onStartElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { // The value should have been created or assigned already. // This code may no longer be needed. if (value == null && constructorToUse == null) { // create a value try { value = javaType.newInstance(); } catch (Exception e) { throw new SAXException(Messages.getMessage("cantCreateBean00", javaType.getName(), e.toString())); } } // If no type description meta data, there are no attributes, // so we are done. if (typeDesc == null) return; // loop through the attributes and set bean properties that // correspond to attributes for (int i = 0; i < attributes.getLength(); i++) { QName attrQName = new QName(attributes.getURI(i), attributes.getLocalName(i)); String fieldName = typeDesc.getFieldNameForAttribute(attrQName); if (fieldName == null) continue; FieldDesc fieldDesc = typeDesc.getFieldByName(fieldName); // look for the attribute property BeanPropertyDescriptor bpd = (BeanPropertyDescriptor) propertyMap.get(fieldName); if (bpd != null) { if (constructorToUse == null) { // check only if default constructor if (!bpd.isWriteable() || bpd.isIndexed()) continue; } // Get the Deserializer for the attribute Deserializer dSer = getDeserializer(fieldDesc.getXmlType(), bpd.getType(), null, context); if (dSer == null) { dSer = context.getDeserializerForClass(bpd.getType()); } if (dSer == null) throw new SAXException(Messages.getMessage("unregistered00", bpd.getType().toString())); if (!(dSer instanceof SimpleDeserializer)) throw new SAXException( Messages.getMessage("AttrNotSimpleType00", bpd.getName(), bpd.getType().toString())); // Success! Create an object from the string and set // it in the bean try { dSer.onStartElement(namespace, localName, prefix, attributes, context); Object val = ((SimpleDeserializer) dSer).makeValue(attributes.getValue(i)); if (constructorToUse == null) { bpd.set(value, val); } else { // add value for our constructor if (constructorTarget == null) { constructorTarget = new ConstructorTarget(constructorToUse, this); } constructorTarget.set(val); } } catch (Exception e) { throw new SAXException(e); } } // if } // attribute loop }
From source file:SAXTreeValidator.java
/** * <p>//from www . j a va 2 s.co m * This will report a warning that has occurred; this indicates * that while no XML rules were "broken", something appears * to be incorrect or missing. * </p> * * @param exception <code>SAXParseException</code> that occurred. * @throws <code>SAXException</code> when things go wrong */ public void warning(SAXParseException exception) throws SAXException { System.out.println("**Parsing Warning**\n" + " Line: " + exception.getLineNumber() + "\n" + " URI: " + exception.getSystemId() + "\n" + " Message: " + exception.getMessage()); throw new SAXException("Warning encountered"); }
From source file:com.netspective.commons.xml.AbstractContentHandler.java
public void processingInstruction(String target, String pi) throws SAXException { if (target.equals(parseContext.getTransformInstruction())) { if (parseContext.prepareTransformInstruction(pi)) throw new SAXException(new TransformProcessingInstructionEncounteredException()); }//from ww w . j a v a2s . c o m }