List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:org.dhatim.delivery.AbstractParser.java
protected XMLReader createXMLReader() throws SAXException { XMLReader reader;/*from www. j av a2s. co m*/ ExecutionContext execContext = getExecContext(); Source source = FilterSource.getSource(execContext); if (saxDriverConfig != null && saxDriverConfig.getResource() != null) { String className = saxDriverConfig.getResource(); reader = XMLReaderFactory.createXMLReader(className); } else if (source instanceof JavaSource) { JavaSource javaSource = (JavaSource) source; if (isFeatureOn(JavaSource.FEATURE_GENERATE_EVENT_STREAM, saxDriverConfig) && !javaSource.isEventStreamRequired()) { throw new SAXException("Invalid Smooks configuration. Feature '" + JavaSource.FEATURE_GENERATE_EVENT_STREAM + "' is explicitly configured 'on' in the Smooks configuration, while the supplied JavaSource has explicitly configured event streaming to be off (through a call to JavaSource.setEventStreamRequired)."); } // Event streaming must be explicitly turned off. If is on as long as it is (a) not configured "off" in // the smooks config (via the reader features) and (b) not turned off via the supplied JavaSource... boolean eventStreamingOn = (!isFeatureOff(JavaSource.FEATURE_GENERATE_EVENT_STREAM, saxDriverConfig) && javaSource.isEventStreamRequired()); if (eventStreamingOn && javaSource.getSourceObjects() != null) { reader = new XStreamXMLReader(); } else { reader = new NullSourceXMLReader(); } } else { reader = XMLReaderFactory.createXMLReader(); } if (reader instanceof SmooksXMLReader) { if (saxDriverConfig != null) { Configurator.configure(reader, saxDriverConfig, execContext.getContext()); } else { Configurator.initialise(reader); } } reader.setFeature("http://xml.org/sax/features/namespaces", true); reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); setHandlers(reader); setFeatures(reader); return reader; }
From source file:org.dhatim.delivery.AbstractParser.java
protected void configureReader(XMLReader reader, DefaultHandler2 handler, ExecutionContext execContext, Source source) throws SAXException { if (reader instanceof SmooksXMLReader) { ((SmooksXMLReader) reader).setExecutionContext(execContext); }//from w ww. j a v a 2 s .c o m if (reader instanceof JavaXMLReader) { if (!(source instanceof JavaSource)) { throw new SAXException("A " + JavaSource.class.getName() + " source must be supplied for " + JavaXMLReader.class.getName() + " implementations."); } ((JavaXMLReader) reader).setSourceObjects(((JavaSource) source).getSourceObjects()); } reader.setContentHandler(handler); try { reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); } catch (SAXNotRecognizedException e) { logger.debug( "XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader '" + reader.getClass().getName() + "'."); } }
From source file:org.dhatim.delivery.AbstractParser.java
public static boolean isFeatureOn(String name, SmooksResourceConfiguration saxDriverConfig) throws SAXException { boolean featureOn = isFeature(name, FeatureValue.ON, saxDriverConfig); // Make sure the same feature is not also configured off... if (featureOn && isFeature(name, FeatureValue.OFF, saxDriverConfig)) { throw new SAXException("Invalid Smooks configuration. Feature '" + name + "' is explicitly configured 'on' and 'off'. Must be one or the other!"); }//from w w w . j a va 2s .com return featureOn; }
From source file:org.dhatim.delivery.AbstractParser.java
public static boolean isFeatureOff(String name, SmooksResourceConfiguration saxDriverConfig) throws SAXException { boolean featureOff = isFeature(name, FeatureValue.OFF, saxDriverConfig); // Make sure the same feature is not also configured on... if (featureOff && isFeature(name, FeatureValue.ON, saxDriverConfig)) { throw new SAXException("Invalid Smooks configuration. Feature '" + name + "' is explicitly configured 'on' and 'off'. Must be one or the other!"); }//from ww w . ja v a2 s . c o m return featureOff; }
From source file:org.dhatim.delivery.sax.SAXHandler.java
public void startDTD(String name, String publicId, String systemId) throws SAXException { DocType.setDocType(name, publicId, systemId, null, execContext); if (writer != null) { DocType.DocumentTypeData docTypeData = DocType.getDocType(execContext); if (docTypeData != null) { try { DocType.serializeDoctype(docTypeData, writer); } catch (IOException e) { throw new SAXException("Failed to serialize DOCTYPE."); }/* w ww . j av a2s . com*/ } } }
From source file:org.dhatim.edisax.unedifact.handlers.r41.UNEdifact41ControlBlockHandlerFactory.java
public ControlBlockHandler getControlBlockHandler(String segCode) throws SAXException { if (segCode.equals("UNH")) { return new UNHHandler(unhSegment, untSegment, hierarchyChangeListener); } else if (segCode.equals("UNG")) { return new UNGHandler(ungSegment, uneSegment); } else if (segCode.equals("UNA")) { return new UNAHandler(); } else if (segCode.equals("UNB")) { return new UNBHandler(unbSegment, unzSegment, toCharsetMapping); } else if (segCode.charAt(0) == 'U') { return new GenericHandler(); }// ww w .j ava2s. c o m throw new SAXException("Unknown/Unexpected UN/EDIFACT control block segment code '" + segCode + "'."); }
From source file:org.dita.dost.module.GenMapAndTopicListModule.java
private XMLReader getXmlReader(final String format) throws SAXException { for (final Map.Entry<String, String> e : parserMap.entrySet()) { if (format != null && format.equals(e.getKey())) { try { return (XMLReader) this.getClass().forName(e.getValue()).newInstance(); } catch (final InstantiationException | ClassNotFoundException | IllegalAccessException ex) { throw new SAXException(ex); }/*from w w w . jav a2 s . co m*/ } } return reader; }
From source file:org.dita.dost.module.reader.AbstractReaderModule.java
private XMLReader getXmlReader(final String format) throws SAXException { for (final Map.Entry<String, String> e : parserMap.entrySet()) { if (format != null && format.equals(e.getKey())) { try { return (XMLReader) Class.forName(e.getValue()).newInstance(); } catch (final InstantiationException | ClassNotFoundException | IllegalAccessException ex) { throw new SAXException(ex); }//from w w w .j a v a 2 s . co m } } return reader; }
From source file:org.dspace.app.util.DCInputsReader.java
/** * Process the form-definitions section of the XML file. Each element is * formed thusly: <form name="formname">...pages...</form> Each pages * subsection is formed: <page number="#"> ...fields... </page> Each field * is formed from: dc-element, dc-qualifier, label, hint, input-type name, * required text, and repeatable flag.//ww w. j a v a 2 s. c o m */ private void processDefinition(Node e) throws SAXException, DCInputsReaderException { int numForms = 0; NodeList nl = e.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node nd = nl.item(i); // process each form definition if (nd.getNodeName().equals("form")) { numForms++; String formName = getAttribute(nd, "name"); if (formName == null) { throw new SAXException("form element has no name attribute"); } List<Map<String, String>> fields = new ArrayList<Map<String, String>>(); // the form contains fields formDefns.put(formName, fields); NodeList pl = nd.getChildNodes(); int lenpg = pl.getLength(); for (int j = 0; j < lenpg; j++) { Node npg = pl.item(j); if (npg.getNodeName().equals("field")) { // process each field definition Map<String, String> field = new HashMap<String, String>(); processField(formName, npg, field); fields.add(field); // we omit the duplicate validation, allowing multiple // fields definition for // the same metadata and different visibility/type-bind } } // sanity check number of fields if (fields.size() < 1) { throw new DCInputsReaderException("Form " + formName + " has no fields"); } } } if (numForms == 0) { throw new DCInputsReaderException("No form definition found"); } }
From source file:org.dspace.app.util.DCInputsReader.java
/** * Process parts of a field//from w w w. java 2 s . c o m * At the end, make sure that input-types 'qualdrop_value' and * 'twobox' are marked repeatable. Complain if dc-element, label, * or input-type are missing. */ private void processField(String formName, Node n, Map<String, String> field) throws SAXException { NodeList nl = n.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node nd = nl.item(i); if (!isEmptyTextNode(nd)) { String tagName = nd.getNodeName(); String value = getValue(nd); field.put(tagName, value); if (tagName.equals("input-type")) { if (value.equals("dropdown") || value.equals("qualdrop_value") || value.equals("list")) { String pairTypeName = getAttribute(nd, PAIR_TYPE_NAME); if (pairTypeName == null) { throw new SAXException("Form " + formName + ", field " + field.get("dc-element") + "." + field.get("dc-qualifier") + " has no name attribute"); } else { field.put(PAIR_TYPE_NAME, pairTypeName); } } } else if (tagName.equals("vocabulary")) { String closedVocabularyString = getAttribute(nd, "closed"); field.put("closedVocabulary", closedVocabularyString); } else if (tagName.equals("language")) { if (Boolean.valueOf(value)) { String pairTypeName = getAttribute(nd, PAIR_TYPE_NAME); if (pairTypeName == null) { throw new SAXException("Form " + formName + ", field " + field.get("dc-element") + "." + field.get("dc-qualifier") + " has no language attribute"); } else { field.put(PAIR_TYPE_NAME, pairTypeName); } } } } } String missing = null; if (field.get("dc-element") == null) { missing = "dc-element"; } if (field.get("label") == null) { missing = "label"; } if (field.get("input-type") == null) { missing = "input-type"; } if (missing != null) { String msg = "Required field " + missing + " missing on form " + formName; throw new SAXException(msg); } String type = field.get("input-type"); if (type.equals("twobox") || type.equals("qualdrop_value")) { String rpt = field.get("repeatable"); if ((rpt == null) || ((!rpt.equalsIgnoreCase("yes")) && (!rpt.equalsIgnoreCase("true")))) { String msg = "The field \'" + field.get("label") + "\' must be repeatable"; throw new SAXException(msg); } } }