List of usage examples for org.xml.sax SAXException SAXException
public SAXException(String message, Exception e)
From source file:eu.annocultor.converter.ConverterHandler.java
@Override public void characters(char[] characters, int begin, int end) throws SAXException { try {//from www. j a v a 2 s . c o m if (tagBeingIgnored != null) return; // append to the top element at the stack / current element if (tagPath.size() > 0) { tagPath.peek().appendValue(characters, begin, end); } } catch (Exception e) { throw new SAXException("Exception on characaters " + new String(characters), e); } }
From source file:io.inkstand.jcr.util.JCRContentHandler.java
/** * Invoked on rootNode element/*from ww w. java2 s . com*/ * * @param attributes * the DOM attributes of the root node element * * @throws SAXException */ private void startElementRootNode(final Attributes attributes) throws SAXException { LOG.debug("Found rootNode"); try { nodeStack.push(newNode(null, attributes)); } catch (final RepositoryException e) { throw new SAXException("Could not create node", e); } }
From source file:io.inkstand.jcr.util.JCRContentHandler.java
/** * Invoked on node element//w w w. j a v a 2 s .c o m * * @param attributes * the DOM attributes of the node element * * @throws SAXException */ private void startElementNode(final Attributes attributes) throws SAXException { LOG.debug("Found node"); try { nodeStack.push(newNode(nodeStack.peek(), attributes)); } catch (final RepositoryException e) { throw new SAXException("Could not create node", e); } }
From source file:io.inkstand.jcr.util.JCRContentHandler.java
/** * Invoked on mixin element/*w w w .j a va 2 s .co m*/ * * @param attributes * the DOM attributes of the mixin element * * @throws SAXException */ private void startElementMixin(final Attributes attributes) throws SAXException { LOG.debug("Found mixin declaration"); try { addMixin(nodeStack.peek(), attributes); } catch (final RepositoryException e) { throw new SAXException("Could not add mixin type", e); } }
From source file:hd3gtv.mydmam.db.BackupDbCassandra.java
public void endElement(String uri, String localName, String qName) throws SAXException { try {// w w w.java 2 s . c o m if (qName.equalsIgnoreCase("columnfamily")) { if (mutator != null) { mutator.execute().getResult(); } return; } if (qName.equalsIgnoreCase("coldef")) { return; } if (qName.equalsIgnoreCase("key")) { if (mutator_key_count > max_mutator_key_count) { mutator.execute().getResult(); mutator = CassandraDb.prepareMutationBatch(); mutator_key_count = 0; } return; } if (qName.equalsIgnoreCase("col")) { try { if (col_ttl > 0) { mutator.withRow(columnfamily, key_name).putColumn(col_name, quotedprintablecodec.decode(rawtext.toString().getBytes()), col_ttl); } else { mutator.withRow(columnfamily, key_name).putColumn(col_name, quotedprintablecodec.decode(rawtext.toString().getBytes())); } } catch (DecoderException e) { Log2.log.error("Bad column content decoding", e, new Log2Dump("raw content", rawtext.toString())); e.printStackTrace(); } return; } } catch (ConnectionException e) { throw new SAXException("Can't access to CassandraDb", e); } Log2Dump dump = new Log2Dump(); dump.add("qName", qName); Log2.log.error("Unknow end qName", null, dump); }
From source file:me.crime.loader.DataBaseLoader.java
private void saveData(String method, String data, Object obj) throws SAXException { Method getMethod = getMethod("get" + method, obj); Method setMethod = getMethod("set" + method, obj); try {/* w w w . ja v a2s. c om*/ Object args[] = new Object[1]; if (getMethod.getGenericReturnType() == Integer.TYPE) { args[0] = new Integer(data); } else if (getMethod.getGenericReturnType() == String.class) { args[0] = data; } else if (getMethod.getGenericReturnType() == Double.TYPE) { args[0] = new Double(data); } else if (getMethod.getGenericReturnType() == Long.TYPE) { args[0] = new Long(data); } else if (getMethod.getGenericReturnType() == Calendar.class) { String[] dt = data.split(":"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.parseInt(dt[0])); cal.set(Calendar.MONTH, Integer.parseInt(dt[1])); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dt[2])); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dt[3])); cal.set(Calendar.MINUTE, Integer.parseInt(dt[4])); cal.set(Calendar.SECOND, Integer.parseInt(dt[5])); cal.set(Calendar.MILLISECOND, Integer.parseInt(dt[5])); if (cal.get(Calendar.YEAR) < 10) { cal.set(Calendar.YEAR, 2000 + cal.get(Calendar.YEAR)); } args[0] = cal; } setMethod.invoke(obj, args); } catch (Exception e) { DataBaseLoader.log_.error("saveData: " + method, e); throw new SAXException("saveData:", e); } }
From source file:hd3gtv.mydmam.db.BackupDbElasticsearch.java
public void endElement(String uri, String localName, String qName) throws SAXException { try {/*from w ww .j a v a2s . co m*/ if (qName.equalsIgnoreCase("index")) { if (bulk_op == null) { return; } bulk_op.terminateBulk(); return; } if (qName.equalsIgnoreCase("mapping")) { if (Elasticsearch.isIndexExists(index_name) == false) { Elasticsearch.createIndex(index_name); } Elasticsearch.addMappingToIndex(index_name, mapping_name, getContent()); return; } if (qName.equalsIgnoreCase("settings")) { return; } // throw new SAXException("Can't declare mapping", e); if (qName.equalsIgnoreCase("key")) { if (bulk_op == null) { bulk_op = Elasticsearch.prepareBulk(); } IndexRequestBuilder index = bulk_op.getClient().prepareIndex(); index.setId(key_name); index.setIndex(index_name); index.setType(type_name); if (ttl > 0) { index.setTTL(ttl); } index.setSource(getContent()); bulk_op.add(index); return; } } catch (DecoderException e) { throw new SAXException("Bad XML content decoding", e); } Log2Dump dump = new Log2Dump(); dump.add("qName", qName); Log2.log.error("Unknow end qName", null, dump); }
From source file:io.inkstand.jcr.util.JCRContentHandler.java
private void endElementProperty() throws SAXException { LOG.debug("Closing property"); final PropertyDescriptor pd = propertyStack.pop(); try {//ww w. ja va 2 s . c o m pd.setValue(parseValue(pd.getJcrType(), textStack.pop())); addProperty(nodeStack.peek(), pd); } catch (final RepositoryException e) { throw new SAXException("Could set property value", e); } }
From source file:eu.annocultor.converter.ConverterHandler.java
@Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { try {/* ww w .jav a 2 s . c o m*/ if (endRawFilter(qName)) { return; } // closing a triple if (tagPath.size() > 0) { // process this tag value Path closingTag = tagPath.pop(); DataObject dataObject = peekNotYetCompletedDataObject(); if (dataObject != null) { XmlValue value = new XmlValue(StringUtils.trim(closingTag.getValue()), closingTag.getLang()); if (value != null) { try { dataObject.addValue(closingTag, value); } catch (Exception e) { throw new SAXException("error on " + closingTag, e); } if (dataObject.size() > 10000) { throw new SAXException( "Data object is longer than 10000 elements. This suggests that the record separating XML path is incorrect"); } } } // closing a record List<ObjectRule> rules; try { rules = task.getRuleForSourcePath(closingTag); } catch (Exception e) { throw new SAXException(e); } if (rules.size() > 1) throw new SAXException("Multiple rules found on path: " + tagPath.peek()); if (rules.size() == 1) { /* * This is the end of a data object */ // check consistency if (closingTag == null) throw new SAXException("Data object separator tag is not closed"); if (!partsNotYetCompleted.peek().getSeparatingPath().equals(closingTag)) throw new SAXException( "Open-close tags mismatch on tag " + localName + " value " + closingTag.getValue()); // complete this part partsCompleted.add(partsNotYetCompleted.pop()); // if we completed all parts - process them if (partsNotYetCompleted.isEmpty()) { passedARecord = true; currentPassedRecord++; while (!partsCompleted.isEmpty()) { try { processDataObject(); } catch (Exception e) { try { reportException(e); } catch (Exception ex) { throw new SAXException(ex); } throw new SAXException(e); } partsCompleted.pop(); } } } // append this tag value to the parent if (htmlMode) if (tagPath.size() > 0) { // TODO: should be local tag ipv full ns tagPath tagPath.peek().appendValue('<' + tagPath.peek().getPath() + '>' + closingTag.getValue() + "</" + tagPath.peek().getPath() + ">"); } } else throw new SAXException("Error in XML structure"); } catch (Exception e) { throw new SAXException("Exception on ending tag " + namespaceURI + localName, e); } }
From source file:eu.esdihumboldt.hale.io.wfs.AbstractWFSWriter.java
private Document parseResponse(HttpEntity entity) throws IOException, ParserConfigurationException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); byte[] data = EntityUtils.toByteArray(entity); try (InputStream response = new ByteArrayInputStream(data)) { return builder.parse(response); } catch (SAXException e) { String response = new String(data, StandardCharsets.UTF_8); throw new SAXException("Invalid XML response: " + response, e); }//from w w w. j a v a 2 s . c o m }