List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:org.fosstrak.epcis.repository.capture.CaptureOperationsModule.java
/** * (nkef) Takes an XML document node, parses it as EPCIS Master Data and * inserts the data into the database. The parse routine is generic for all * Vocabulary types;//from ww w. j a v a 2 s . c o m * * @param vocNode * The current vocabulary node. * @param vocType * The current vocabulary type. * @throws Exception * @throws DOMException */ private void handleVocabulary(Session session, final Node vocNode, final String vocType) throws DOMException, SAXException, InvalidFormatException { if (vocNode == null) { // nothing to do return; } else if (vocNode.getChildNodes().getLength() == 0) { throw new SAXException("Vocabulary element '" + vocNode.getNodeName() + "' has no children elements."); } for (int i = 0; i < vocNode.getChildNodes().getLength(); i++) { Node curVocNode = vocNode.getChildNodes().item(i); if (isTextOrComment(curVocNode)) { continue; } for (int j = 0; j < curVocNode.getChildNodes().getLength(); j++) { Node curVocElemNode = curVocNode.getChildNodes().item(j); if (isTextOrComment(curVocElemNode)) { continue; } LOG.debug(" processing vocabulary '" + curVocElemNode.getNodeName() + "'"); String curVocElemId = curVocElemNode.getAttributes().getNamedItem("id").getNodeValue(); /* * vocabularyElementEditMode 1: insert((it can be anything * except 2,3,4)) 2: alterURI 3: singleDelete 4: Delete element * with it's direct or indirect descendants */ String vocElemEditMode = ""; if (!(curVocElemNode.getAttributes().getNamedItem("mode") == null)) { vocElemEditMode = curVocElemNode.getAttributes().getNamedItem("mode").getNodeValue(); } else { vocElemEditMode = "1"; } VocabularyElement curVocElem = getOrEditVocabularyElement(session, vocType, curVocElemId, vocElemEditMode); // ***************************************** if (curVocElem != null) { for (int k = 0; k < curVocElemNode.getChildNodes().getLength(); k++) { Node curVocAttrNode = curVocElemNode.getChildNodes().item(k); if (isTextOrComment(curVocAttrNode)) { continue; } LOG.debug(" processing vocabulary attribute '" + curVocAttrNode.getNodeName() + "'"); String curVocAttrId = curVocAttrNode.getAttributes().getNamedItem("id").getNodeValue(); String curVocAttrValue = parseVocAttributeValue(curVocAttrNode); /* * vocabularyAttributeEditMode 1: Insert (it can be * anything except 3)) 2: Alter Attribute Value (it can * be anything except 3) 3: Delete Attribute (required) */ String vocabularyAttributeEditMode = ""; if (!(curVocAttrNode.getAttributes().getNamedItem("mode") == null)) { vocabularyAttributeEditMode = curVocAttrNode.getAttributes().getNamedItem("mode") .getNodeValue(); } else { vocabularyAttributeEditMode = "add/alter"; } getOrEditVocabularyAttributeElement(session, vocType, curVocElem.getId(), curVocAttrId, curVocAttrValue, vocabularyAttributeEditMode); } } // ***************************************** } } }
From source file:org.gbif.harvest.digir.DigirHarvesterTest.java
/** * Test method for {@link org.gbif.harvest.biocase.BiocaseHarvester#search(String, String, String, String, String, * String, Boolean, String, int)}. Difference from test3Harvest() being that this mocks the RequestUtils execute * method always returning a WrappedSaxException instead of a Diagnostics object. *//* w w w .j a v a 2 s . com*/ @Test public void testHarvestWithMockSAXException() throws IOException, OperationStoppedException, HarvesterException { // Mocked SAXException RequestUtils requestUtils = mock(RequestUtils.class); when(requestUtils.executeGetRequestAndReturnDiagnostics(anyString(), any(ProtocolTypeEnum.class), any(RequestResponseWriterManager.class))) .thenThrow(new WrappedSaxException(new SAXException("Mocked SAXException"))); harvester = new DigirHarvester(new TemplateUtils(), fileUtils, requestUtils, new DigesterUtils(fileUtils), gbifLogger); // runs through all name ranges, doesn't just terminate first time it encounters a SAXException harvester.search(TEST_RESOURCE, TEST_DESTINATION, targetDirectory.getAbsolutePath(), TEST_PROTOCOL, TEST_MAX_SEARCH_RESPONSE, TEST_TARGET_COUNT); // collect search request files (there were 2 ranges, so there are 2 search request) String[] files = targetDirectory.list(new PrefixFileFilter(Constants.SEARCH_REQUEST_FILENAME)); assertEquals(2, files.length); // there were no search response files because the exception was thrown each time files = targetDirectory.list(new PrefixFileFilter(Constants.SEARCH_RESPONSE_FILENAME)); assertEquals(0, files.length); log.info("Harvest was successful. Please check the folder " + TEST_DIRECTORY); }
From source file:org.h2gis.drivers.osm.OSMParser.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { String type = attributes.getValue("type"); if (progress.isCanceled()) { throw new SAXException("Canceled by user"); }/*from w w w.j a va 2 s. c om*/ if (localName.compareToIgnoreCase("node") == 0) { nodeOSMElement = new NodeOSMElement(Double.valueOf(attributes.getValue("lat")), Double.valueOf(attributes.getValue("lon"))); setCommonsAttributes(nodeOSMElement, attributes); tagLocation = TAG_LOCATION.NODE; } else if (localName.compareToIgnoreCase("way") == 0) { wayOSMElement = new WayOSMElement(); setCommonsAttributes(wayOSMElement, attributes); tagLocation = TAG_LOCATION.WAY; } else if (localName.compareToIgnoreCase("tag") == 0) { String key = attributes.getValue("k"); String value = attributes.getValue("v"); boolean insertTag = true; switch (tagLocation) { case NODE: insertTag = nodeOSMElement.addTag(key, value); break; case WAY: insertTag = wayOSMElement.addTag(key, value); break; case RELATION: insertTag = relationOSMElement.addTag(key, value); break; } try { if (insertTag && !insertedTagsKeys.contains(key)) { tagPreparedStmt.setObject(1, key); tagPreparedStmt.execute(); insertedTagsKeys.add(key); } } catch (SQLException ex) { if (ex.getErrorCode() != ErrorCode.DUPLICATE_KEY_1 && !TAG_DUPLICATE_EXCEPTION.equals(ex.getSQLState())) { throw new SAXException("Cannot insert the tag : {" + key + " , " + value + "}", ex); } } } else if (localName.compareToIgnoreCase("nd") == 0) { wayOSMElement.addRef(attributes.getValue("ref")); } else if (localName.compareToIgnoreCase("relation") == 0) { relationOSMElement = new OSMElement(); setCommonsAttributes(relationOSMElement, attributes); tagLocation = TAG_LOCATION.RELATION; } else if (localName.compareToIgnoreCase("member") == 0) { if (type.equalsIgnoreCase("node")) { try { nodeMemberPreparedStmt.setObject(1, relationOSMElement.getID()); nodeMemberPreparedStmt.setObject(2, Long.valueOf(attributes.getValue("ref"))); nodeMemberPreparedStmt.setObject(3, attributes.getValue("role")); nodeMemberPreparedStmt.setObject(4, idMemberOrder); nodeMemberPreparedStmt.addBatch(); nodeMemberPreparedStmtBatchSize++; } catch (SQLException ex) { throw new SAXException( "Cannot insert the node member for the relation : " + relationOSMElement.getID(), ex); } } else if (type.equalsIgnoreCase("way")) { try { wayMemberPreparedStmt.setObject(1, relationOSMElement.getID()); wayMemberPreparedStmt.setObject(2, Long.valueOf(attributes.getValue("ref"))); wayMemberPreparedStmt.setObject(3, attributes.getValue("role")); wayMemberPreparedStmt.setObject(4, idMemberOrder); wayMemberPreparedStmt.addBatch(); wayMemberPreparedStmtBatchSize++; } catch (SQLException ex) { throw new SAXException( "Cannot insert the way member for the relation : " + relationOSMElement.getID(), ex); } } else if (type.equalsIgnoreCase("relation")) { try { relationMemberPreparedStmt.setObject(1, relationOSMElement.getID()); relationMemberPreparedStmt.setObject(2, Long.valueOf(attributes.getValue("ref"))); relationMemberPreparedStmt.setObject(3, attributes.getValue("role")); relationMemberPreparedStmt.setObject(4, idMemberOrder); relationMemberPreparedStmt.addBatch(); relationMemberPreparedStmtBatchSize++; } catch (SQLException ex) { throw new SAXException( "Cannot insert the relation member for the relation : " + relationOSMElement.getID(), ex); } } } }
From source file:org.infoscoop.request.filter.rss.RssHandler.java
public void comment(char[] ch, int start, int length) throws SAXException { if (itemCount >= maxCount) return;//from w w w . j a v a 2 s . co m // if (contentsLevel > 1) { try { charBuf.write("<!--"); charBuf.write(ch, start, length); charBuf.write("-->"); } catch (IOException e) { throw new SAXException(e); } // } }
From source file:org.infoscoop.request.filter.rss.RssHandler.java
public void startCDATA() throws SAXException { if (itemCount >= maxCount) return;// w w w. java2s . c om // if (contentsLevel > 1) { if (isUnknownTag) { try { charBuf.write("<![CDATA["); } catch (IOException e) { throw new SAXException(e); } } // } }
From source file:org.infoscoop.request.filter.rss.RssHandler.java
public void endCDATA() throws SAXException { if (itemCount >= maxCount) return;/*from w w w .j a va 2 s . c o m*/ // if (contentsLevel > 1) { if (isUnknownTag) { try { charBuf.write("]]>"); } catch (IOException e) { throw new SAXException(e); } } // } }
From source file:org.infoscoop.request.filter.rss.RssHandler.java
void writeStartElement(String uri, String localName, String qName, Attributes attributes, Writer writer) throws SAXException { //System.out.println("writeStartElement"); try {/*from w w w . j a v a 2s . c om*/ writer.write("<" + localName); for (int i = 0; i < attributes.getLength(); i++) { String qname = attributes.getQName(i); String value = attributes.getValue(i); writer.write(" " + qname + "=\"" + XmlUtil.escapeXmlEntities(value) + "\""); } writer.write(">"); } catch (IOException e) { throw new SAXException(e); } }
From source file:org.infoscoop.request.filter.rss.RssHandler.java
void writeEndElement(String uri, String localName, String qName, Writer writer) throws SAXException { try {//w ww.jav a2s. co m writer.write("</" + localName + ">"); } catch (IOException e) { throw new SAXException(e); } }
From source file:org.intermine.api.bag.BagQueryHandler.java
/** * {@inheritDoc}/* www. j ava 2 s . c o m*/ */ @Override public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { if ("bag-type".equals(qName)) { type = attrs.getValue("type"); if (!model.hasClassDescriptor(pkg + "." + type)) { throw new SAXException("Type was not found in model: " + type); } queryList = new ArrayList<BagQuery>(); preDefaultQueryList = new ArrayList<BagQuery>(); if (bagQueries.containsKey(type)) { throw new SAXException("Duplicate query lists defined for type: " + type); } String matchOnFirstStr = attrs.getValue("matchOnFirst"); if (StringUtils.isNotEmpty(matchOnFirstStr)) { matchOnFirst = ("false".equalsIgnoreCase(matchOnFirstStr) ? false : true); } bagQueryConfig.setMatchOnFirst(matchOnFirst); } if ("query".equals(qName)) { message = attrs.getValue("message"); matchesAreIssues = Boolean.valueOf(attrs.getValue("matchesAreIssues")); runBeforeDefault = Boolean.valueOf(attrs.getValue("runBeforeDefault")); sb = new StringBuffer(); } if ("additional-converter".equals(qName)) { processAdditionalConverters(attrs); } }
From source file:org.intermine.api.xml.ProfileManagerBinding.java
/** * {@inheritDoc}//from w ww . ja v a2 s .c om */ @Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if ("userprofile".equals(qName)) { Profile profile; profile = profileHandler.getProfile(); profileManager.createProfileWithoutBags(profile); try { Map<String, Set<BagValue>> bagValues = profileHandler.getBagsValues(); for (StorableBag bag : profile.getAllBags().values()) { bag.saveWithBagValues(profile.getUserId(), bagValues.get(bag.getName())); } } catch (ObjectStoreException ose) { throw new SAXException(ose); } // Must come after the bags themselves have been stored. try { // Make sure the tables we need exist. SharedBagManager sbm = SharedBagManager.getInstance(profileManager); profileHandler.getInvitationHandler().storeInvites(profile); } catch (SQLException e) { LOG.error("Cannot store invitations", e); if (abortOnError) { throw new SAXException(e); } } Set<Tag> tags = profileHandler.getTags(); TagManager tagManager = new TagManagerFactory(profile.getProfileManager()).getTagManager(); for (Tag tag : tags) { try { tagManager.addTag(tag.getTagName(), tag.getObjectIdentifier(), tag.getType(), profile); } catch (TagManager.TagException e) { LOG.error("Cannot add tag: " + tag.toString(), e); if (abortOnError) { throw new SAXException(e); } } catch (RuntimeException e) { LOG.error("Error adding tag: " + tag.toString(), e); if (abortOnError) { throw new SAXException(e); } } } profile.getSearchRepository().receiveEvent(new MassTaggingEvent()); profileHandler = null; long totalTime = System.currentTimeMillis() - startTime; LOG.info("Finished profile: " + profile.getUsername() + " took " + totalTime + "ms."); } if ("userprofiles".equals(qName)) { if (!sharedBagsByUsers.isEmpty()) { SharedBagManager sharedBagManager = SharedBagManager.getInstance(profileManager); String bagName, dateCreated; for (String user : sharedBagsByUsers.keySet()) { List<Map<String, String>> sharedBags = sharedBagsByUsers.get(user); if (!sharedBags.isEmpty()) { for (Map<String, String> sharedBag : sharedBags) { bagName = sharedBag.get("name"); dateCreated = sharedBag.get("dateCreated"); sharedBagManager.shareBagWithUser(bagName, dateCreated, user); } } } } } if (profileHandler != null) { profileHandler.endElement(uri, localName, qName); } if (trackHandler != null) { trackHandler.endElement(uri, localName, qName); } }