List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:com.connexta.arbitro.ctx.InputParser.java
/** * Standard handler routine for the XML parsing. * // w w w.j a v a 2s . co m * @param exception information on what caused the problem * * @throws SAXException always to halt parsing on errors */ public void error(SAXParseException exception) throws SAXException { if (logger.isErrorEnabled()) logger.error("Error on line " + exception.getLineNumber() + ": " + exception.getMessage()); throw new SAXException("invalid context document"); }
From source file:com.webcohesion.ofx4j.io.tagsoup.TagSoupHandler.java
public void endElement(String uri, String localName, String qName) throws SAXException { qName = qName.toUpperCase();// tag soup converts to lower case for HTML tags. if (LOG.isDebugEnabled()) { LOG.debug("END ELEMENT: " + qName); }/*ww w . java 2 s.co m*/ String lastElement; try { lastElement = processLastCharactersIfNecessary(); } catch (IOException e) { throw new SAXException(e); } //if this is the end element tag of the last element that was ended, we must be parsing an OFX 2.0 document. //otherwise, this is a potential end element of an OFX aggregate. if ((lastElement == null) || (!lastElement.equals(qName))) { if (eventStack.isEmpty()) { throw new IllegalStateException("End of element '" + qName + "' at an empty event stack."); } switch (eventStack.peek().getEventType()) { case CHARACTERS: throw new IllegalStateException("End of element '" + qName + "' with characters \"" + eventStack.peek().getEventValue() + "\" on the stack!"); case ELEMENT: if (qName.equals(eventStack.peek().getEventValue())) { //the last element on the stack is ours; we're ending an OFX aggregate. OFXParseEvent event = eventStack.pop(); String value = event.getEventValue(); if (LOG.isDebugEnabled()) { LOG.debug("Ending aggregate " + value); } try { this.ofxHandler.endAggregate(value); } catch (OFXParseException e) { throw new SAXException(e); } this.startedEvents.remove(event); break; } else { //ignore; tagsoup is just ending an OFX element for us. break; } default: //ignore; unknown OFX event } } }
From source file:com.sshtools.common.hosts.AbstractHostKeyVerification.java
/** * * * @param uri// ww w .j ava 2 s. c o m * @param localName * @param qname * @param attrs * * @throws SAXException */ public void startElement(String uri, String localName, String qname, Attributes attrs) throws SAXException { if (currentElement == null) { if (qname.equals("HostAuthorizations")) { allowedHosts.clear(); deniedHosts.clear(); currentElement = qname; } else { throw new SAXException("Unexpected document element!"); } } else { if (!currentElement.equals("HostAuthorizations")) { throw new SAXException("Unexpected parent element found!"); } if (qname.equals("AllowHost")) { String hostname = attrs.getValue("HostName"); String fingerprint = attrs.getValue("Fingerprint"); if ((hostname != null) && (fingerprint != null)) { if (log.isDebugEnabled()) { log.debug("AllowHost element for host '" + hostname + "' with fingerprint '" + fingerprint + "'"); } allowedHosts.put(hostname, fingerprint); currentElement = qname; } else { throw new SAXException("Requried attribute(s) missing!"); } } else if (qname.equals("DenyHost")) { String hostname = attrs.getValue("HostName"); if (hostname != null) { if (log.isDebugEnabled()) { log.debug("DenyHost element for host " + hostname); } deniedHosts.add(hostname); currentElement = qname; } else { throw new SAXException("Required attribute hostname missing"); } } else { log.warn("Unexpected " + qname + " element found in allowed hosts file"); } } }
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * Outputs a start or empty element tag if there is one stored. * @param end true if this method was called due to an endElement event, * i.e. an empty element tag has to be output. * @return true if something was output (needed for endElement to * determine, if a separate end tag must be output) *//*from ww w.ja v a2 s. c o m*/ private boolean processLastElement(boolean end) throws SAXException { if (lastQName != null) { StringBuffer out = new StringBuffer("<"); out.append(lastQName); out.append(nsDeclarations); nsDeclarations.setLength(0); // attributes int length = lastAttrs.getLength(); for (int i = 0; i < length; i++) { out.append(' ').append(lastAttrs.getQName(i)).append("=\""); char[] attChars = lastAttrs.getValue(i).toCharArray(); // output escaping for (int j = 0; j < attChars.length; j++) switch (attChars[j]) { case '&': out.append("&"); break; case '<': out.append("<"); break; case '>': out.append(">"); break; case '\"': out.append("""); break; case '\t': out.append("	"); break; case '\n': out.append("
"); break; case '\r': out.append("
"); break; default: j = encodeCharacters(attChars, j, out); } out.append('\"'); } out.append(end ? " />" : ">"); try { // stream string to writer writer.write(out.toString()); if (DEBUG) log.debug(out); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } lastQName = null; return true; } return false; }
From source file:com.connexta.arbitro.ctx.InputParser.java
/** * Standard handler routine for the XML parsing. * //from ww w . ja v a2 s . co m * @param exception information on what caused the problem * * @throws SAXException always to halt parsing on errors */ public void fatalError(SAXParseException exception) throws SAXException { if (logger.isErrorEnabled()) logger.error("FatalError on line " + exception.getLineNumber() + ": " + exception.getMessage()); throw new SAXException("invalid context document"); }
From source file:org.callimachusproject.xproc.Pipeline.java
private Pipe pipeSource(XdmNode source, XdmNodeFactory resolver, XProcConfiguration config) throws SAXException, IOException { Pipe pipe = null;//from w ww . j a v a2 s. c om XProcRuntime runtime = new XProcRuntime(config); try { CloseableURIResolver uriResolver = new CloseableURIResolver(resolver); CloseableEntityResolver entityResolver = new CloseableEntityResolver(resolver); runtime.setURIResolver(uriResolver); runtime.setEntityResolver(entityResolver); runtime.getResolver().setUnderlyingModuleURIResolver(resolver); runtime.getResolver().setUnderlyingUnparsedTextURIResolver(resolver); runtime.setHttpClient(client); XdmNode doc = this.pipeline; if (doc == null) { doc = resolver.parse(systemId); } if (doc == null) throw new InternalServerError("Missing pipeline: " + systemId); XPipeline xpipeline = runtime.use(doc); if (source != null) { xpipeline.writeTo("source", source); } return pipe = new Pipe(runtime, uriResolver, entityResolver, xpipeline, systemId); } catch (SaxonApiException e) { throw new SAXException(e); } finally { if (pipe == null) { runtime.setHttpClient(null); runtime.close(); } } }
From source file:com.netspective.commons.xml.template.Template.java
public Template[] getInheritedTemplates() throws SAXException { if (!calculatedInheritedTemplates) { Map myTemplatesMap = templateCatalog.getProducerTemplates(templateProducer); if (myTemplatesMap == null) throw new SAXException("Unable to locate templates catalog for namespace '" + templateProducer.getNameSpaceId() + "'"); if (templateProducer.getTemplateInhAttrName() != null) { String inheritTemplatesNames = getAttributes().getValue(templateProducer.getTemplateInhAttrName()); if (inheritTemplatesNames != null && inheritTemplatesNames.length() > 0) { List inherited = new ArrayList(); StringTokenizer st = new StringTokenizer(inheritTemplatesNames, ","); while (st.hasMoreTokens()) { String templateName = st.nextToken().trim(); Template template = (Template) myTemplatesMap.get(templateName); if (template == null) throw new SAXException("Inherited template '" + templateName + "' for template '" + templateProducer.getElementName() + "' (namespace '" + templateProducer.getNameSpaceId() + "') was not found in the active document. Available: " + myTemplatesMap.keySet() + " at " + getDefnSourceLocation()); inherited.add(template); }/*from w w w .ja v a 2 s. c o m*/ inheritedTemplates = (Template[]) inherited.toArray(new Template[inherited.size()]); } else inheritedTemplates = null; } else inheritedTemplates = null; calculatedInheritedTemplates = true; } return inheritedTemplates; }
From source file:io.github.msdk.io.mzdata.MzDataSaxHandler.java
/** * {@inheritDoc}/*www.j a v a 2s .c o m*/ * * endElement() */ @SuppressWarnings("null") public void endElement(String namespaceURI, String sName, String qName) throws SAXException { if (canceled) throw new SAXException("Parsing Cancelled"); // <spectrumInstrument> if (qName.equalsIgnoreCase("spectrumInstrument")) { spectrumInstrumentFlag = false; } // <precursor> if (qName.equalsIgnoreCase("precursor")) { precursorFlag = false; } // <spectrum> if (qName.equalsIgnoreCase("spectrum")) { spectrumInstrumentFlag = false; // Auto-detect whether this scan is centroided MsSpectrumType spectrumType = SpectrumTypeDetectionAlgorithm.detectSpectrumType(mzBuffer, intensityBuffer, peaksCount); // Create a new scan MsFunction msFunction = MSDKObjectBuilder.getMsFunction(msLevel); MsScan newScan = MSDKObjectBuilder.getMsScan(dataStore, scanNumber, msFunction); newScan.setDataPoints(mzBuffer, intensityBuffer, peaksCount); newScan.setSpectrumType(spectrumType); newScan.setPolarity(polarity); if (retentionTime != null) { ChromatographyInfo chromInfo = MSDKObjectBuilder.getChromatographyInfo1D(SeparationType.UNKNOWN, retentionTime); newScan.setChromatographyInfo(chromInfo); } if (precursorMz != null) { IsolationInfo isolation = MSDKObjectBuilder.getIsolationInfo(Range.singleton(precursorMz), null, precursorMz, precursorCharge, null); newScan.getIsolations().add(isolation); } // Add the scan to the file newRawFile.addScan(newScan); parsedScans++; } // <mzArrayBinary> if (qName.equalsIgnoreCase("mzArrayBinary")) { mzArrayBinaryFlag = false; // Allocate space for the whole array if (mzBuffer.length < peaksCount) mzBuffer = new double[peaksCount * 2]; byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes()); ByteBuffer currentMzBytes = ByteBuffer.wrap(peakBytes); if (endian.equals("big")) { currentMzBytes = currentMzBytes.order(ByteOrder.BIG_ENDIAN); } else { currentMzBytes = currentMzBytes.order(ByteOrder.LITTLE_ENDIAN); } for (int i = 0; i < peaksCount; i++) { if (precision == null || precision.equals("32")) mzBuffer[i] = (double) currentMzBytes.getFloat(); else mzBuffer[i] = currentMzBytes.getDouble(); } } // <intenArrayBinary> if (qName.equalsIgnoreCase("intenArrayBinary")) { intenArrayBinaryFlag = false; // Allocate space for the whole array if (intensityBuffer.length < peaksCount) intensityBuffer = new float[peaksCount * 2]; byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes()); ByteBuffer currentIntensityBytes = ByteBuffer.wrap(peakBytes); if (endian.equals("big")) { currentIntensityBytes = currentIntensityBytes.order(ByteOrder.BIG_ENDIAN); } else { currentIntensityBytes = currentIntensityBytes.order(ByteOrder.LITTLE_ENDIAN); } for (int i = 0; i < peaksCount; i++) { if (precision == null || precision.equals("32")) intensityBuffer[i] = currentIntensityBytes.getFloat(); else intensityBuffer[i] = (float) currentIntensityBytes.getDouble(); } } }
From source file:me.crime.loader.DataBaseLoader.java
private Method getMethod(String methodName, Object obj) throws SAXException { Method[] methods = obj.getClass().getMethods(); for (Method m : methods) { if (m.getName().compareTo(methodName) == 0) { return m; }//from w w w . j a va 2 s . c o m } throw new SAXException("invalid method: " + methodName); }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.WsConfigParserHandler.java
private void processSimpleScheduler(Attributes attrs) throws SAXException { if (currStep == null) { throw new SAXParseException( StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.malformed.configuration2", SCHED_SIMPLE_ELMT, STEP_ELMT), currParseLocation);/* w w w. j a v a 2 s . c o m*/ } if (currStep.getSchedulerData() != null) { throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME, "WsConfigParserHandler.element.has.multiple", STEP_ELMT, SCHED_CRON_ELMT, SCHED_SIMPLE_ELMT, getLocationInfo())); } Integer interval = null; String timeUnits = null; Integer repeatCount = null; for (int i = 0; i < attrs.getLength(); i++) { String attName = attrs.getQName(i); String attValue = attrs.getValue(i); if (INTERVAL_ATTR.equals(attName)) { interval = Integer.parseInt(attValue); } else if (UNITS_ATTR.equals(attName)) { timeUnits = attValue; } else if (REPEATS_ATTR.equals(attName)) { repeatCount = Integer.parseInt(attValue); } } if (interval == null || interval < 0) { throw new SAXException(StreamsResources.getStringFormatted(WsStreamConstants.RESOURCE_BUNDLE_NAME, "WsConfigParserHandler.attr.missing.or.illegal", SCHED_SIMPLE_ELMT, INTERVAL_ATTR, interval, getLocationInfo())); } SimpleSchedulerData schedData = new SimpleSchedulerData(interval); schedData.setUnits( StringUtils.isEmpty(timeUnits) ? TimeUnit.MILLISECONDS : TimeUnit.valueOf(timeUnits.toUpperCase())); schedData.setRepeatCount(repeatCount); currStep.setSchedulerData(schedData); }