List of usage examples for javax.xml.parsers ParserConfigurationException printStackTrace
public void printStackTrace()
From source file:org.sakaiproject.iclicker.logic.IClickerLogic.java
/** * Attempt to decode the XML into readable values in a map * * @param xml XML//from ww w . jav a 2 s . co m * @return the map of attributes from S student record * @throws IllegalArgumentException if the xml is invalid or blank * @throws RuntimeException if there is an internal failure in the XML parser */ public Map<String, String> decodeGetRegisteredForClickerMACResult(String xml) { /* <StudentEnrol> <S StudentId="testgoqait99" FirstName="testgoqait99" LastName="testgoqait99" MiddleName="" WebClickerId="C570BF0C2154"/> </StudentEnrol> */ if (xml == null || "".equals(xml)) { throw new IllegalArgumentException("xml must be set"); } // read the xml (try to anyway) DocumentBuilder db; try { db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new RuntimeException("XML parser failure: " + e, e); } Document doc; try { doc = db.parse(new ByteArrayInputStream(xml.getBytes())); } catch (SAXException e) { e.printStackTrace(); throw new RuntimeException("XML read failure: " + e, e); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("XML IO failure: " + e, e); } HashMap<String, String> m = new HashMap<String, String>(); try { doc.getDocumentElement().normalize(); NodeList users = doc.getElementsByTagName("S"); if (users.getLength() == 0) { throw new IllegalArgumentException("Invalid XML, no S element"); } Node userNode = users.item(0); if (userNode.getNodeType() == Node.ELEMENT_NODE) { Element user = (Element) userNode; NamedNodeMap attributes = user.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { String name = attributes.item(j).getNodeName(); String value = attributes.item(j).getNodeValue(); m.put(name, value); } } else { throw new IllegalArgumentException("Invalid user node in XML: " + userNode); } } catch (DOMException e) { e.printStackTrace(); throw new RuntimeException("XML DOM parsing failure: " + e, e); } return m; }
From source file:org.sakaiproject.iclicker.logic.IClickerLogic.java
/** * The xml format to upload students registration to the CMS Server remains the same as the national registration * web services and this upload should be treated as if the user is registering the remotes manually inside the * plug-in i.e all applicable messages should be returned <br/> * NOTE: we are ignoring the email and name inputs because we will get them from the user lookup of the id * /* ww w .j ava 2 s. c o m*/ * @param xml XML * @return the clicker registration object from the xml * @throws IllegalArgumentException if the xml is invalid or blank * @throws RuntimeException if there is an internal failure in the XML parser */ public ClickerRegistration decodeClickerRegistration(String xml) { /* <Register> <S DisplayName="DisplayName-azeckoski-123456" FirstName="First" LastName="Lastazeckoski-123456" StudentID="eid-azeckoski-123456" Email="azeckoski-123456@email.com" URL="http://sakaiproject.org"; ClickerID="11111111"></S> </Register> */ if (xml == null || "".equals(xml)) { throw new IllegalArgumentException("xml must be set"); } // read the xml (try to anyway) DocumentBuilder db; try { db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new RuntimeException("XML parser failure: " + e, e); } Document doc; try { doc = db.parse(new ByteArrayInputStream(xml.getBytes())); } catch (SAXException e) { e.printStackTrace(); throw new RuntimeException("XML read failure: " + e, e); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("XML IO failure: " + e, e); } ClickerRegistration cr; try { doc.getDocumentElement().normalize(); NodeList users = doc.getElementsByTagName("S"); if (users.getLength() == 0) { throw new IllegalArgumentException("Invalid XML, no S element"); } Node userNode = users.item(0); if (userNode.getNodeType() == Node.ELEMENT_NODE) { Element user = (Element) userNode; String clickerId = user.getAttribute("ClickerID"); if (clickerId == null || "".equals(clickerId)) { throw new IllegalArgumentException( "Invalid XML for registration, no id in the ClickerID element (Cannot process)"); } String userId = user.getAttribute("StudentID"); // this is the userId if (userId == null || "".equals(userId)) { throw new IllegalArgumentException( "Invalid XML for registration, no id in the StudentID element (Cannot process)"); } cr = new ClickerRegistration(clickerId, userId); cr.userDisplayName = user.getAttribute("DisplayName"); } else { throw new IllegalArgumentException("Invalid user node in XML: " + userNode); } } catch (DOMException e) { e.printStackTrace(); throw new RuntimeException("XML DOM parsing failure: " + e, e); } return cr; }
From source file:org.sakaiproject.iclicker.logic.IClickerLogic.java
public Gradebook decodeGradebookXML(String xml) { /*//from w w w .j a va 2 s .com <coursegradebook courseid="BFW61"> <user id="lm_student01" usertype="S"> <lineitem name="06/02/2009" pointspossible="50" type="iclicker polling scores" score="0"/> </user> <user id="lm_student02" usertype="S"> <lineitem name="06/02/2009" pointspossible="50" type="iclicker polling scores" score="0"/> </user> </coursegradebook> */ if (xml == null || "".equals(xml)) { throw new IllegalArgumentException("xml must be set"); } // read the xml (try to anyway) DocumentBuilder db; try { db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new RuntimeException("XML parser failure: " + e, e); } Document doc; try { doc = db.parse(new ByteArrayInputStream(xml.getBytes())); } catch (SAXException e) { e.printStackTrace(); throw new RuntimeException("XML read failure: " + e, e); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("XML IO failure: " + e, e); } Gradebook gb; try { doc.getDocumentElement().normalize(); // get the course id from the root attribute String courseId = doc.getDocumentElement().getAttribute("courseid"); if (courseId == null || "".equals(courseId)) { throw new IllegalArgumentException("Invalid XML, no courseid in the root xml element"); } NodeList users = doc.getElementsByTagName("user"); if (users.getLength() == 0) { throw new IllegalArgumentException("Invalid XML, no user elements element"); } gb = new Gradebook(courseId); gb.courseId = courseId; for (int i = 0; i < users.getLength(); i++) { Node userNode = users.item(i); if (userNode.getNodeType() == Node.ELEMENT_NODE) { Element user = (Element) userNode; String userType = user.getAttribute("usertype"); if (!"s".equalsIgnoreCase(userType)) { continue; // skip this one } // valid user to process String userId = user.getAttribute("id"); // this is the userId if (userId == null || "".equals(userId)) { log.warn("Invalid XML for user, no id in the user element (skipping this entry): " + user); continue; } NodeList lineitems = user.getElementsByTagName("lineitem"); for (int j = 0; j < lineitems.getLength(); j++) { Element lineitem = (Element) lineitems.item(j); String liName = lineitem.getAttribute("name"); if (liName == null || "".equals(liName)) { throw new IllegalArgumentException( "Invalid XML, no name in the lineitem xml element: " + lineitem); } String liType = lineitem.getAttribute("type"); Double liPointsPossible = 100.0; String liPPText = lineitem.getAttribute("pointspossible"); if (liPPText != null && !"".equals(liPPText)) { try { liPointsPossible = Double.valueOf(liPPText); } catch (NumberFormatException e) { log.warn("Invalid points possible (" + liPPText + "), using default of " + liPointsPossible + ": " + lineitem + ": " + e); } } String liScore = lineitem.getAttribute("score"); if (liScore == null || "".equals(liScore)) { log.warn("Invalid score (" + liScore + "), skipping this entry: " + lineitem); continue; } GradebookItem gbi = new GradebookItem(gb.id, liName); if (!gb.items.contains(gbi)) { gbi.pointsPossible = liPointsPossible; gbi.type = liType; gb.items.add(gbi); } else { int pos = gb.items.lastIndexOf(gbi); if (pos >= 0) { gbi = gb.items.get(pos); } } // add in the score GradebookItemScore gbis = new GradebookItemScore(gbi.name, userId, liScore); gbi.scores.add(gbis); } } else { throw new IllegalArgumentException("Invalid user node in XML: " + userNode); } } } catch (DOMException e) { e.printStackTrace(); throw new RuntimeException("XML DOM parsing failure: " + e, e); } return gb; }
From source file:com.connectsdk.service.NetcastTVService.java
private JSONObject parseVolumeXmlToJSON(String data) { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); try {//from w ww. j av a 2 s .c o m InputStream stream = new ByteArrayInputStream(data.getBytes("UTF-8")); SAXParser saxParser = saxParserFactory.newSAXParser(); NetcastVolumeParser handler = new NetcastVolumeParser(); saxParser.parse(stream, handler); return handler.getVolumeStatus(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.connectsdk.service.NetcastTVService.java
private int parseAppNumberXmlToJSON(String data) { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); try {//ww w . j a va 2s . c o m InputStream stream = new ByteArrayInputStream(data.getBytes("UTF-8")); SAXParser saxParser = saxParserFactory.newSAXParser(); NetcastAppNumberParser handler = new NetcastAppNumberParser(); saxParser.parse(stream, handler); return handler.getApplicationNumber(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return 0; }
From source file:com.connectsdk.service.NetcastTVService.java
private JSONArray parseApplicationsXmlToJSON(String data) { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); try {//from w w w . ja v a 2s. co m InputStream stream = new ByteArrayInputStream(data.getBytes("UTF-8")); SAXParser saxParser = saxParserFactory.newSAXParser(); NetcastApplicationsParser handler = new NetcastApplicationsParser(); saxParser.parse(stream, handler); return handler.getApplications(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.connectsdk.service.NetcastTVService.java
@Override public void getCurrentChannel(final ChannelListener listener) { String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CURRENT_CHANNEL); ResponseListener<Object> responseListener = new ResponseListener<Object>() { @Override/*from w w w . j a v a 2 s. c om*/ public void onSuccess(Object response) { String strObj = (String) response; try { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); InputStream stream = new ByteArrayInputStream(strObj.getBytes("UTF-8")); SAXParser saxParser = saxParserFactory.newSAXParser(); NetcastChannelParser parser = new NetcastChannelParser(); saxParser.parse(stream, parser); JSONArray channelArray = parser.getJSONChannelArray(); if (channelArray.length() > 0) { JSONObject rawData = (JSONObject) channelArray.get(0); ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData); Util.postSuccess(listener, channel); } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(ServiceCommandError error) { Util.postError(listener, error); } }; ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener); request.send(); }
From source file:MyZone.Settings.java
public boolean deleteFriend(String username) { refresh(BASIC_INFO);/*from www . ja v a 2s . c om*/ refresh(ZONES); refresh(FRIENDS); try { zone z = new zone(); for (int i = 0; i < zones.size(); i++) { z = new zone(zones.get(i)); z.removeMember(username); zones.add(i, z); zones.remove(i + 1); } save(ZONES); profile userProfile = new profile(this.username, this.username, prefix); userProfile.fileList.clear(); userProfile.parseDocument(prefix + this.username + "/correctImage.xml", "fileListEntry"); for (int i = userProfile.fileList.size() - 1; i >= 0; i--) { fileListEntry fle = new fileListEntry(userProfile.fileList.get(i)); if (fle.getOwner().equals(username)) { userProfile.fileList.remove(i); } } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); } catch (javax.xml.parsers.ParserConfigurationException e) { if (DEBUG) { e.printStackTrace(); } return false; } Document fileListDOM = db.newDocument(); Element rootEle = fileListDOM.createElement("correctImage"); fileListDOM.appendChild(rootEle); for (int i = 0; i < userProfile.fileList.size(); i++) { fileListEntry f = new fileListEntry(userProfile.fileList.get(i)); rootEle.appendChild(f.createDOMElement(fileListDOM)); } while (!userProfile.saveXML(prefix + this.username + "/correctImage.xml", fileListDOM)) { try { Thread.sleep(100); } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } } } userProfile.fileList.clear(); userProfile.parseDocument(prefix + this.username + "/existingImage.xml", "fileListEntry"); for (int i = userProfile.fileList.size() - 1; i >= 0; i--) { fileListEntry fle = new fileListEntry(userProfile.fileList.get(i)); if (fle.getOwner().equals(username)) { userProfile.fileList.remove(i); } } dbf = DocumentBuilderFactory.newInstance(); try { db = dbf.newDocumentBuilder(); } catch (javax.xml.parsers.ParserConfigurationException e) { if (DEBUG) { e.printStackTrace(); } return false; } fileListDOM = db.newDocument(); rootEle = fileListDOM.createElement("existingImage"); fileListDOM.appendChild(rootEle); for (int i = 0; i < userProfile.fileList.size(); i++) { fileListEntry f = new fileListEntry(userProfile.fileList.get(i)); rootEle.appendChild(f.createDOMElement(fileListDOM)); } while (!userProfile.saveXML(prefix + this.username + "/existingImage.xml", fileListDOM)) { try { Thread.sleep(100); } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } } } for (int i = 0; i < friends.size(); i++) { friend f = new friend(friends.get(i)); user u = new user(f.getUser()); if (u.getUsername().equals(username)) { friends.remove(i); deleteOriginal(username); deleteMirror(username); File dir = new File(prefix + this.username + "/friends/" + username); deleteDir(dir); break; } } save(FRIENDS); for (int i = 0; i < passphrases.size(); i++) { passphraseEntry p = new passphraseEntry(passphrases.get(i)); if (p.getUsername().equals(username)) { passphrases.remove(i); break; } } save(PASSPHRASES); return true; } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } } return false; }
From source file:edu.stanford.epad.epadws.queries.DefaultEpadOperations.java
@Override public EPADSeriesList getSeriesDescriptions(StudyReference studyReference, String username, String sessionID, EPADSearchFilter searchFilter, boolean filterDSOs, boolean includeAnnotationStatus) { EPADSeriesList epadSeriesList = new EPADSeriesList(); DCM4CHEESeriesList dcm4CheeSeriesList = Dcm4CheeQueries.getSeriesInStudy(studyReference.studyUID); for (DCM4CHEESeries dcm4CheeSeries : dcm4CheeSeriesList.ResultSet.Result) { EPADSeries epadSeries = dcm4cheeSeries2EpadSeries(sessionID, studyReference.projectID, studyReference.subjectID, dcm4CheeSeries, username, includeAnnotationStatus); boolean filter = searchFilter.shouldFilterSeries(epadSeries.patientID, epadSeries.patientName, epadSeries.examType, epadSeries.numberOfAnnotations); // log.info("Series:" + epadSeries.seriesDescription + " filterDSO:" + filterDSOs + " isDSO:"+ epadSeries.isDSO + " annotation:"+ epadSeries.annotationStatus.toString()); if (!filter && !(filterDSOs && epadSeries.isDSO)) { if (epadSeries.isDSO) { //bad solution!! //ml filter dsos with no permission log.info("filter"); List<EPADAIM> aims = null; if (studyReference.projectID != null && !studyReference.projectID.equals("")) aims = this.epadDatabaseOperations.getAIMsByDSOSeries(studyReference.projectID, epadSeries.seriesUID); else { aims = this.epadDatabaseOperations.getAIMsByDSOSeries(epadSeries.seriesUID); log.info(//from w w w . j a v a 2 s . c o m "No project id. Returning all series for this project. may download dso series that are in other projects"); } try { EPADAIMList aimList = AIMUtil.filterPermittedImageAnnotations(new EPADAIMList(aims), username, sessionID, studyReference.projectID); if (aimList != null && aimList.ResultSet.totalRecords != 0) { log.info("putting dso series:" + epadSeries.seriesUID); epadSeriesList.addEPADSeries(epadSeries); } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AimException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //log.info("Series:" + epadSeries.seriesDescription + " createdtime:" + epadSeries.createdTime); else epadSeriesList.addEPADSeries(epadSeries); } else if (epadSeries.isDSO) { // Check if AIM exists List<EPADAIM> aims = this.epadDatabaseOperations.getAIMsByDSOSeries(epadSeries.seriesUID); if (aims == null || aims.size() == 0) { log.info("No aim found for DSO:" + epadSeries.seriesUID); Set<DICOMFileDescription> dicomFileDescriptions = dcm4CheeDatabaseOperations .getDICOMFilesForSeries(epadSeries.seriesUID); if (dicomFileDescriptions.size() > 0) { File dsoDICOMFile = null; DICOMFileDescription lastDSO = dicomFileDescriptions.iterator().next(); String createdTime = lastDSO.createdTime; for (DICOMFileDescription dicomFileDescription : dicomFileDescriptions) { if (createdTime.compareTo(dicomFileDescription.createdTime) < 0) { createdTime = dicomFileDescription.createdTime; lastDSO = dicomFileDescription; } } String dicomFilePath = EPADConfig.dcm4cheeDirRoot + "/" + lastDSO.filePath; dsoDICOMFile = new File(dicomFilePath); try { List<ImageAnnotation> ias = AIMQueries.getAIMImageAnnotations(AIMSearchType.SERIES_UID, epadSeries.seriesUID, username, 1, 50); if (ias == null || ias.size() == 0) { AIMUtil.generateAIMFileForDSO(dsoDICOMFile, "shared", studyReference.projectID); } // else // { // log.info("Adding entries to annotations table"); // Aim aim = new Aim(ias.get(0)); // ImageReference reference = new ImageReference(epadSeries.projectID, epadSeries.patientID, epadSeries.studyUID, aim.getFirstSeriesID(), aim.getFirstImageID()); // this.epadDatabaseOperations.addDSOAIM(username, reference, epadSeries.seriesUID, ias.get(0).getUniqueIdentifier()); // } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } try { List<NonDicomSeries> ndSerieses = projectOperations.getNonDicomSeriesForStudy(studyReference.studyUID); for (NonDicomSeries ndSeries : ndSerieses) { EPADSeries series = new EPADSeries(studyReference.projectID, studyReference.subjectID, "", studyReference.studyUID, ndSeries.getSeriesUID(), dateformat.format(ndSeries.getSeriesDate()), ndSeries.getDescription(), "", "", "", 0, 0, 0, "", "", "", null, "", "", "SEG".equalsIgnoreCase(ndSeries.getModality())); series.isNonDicomSeries = true; epadSeriesList.addEPADSeries(series); } } catch (Exception e) { log.warning("Error getting non-dicom series", e); } return epadSeriesList; }