List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:org.dspace.app.util.DCInputsReader.java
/** * Process the form-value-pairs section of the XML file. * Each element is formed thusly:/*from w w w . j av a 2 s .co m*/ * <value-pairs name="..." dc-term="..."> * <pair> * <display>displayed name-</display> * <storage>stored name</storage> * </pair> * For each value-pairs element, create a new vector, and extract all * the pairs contained within it. Put the display and storage values, * respectively, in the next slots in the vector. Store the vector * in the passed in hashmap. */ private void processValuePairs(Node e) throws SAXException { NodeList nl = e.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node nd = nl.item(i); String tagName = nd.getNodeName(); // process each value-pairs set if (tagName.equals("value-pairs")) { String pairsName = getAttribute(nd, PAIR_TYPE_NAME); String dcTerm = getAttribute(nd, "dc-term"); if (pairsName == null) { String errString = "Missing name attribute for value-pairs for DC term " + dcTerm; throw new SAXException(errString); } List<String> pairs = new ArrayList<String>(); valuePairs.put(pairsName, pairs); NodeList cl = nd.getChildNodes(); int lench = cl.getLength(); for (int j = 0; j < lench; j++) { Node nch = cl.item(j); String display = null; String storage = null; if (nch.getNodeName().equals("pair")) { NodeList pl = nch.getChildNodes(); int plen = pl.getLength(); for (int k = 0; k < plen; k++) { Node vn = pl.item(k); String vName = vn.getNodeName(); if (vName.equals("displayed-value")) { display = getValue(vn); } else if (vName.equals("stored-value")) { storage = getValue(vn); if (storage == null) { storage = ""; } } // ignore any children that aren't 'display' or 'storage' } pairs.add(display); pairs.add(storage); } // ignore any children that aren't a 'pair' } } // ignore any children that aren't a 'value-pair' } }
From source file:org.dspace.app.util.SubmissionConfigReader.java
/** * Process the submission-map section of the XML file. Each element looks * like: <name-map collection-handle="hdl" submission-name="name" /> Extract * the collection handle and item submission name, put name in hashmap keyed * by the collection handle.// w w w . java 2s . c o m */ private void processMap(Node e) throws SAXException { NodeList nl = e.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node nd = nl.item(i); if (nd.getNodeName().equals("name-map")) { String id = getAttribute(nd, "collection-handle"); String value = getAttribute(nd, "submission-name"); String content = getValue(nd); if (id == null) { throw new SAXException( "name-map element is missing collection-handle attribute in 'item-submission.xml'"); } if (value == null) { throw new SAXException( "name-map element is missing submission-name attribute in 'item-submission.xml'"); } if (content != null && content.length() > 0) { throw new SAXException( "name-map element has content in 'item-submission.xml', it should be empty."); } collectionToSubmissionConfig.put(id, value); } // ignore any child node that isn't a "name-map" } }
From source file:org.dspace.app.util.SubmissionConfigReader.java
/** * Process the "step-definition" section of the XML file. Each element is * formed thusly: <step id="unique-id"> ...step_fields... </step> The valid * step_fields are: heading, processing-servlet. * <P>/* w w w .j av a2 s . c om*/ * Extract the step information (from the step_fields) and place in a * HashMap whose key is the step's unique id. */ private void processStepDefinition(Node e) throws SAXException, SubmissionConfigReaderException { stepDefns = new HashMap<String, Map<String, String>>(); NodeList nl = e.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node nd = nl.item(i); // process each step definition if (nd.getNodeName().equals("step")) { String stepID = getAttribute(nd, "id"); if (stepID == null) { throw new SAXException( "step element has no 'id' attribute in 'item-submission.xml', which is required in the 'step-definitions' section"); } else if (stepDefns.containsKey(stepID)) { throw new SAXException( "There are two step elements with the id '" + stepID + "' in 'item-submission.xml'"); } Map<String, String> stepInfo = processStepChildNodes("step-definition", nd); stepDefns.put(stepID, stepInfo); } // ignore any child that is not a 'step' } // Sanity check number of step definitions if (stepDefns.size() < 1) { throw new SubmissionConfigReaderException( "step-definition section has no steps! A step with id='collection' is required in 'item-submission.xml'!"); } }
From source file:org.dspace.app.util.SubmissionConfigReader.java
/** * Process the "submission-definition" section of the XML file. Each element * is formed thusly: <submission-process name="submitName">...steps...</submit-process> * Each step subsection is formed: <step> ...step_fields... </step> (with * optional "id" attribute, to reference a step from the <step-definition> * section). The valid step_fields are: heading, class-name. * <P>// w ww . ja v a2s .com * Extract the submission-process name and steps and place in a HashMap * whose key is the submission-process's unique name. */ private void processSubmissionDefinition(Node e) throws SAXException, SubmissionConfigReaderException { int numSubmitProcesses = 0; List<String> submitNames = new ArrayList<String>(); // find all child nodes of the 'submission-definition' node and loop // through NodeList nl = e.getChildNodes(); int len = nl.getLength(); for (int i = 0; i < len; i++) { Node nd = nl.item(i); // process each 'submission-process' node if (nd.getNodeName().equals("submission-process")) { numSubmitProcesses++; String submitName = getAttribute(nd, "name"); if (submitName == null) { throw new SAXException( "'submission-process' element has no 'name' attribute in 'item-submission.xml'"); } else if (submitNames.contains(submitName)) { throw new SAXException("There are two 'submission-process' elements with the name '" + submitName + "' in 'item-submission.xml'."); } submitNames.add(submitName); // the 'submission-process' definition contains steps List<Map<String, String>> steps = new ArrayList<Map<String, String>>(); submitDefns.put(submitName, steps); // loop through all the 'step' nodes of the 'submission-process' NodeList pl = nd.getChildNodes(); int lenStep = pl.getLength(); for (int j = 0; j < lenStep; j++) { Node nStep = pl.item(j); // process each 'step' definition if (nStep.getNodeName().equals("step")) { // check for an 'id' attribute String stepID = getAttribute(nStep, "id"); Map<String, String> stepInfo; // if this step has an id, load its information from the // step-definition section if ((stepID != null) && (stepID.length() > 0)) { if (stepDefns.containsKey(stepID)) { // load the step information from the // step-definition stepInfo = stepDefns.get(stepID); } else { throw new SubmissionConfigReaderException("The Submission process config named " + submitName + " contains a step with id=" + stepID + ". There is no step with this 'id' defined in the 'step-definition' section of 'item-submission.xml'."); } // Ignore all children of a step element with an // "id" } else { // get information about step from its children // nodes stepInfo = processStepChildNodes("submission-process", nStep); } steps.add(stepInfo); } // ignore any child that is not a 'step' } // sanity check number of steps if (steps.size() < 1) { throw new SubmissionConfigReaderException("Item Submission process config named " + submitName + " has no steps defined in 'item-submission.xml'"); } } } if (numSubmitProcesses == 0) { throw new SubmissionConfigReaderException( "No 'submission-process' elements/definitions found in 'item-submission.xml'"); } }
From source file:org.dspace.app.xmlui.cocoon.DSpaceFeedGenerator.java
/** * Generate the syndication feed.// ww w .j a va 2s . c o m */ public void generate() throws IOException, SAXException, ProcessingException { try { Context context = ContextUtil.obtainContext(objectModel); DSpaceObject dso = null; if (handle != null && !handle.contains("site")) { dso = HandleManager.resolveToObject(context, handle); if (dso == null) { // If we were unable to find a handle then return page not found. throw new ResourceNotFoundException( "Unable to find DSpace object matching the given handle: " + handle); } if (!(dso.getType() == Constants.COLLECTION || dso.getType() == Constants.COMMUNITY)) { // The handle is valid but the object is not a container. throw new ResourceNotFoundException("Unable to syndicate DSpace object: " + handle); } } SyndicationFeed feed = new SyndicationFeed(SyndicationFeed.UITYPE_XMLUI); Request request = ObjectModelHelper.getRequest(objectModel); String pageNumberParam = StringUtils.trimToNull(request.getParameter("page")); int pageNumber = StringUtils.isNumeric(pageNumberParam) ? Integer.parseInt(pageNumberParam) : 0; feed.setCurrentPage(pageNumber); feed.populate(ObjectModelHelper.getRequest(objectModel), dso, getRecentlySubmittedItems(context, dso, pageNumber), FeedUtils.i18nLabels); feed.setType(this.format); Document dom = feed.outputW3CDom(); FeedUtils.unmangleI18N(dom); DOMStreamer streamer = new DOMStreamer(contentHandler, lexicalHandler); streamer.stream(dom); } catch (IllegalArgumentException iae) { throw new ResourceNotFoundException("Syndication feed format, '" + this.format + "', is not supported.", iae); } catch (FeedException fe) { throw new SAXException(fe); } catch (SQLException sqle) { throw new SAXException(sqle); } }
From source file:org.easyxml.parser.EasySAXParser.java
@Override public void endDocument() throws SAXException { super.endDocument(); if (!StringUtils.isBlank(path)) throw new SAXException("There are still some path unsolved: " + path); }
From source file:org.easyxml.parser.EasySAXParser.java
@Override public void endElement(String uri, String localName, String qName) throws SAXException { int lastSignPos = path.lastIndexOf(Element.DefaultElementPathSign); if (!path.endsWith(qName)) { String lastTag = path.substring(lastSignPos + 1); throw new SAXException("Now the expected endElement is </" + lastTag + ">, instead of: " + qName); }//from w w w . j a va 2s . co m // Remove the tag from path path = path.substring(0, lastSignPos == -1 ? 0 : lastSignPos); if (innerText.length() > 0) { currentElement.setValue(innerText.toString()); // Reset the StringBuilder innerText.setLength(0); } lastContainer = lastContainer.getParent(); }
From source file:org.easyxml.xml.Element.java
/** * //from www.ja v a 2 s. c o m * Method to add a new Attribute to this element. * * @param name * - Name of the new Attribute * * @param value * - Value of the new Attribute * * @return This element for cascading processing. * * @throws SAXException */ public Element addAttribute(String name, String value) throws SAXException { if (this.attributes == null) this.attributes = new LinkedHashMap<String, Attribute>(); // The name of an attribute cannot be duplicated according to XML // specification if (this.attributes.containsKey(name)) throw new SAXException("Attribute name must be unique within an Element."); if (value != null) this.attributes.put(name, new Attribute(this, name, value)); return this; }
From source file:org.eclipse.mylyn.commons.core.CoreUtil.java
/** * Returns a new {@link XMLReader} instance using default factories. * //from ww w . j a va2 s. c om * @since 3.9 */ public static SAXParser newSaxParser() throws SAXException { try { return saxParserFactory.newSAXParser(); } catch (ParserConfigurationException e) { throw new SAXException(e); } }
From source file:org.eclipse.rdf4j.rio.rdfxml.RDFXMLParser.java
/** * Implementation of SAX ErrorHandler.error */// w ww .ja v a2s .c o m @Override public void error(SAXParseException exception) throws SAXException { try { this.reportError(exception, XMLParserSettings.FAIL_ON_SAX_NON_FATAL_ERRORS); } catch (RDFParseException rdfpe) { throw new SAXException(rdfpe); } }