List of usage examples for org.xml.sax SAXException printStackTrace
public void printStackTrace()
From source file:org.vfny.geoserver.config.web.tiles.definition.MultipleDefinitionsFactory.java
/** * Parse specified xml file and add definition to specified definitions set. * This method is used to load several description files in one instances list. * If filename exists and definition set is <code>null</code>, create a new set. Otherwise, return * passed definition set (can be <code>null</code>). * @param servletContext Current servlet context. Used to open file. * @param filename Name of file to parse. * @param xmlDefinitions Definitions set to which definitions will be added. If null, a definitions * set is created on request./*from w w w . j av a 2s . c o m*/ * @return XmlDefinitionsSet The definitions set created or passed as parameter. * @throws DefinitionsFactoryException On errors parsing file. */ private XmlDefinitionsSet parseXmlFile(ServletContext servletContext, String filename, XmlDefinitionsSet xmlDefinitions) throws DefinitionsFactoryException { try { /*InputStream input = servletContext.getResourceAsStream(filename);*/ InputStream input = null; Resource[] resources = WebApplicationContextUtils.getWebApplicationContext(servletContext) .getResources(filename); final int length = resources.length; for (int i = 0; i < length; i++) { try { input = resources[i].getURL().openStream(); /*getServletContext().getResource(path)*/ } catch (IOException e) { //error loading from this resource. Probably it doesn't exist. if (log.isDebugEnabled()) { log.debug("", e); } return xmlDefinitions; } // Try to load using real path. // This allow to load config file under websphere 3.5.x // Patch proposed Houston, Stephen (LIT) on 5 Apr 2002 if (null == input) { try { input = new java.io.FileInputStream(servletContext.getRealPath(filename)); } catch (Exception e) { } } // If still nothing found, this mean no config file is associated if (input == null) { if (log.isDebugEnabled()) { log.debug("Can't open file '" + filename + "'"); } return xmlDefinitions; } // Check if parser already exist. // Doesn't seem to work yet. //if( xmlParser == null ) if (true) { xmlParser = new XmlParser(); xmlParser.setValidating(isValidatingParser); } // Check if definition set already exist. if (xmlDefinitions == null) { xmlDefinitions = new XmlDefinitionsSet(); } xmlParser.parse(input, xmlDefinitions); } } catch (SAXException ex) { if (log.isDebugEnabled()) { log.debug("Error while parsing file '" + filename + "'."); ex.printStackTrace(); } throw new DefinitionsFactoryException("Error while parsing file '" + filename + "'. " + ex.getMessage(), ex); } catch (IOException ex) { /*throw new DefinitionsFactoryException*/ if (log.isDebugEnabled()) { log.debug("IO Error while parsing file '" + filename + "'. " + ex.getMessage(), ex); } } return xmlDefinitions; }
From source file:org.vivoweb.harvester.fetch.WOSFetch.java
/** * @param previousQuery a WOS soap query xml message * @return the string with the altered first node in the * @throws IOException thrown if there is an issue parsing the previousQuery string *//* w ww . ja v a 2 s .c o m*/ private String getnextQuery(String previousQuery) throws IOException { String nextQuery = ""; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // never forget this! Document searchDoc = factory.newDocumentBuilder() .parse(new ByteArrayInputStream(previousQuery.getBytes())); //log.debug("searchDoc:"); //log.debug(documentToString(searchDoc)); NodeList firstrecordNodes = searchDoc.getElementsByTagName("firstRecord"); Node firstnode = firstrecordNodes.item(0); int firstrecord = Integer.parseInt(firstnode.getTextContent()); log.debug("firstrecord = " + firstrecord); NodeList countNodes = searchDoc.getElementsByTagName("count"); int count = Integer.parseInt(countNodes.item(0).getTextContent()); log.debug("count= " + count); int newFirst = firstrecord + count; firstnode.setTextContent(Integer.toString(newFirst)); log.debug("new First Record= " + newFirst); // } nextQuery = nodeToString(searchDoc); //log.debug("newsearchDoc:\n"+nextQuery); } catch (SAXException e) { e.printStackTrace(); throw new IOException(e); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new IOException(e); } return nextQuery; }
From source file:org.vivoweb.harvester.fetch.WOSFetch.java
/** * @param responseXML String containing the results from the WOS soap query * @return the number of records found in the string *///ww w. j a va 2s . co m private Map<String, String> extractSearchRecords(String responseXML) { HashMap<String, String> recordMap = new HashMap<String, String>(); int numRecords = 0; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // never forget this! Document responseDoc = factory.newDocumentBuilder() .parse(new ByteArrayInputStream(responseXML.getBytes())); NodeList recordList = responseDoc.getElementsByTagName("records"); for (int index = 0; index < recordList.getLength(); index++) { Element currentRecord = (Element) recordList.item(index); String identifier = currentRecord.getElementsByTagName("UT").item(0).getTextContent(); String id = "id_-_" + identifier; compileLamrList(identifier); Element recordRoot = responseDoc.createElement("Description"); recordRoot.setAttribute("ID", identifier); recordRoot.appendChild(currentRecord); String data = nodeToString(recordRoot); recordMap.put(id, data); writeRecord(id, data); numRecords++; } } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } log.debug("Extracted " + numRecords + " records from search"); return recordMap; }
From source file:org.vivoweb.harvester.fetch.WOSFetch.java
/** * /*w w w. j a v a 2s .c o m*/ */ private void executeLamrQuery() { if (this.lamrSet.isEmpty()) { log.debug("No LAMR query sent, empty LAMR set."); return; } //compile lamrquery with lamrSet DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // never forget this! Document lamrDoc = null; try { lamrDoc = factory.newDocumentBuilder().parse(new ByteArrayInputStream(this.lamrMessage.getBytes())); // log.debug("LAMR Message :\n"+nodeToString(lamrDoc)); NodeList mapElements = lamrDoc.getElementsByTagName("map"); Element lookUp = null; for (int index = 0; index < mapElements.getLength(); index++) { Element currentmap = (Element) mapElements.item(index); // log.debug("Element :\n" + nodeToString(currentmap)); // log.debug("Element name = \"" + currentmap.getAttribute("id")+ "\""); if (currentmap.getAttribute("id").contentEquals("lookup")) { log.debug("Found element lookup"); // lookUp = (Element)currentmap.getParentNode(); lookUp = currentmap; break; } } if (lookUp == null) { log.error("No \"lookup\" node in LAMR query message"); } // log.debug("prelookUp = " + nodeToString(lookUp)); for (String currentUT : this.lamrSet) { Element val = lamrDoc.createElement("val"); val.setAttribute("name", "ut"); val.setTextContent(currentUT); Element docMap = lamrDoc.createElement("map"); docMap.setAttribute("name", "doc-" + currentUT); docMap.appendChild(val); lookUp.appendChild(docMap); } // log.debug("LAMR Message :\n"+nodeToString(lamrDoc)); //send lamrquery Document lamrRespDoc = null; ByteArrayOutputStream lamrResponse = new ByteArrayOutputStream(); { SOAPMessenger soapfetch = new SOAPMessenger(this.lamrUrl, lamrResponse, new ByteArrayInputStream(nodeToString(lamrDoc).getBytes()), "", null); soapfetch.execute(); } lamrRespDoc = factory.newDocumentBuilder().parse(new ByteArrayInputStream(lamrResponse.toByteArray())); // log.debug("LAMR Response :\n"+nodeToString(lamrRespDoc)); // extract records - A little hacky - message specifics sensitive // To ensure no erroneous name spaces rebuilding structure from existing data. log.debug("Extracting LAMR Records"); // records are in map elements. NodeList respMapList = lamrRespDoc.getElementsByTagName("map"); int recordsFound = 0; // cycle through existing map elements; for (int index = 0; index < respMapList.getLength(); index++) { Element currentNode = (Element) respMapList.item(index); // what we are looking for is found in maps named "WOS" if (currentNode.getAttribute("name").contentEquals("WOS")) { // for output similarity have the root node be Description Element recordRoot = lamrRespDoc.createElement("Description"); String ut = ""; // each WOS node has the result formatted as named val nodes. NodeList valList = currentNode.getElementsByTagName("val"); for (int index2 = 0; index2 < valList.getLength(); index2++) { Element currentVal = (Element) valList.item(index2); // Getting Record ID if (currentVal.getAttribute("name").contentEquals("ut")) { ut = currentVal.getTextContent(); break; } } if (ut != "") { recordsFound++; recordRoot.setAttribute("ID", ut); NodeList currentchildren = currentNode.getElementsByTagName("val"); Element currentDup = lamrRespDoc.createElement("map"); currentDup.setAttribute("name", "WOS"); for (int index2 = 0; index2 < currentchildren.getLength(); index2++) { Element cur = (Element) currentchildren.item(index2); Element childNode = lamrRespDoc.createElement(cur.getTagName()); childNode.setAttribute("name", cur.getAttribute("name")); childNode.setTextContent(cur.getTextContent()); currentDup.appendChild(childNode); } recordRoot.appendChild(currentDup); writeRecord("id_-_LAMR_-_" + ut, nodeToString(recordRoot)); } } } log.debug("Found " + recordsFound + " LAMR Records"); //write records } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } this.lamrSet.clear(); }
From source file:org.webtestingexplorer.state.CustomizedPropertiesElementsState.java
private Map<WebElementIdentifier, Map<String, String>> parseXML(String xmlString) { Map<WebElementIdentifier, Map<String, String>> elementProperties = new HashMap<WebElementIdentifier, Map<String, String>>(); XpathWebElementIdentifier identifier; Map<String, String> attributeMap; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document doc = null;/*ww w .j a va 2 s . com*/ try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlString)); doc = db.parse(is); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } if (doc == null) { return elementProperties; } NodeList nl = doc.getElementsByTagName("element"); if (nl != null && nl.getLength() > 0) { // Loop through all elements for (int i = 0; i < nl.getLength(); ++i) { identifier = null; attributeMap = null; Element el = (Element) nl.item(i); // Get xpath NodeList xpaths = el.getElementsByTagName("xpath"); Element xpathElement = (Element) xpaths.item(0); String xpath = getCharacterDataFromElement(xpathElement); identifier = new XpathWebElementIdentifier(xpath); NodeList attributes = el.getElementsByTagName("attribute"); if (attributes != null && attributes.getLength() > 0) { // Loop through all attributes attributeMap = new HashMap<String, String>(); for (int j = 0; j < attributes.getLength(); ++j) { Element attributeElement = (Element) attributes.item(j); NamedNodeMap attributeNodeMap = attributeElement.getAttributes(); for (int m = 0; m < attributeNodeMap.getLength(); ++m) { Node attributeNode = attributeNodeMap.item(m); attributeMap.put(attributeNode.getNodeName(), attributeNode.getNodeValue()); } } // for } if (identifier != null && attributeMap != null) { elementProperties.put(identifier, attributeMap); } } // for } return elementProperties; }
From source file:org.yawlfoundation.yawl.digitalSignature.DigitalSignature.java
public static org.w3c.dom.Document ConvertStringToDocument(String Doc) { org.w3c.dom.Document document = null; try {//from w ww. j a v a2 s . c o m DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance(); DocumentBuilder DocBuild = Factory.newDocumentBuilder(); StringBuffer Buffer = new StringBuffer(Doc); ByteArrayInputStream DocArray = new ByteArrayInputStream(Buffer.toString().getBytes("UTF-8")); document = DocBuild.parse(DocArray); } catch (ParserConfigurationException pce) { pce.printStackTrace(); System.exit(0); } catch (org.xml.sax.SAXException se) { se.printStackTrace(); System.exit(0); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } return document; }
From source file:roommateapp.info.droid.ActivityBuilding.java
/** * first init of the data/*from ww w . j a va2 s.com*/ */ private void initActivityBuilding(boolean firstInit) { // Init time picker this.timePickerFragment = new TimePickerFragment(this); // Get submitted data for this activity this.selectedBuilding = getIntent().getParcelableExtra("selectedBuilding"); this.checkedOnceForClientUpdate = getIntent().getBooleanExtra("checkedOnceForClientUpdate", true); // If this is the first instance go for parsing the file data if (firstInit == true || (this.selectedBuilding.getLectureTimes() == null)) { if (RoommateConfig.VERBOSE) { System.out.println("Debug: first init"); } try { this.parser = new XercesParser(); this.parser.setRoommateFilePath(this.selectedBuilding.getFile().toString()); this.parser.setBuildingFile(this.selectedBuilding); this.parser.parseRoommateFile(); } catch (SAXException e) { e.printStackTrace(); if (RoommateConfig.VERBOSE) { System.out.println("PARSER FAIL, SAXException"); } Intent intent = new Intent(this, ActivityMain.class); intent.putExtra("openStd", false); startActivity(intent); } catch (IOException e) { e.printStackTrace(); if (RoommateConfig.VERBOSE) { System.out.println("PARSER FAIL, IOException"); } Intent intent = new Intent(this, ActivityMain.class); intent.putExtra("openStd", false); startActivity(intent); } } // Does the file contains rooms? if (this.selectedBuilding.getRoomListKeySet().isEmpty()) { Toast.makeText(getApplicationContext(), getString(R.string.error_norooms), Toast.LENGTH_LONG).show(); if (RoommateConfig.VERBOSE) { System.out.println("WARNING: No rooms where found in this building."); } finish(); } else { // Get the holidaylist // if (Preferences.isFilterHolidaysOn(getApplicationContext())) { // // parseHolidayfile(); // } // Set the headline TextView headlineActivity = (TextView) findViewById(R.id.TextViewBuildingHeadline); headlineActivity.setText(this.selectedBuilding.getBuildingname()); headlineActivity.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); // Set the swipe pages // pages.get(0 for free_rooms; 1 for allrooms).findViewById(id) LayoutInflater inflater = LayoutInflater.from(this); pages = new ArrayList<View>(); // Page free_rooms View page = inflater.inflate(R.layout.view_free_rooms, null); pages.add(page); // Page all_rooms page = inflater.inflate(R.layout.view_all_rooms, null); pages.add(page); // Set pages BuildingPageAdapter pagerAdapter = new BuildingPageAdapter(pages, this); ViewPager viewPager = new ViewPager(this); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(0); ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager); mViewPager.setAdapter(pagerAdapter); // Displaying filter status if (Preferences.isFilterActive(getApplicationContext())) { filterActive = Preferences.getFilters(getApplicationContext()); } createListViewAll(); // Set the current day and time setTimebar(DateHelper.getCurrentHour(), DateHelper.getCurrentMinute(), DateHelper.translateWeekday(DateHelper.getCurrentDay(this), this)); this.hours = getHours(); this.weekdays = this.selectedBuilding.getWeekdaysStrings(); this.weekdays = DateHelper.translateWeekdays(this.weekdays, this); // Check for client updates if the file was open via "open by default" operation if (Preferences.getDefaultFile(getApplicationContext()) != null && Preferences.getDefaultFile(getApplicationContext()) .equals(this.selectedBuilding.getFile().toString()) && Preferences.isClientUpdateEnabled(getApplicationContext()) && !this.checkedOnceForClientUpdate) { ClientUpdateChecker updateChecker = new ClientUpdateChecker(this, false); updateChecker.execute(getString(R.string.aboutVersion)); } } }
From source file:tud.metaviz.help.methods.HelpMethods.java
@SuppressWarnings("unchecked") //TODO: check if used! public Object[] processRequest(HttpServletRequest request) { Object[] idDocument = new Object[2]; if (request != null) { if (ServletFileUpload.isMultipartContent(request)) { ServletFileUpload sfu = new ServletFileUpload(new DiskFileItemFactory()); List<FileItem> fil; try { fil = sfu.parseRequest(request); Iterator<FileItem> it = fil.iterator(); while (it.hasNext()) { FileItem fi = (FileItem) it.next(); if (fi.getContentType() != null && fi.getContentType().equals("text/xml") && !fi.getName().equals("")) { //hold intern as document InputStream stream = fi.getInputStream(); DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setNamespaceAware(true); idDocument[1] = fac.newDocumentBuilder().parse(stream); } else if (fi.isFormField() && fi.getFieldName().contains("dataset_id")) idDocument[0] = fi.getString(); }// w w w .j a va2 s. c o m } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (FileUploadException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } return idDocument; }
From source file:us.mn.state.health.lims.reports.action.AuditTrailReportBySampleProcessAction.java
private void parseXmlFile(String xml) { //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {//from www . j av a2 s . co m //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file Document dom = db.parse(xml); System.out.println("This is parsed xml getting changes " + dom.getElementById("accessionNumber")); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:wsattacker.plugin.dos.dosExtension.util.SoapTestRequest.java
public SoapTestRequest() { // new Wsdl Project WsdlProject project = null;//w w w.j av a2 s. com try { project = new WsdlProject(); } catch (XmlException ex) { Logger.getLogger(SoapTestRequest.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(SoapTestRequest.class.getName()).log(Level.SEVERE, null, ex); } catch (SoapUIException ex) { Logger.getLogger(SoapTestRequest.class.getName()).log(Level.SEVERE, null, ex); } // Create a copy of WSDL file on tmp folder of local filesystem pathToLocalWsdl = createLocalWsdl(); // new Interface from local WSDL WsdlInterface iface = null; try { iface = WsdlInterfaceFactory.importWsdl(project, pathToLocalWsdl, true)[0]; } catch (SoapUIException ex) { Logger.getLogger(SoapTestRequest.class.getName()).log(Level.SEVERE, null, ex); } // get Operation and create Requests for Operations... WsdlOperation operation = iface.getOperationAt(0); requestWsdlRequest = operation.addNewRequest("MyTestRequest"); requestWsdlRequest.setRequestContent(operation.createRequest(true)); requestString = requestWsdlRequest.getRequestContent(); try { requestDoc = SoapUtilities.stringToDom(requestString); } catch (SAXException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }