List of usage examples for javax.xml.parsers ParserConfigurationException printStackTrace
public void printStackTrace()
From source file:zumzum.app.zunzuneando.visor.weather.YahooWeather.java
private Document convertStringToDocument(Context context, String src) { Document dest = null;/*w ww . ja v a 2s.co m*/ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser; try { parser = dbFactory.newDocumentBuilder(); dest = parser.parse(new ByteArrayInputStream(src.getBytes())); } catch (ParserConfigurationException e1) { e1.printStackTrace(); //Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show(); } catch (SAXException e) { e.printStackTrace(); //Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); //Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } return dest; }
From source file:cn.itcast.fredck.FCKeditor.connector.ConnectorServlet.java
/** * Manage the Get requests (GetFolders, GetFoldersAndFiles, CreateFolder).<br> * * The servlet accepts commands sent in the following format:<br> * connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath<br><br> * It execute the command and then return the results to the client in XML format. * *//*from ww w. j a v a2s .c om*/ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (debug) System.out.println("--- BEGIN DOGET ---"); response.setContentType("text/xml; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); String currentPath = baseDir + typeStr + currentFolderStr; String currentDirPath = getServletContext().getRealPath(currentPath); File currentDir = new File(currentDirPath); if (!currentDir.exists()) { currentDir.mkdir(); } Document document = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } Node root = CreateCommonXml(document, commandStr, typeStr, currentFolderStr, request.getContextPath() + currentPath); if (debug) System.out.println("Command = " + commandStr); if (commandStr.equals("GetFolders")) { getFolders(currentDir, root, document); } else if (commandStr.equals("GetFoldersAndFiles")) { getFolders(currentDir, root, document); getFiles(currentDir, root, document); } else if (commandStr.equals("CreateFolder")) { String newFolderStr = request.getParameter("NewFolderName"); File newFolder = new File(currentDir, newFolderStr); String retValue = "110"; if (newFolder.exists()) { retValue = "101"; } else { try { boolean dirCreated = newFolder.mkdir(); if (dirCreated) retValue = "0"; else retValue = "102"; } catch (SecurityException sex) { retValue = "103"; } } setCreateFolderResponse(retValue, root, document); } document.getDocumentElement().normalize(); try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); if (debug) { StreamResult dbgResult = new StreamResult(System.out); transformer.transform(source, dbgResult); System.out.println(""); System.out.println("--- END DOGET ---"); } } catch (Exception ex) { ex.printStackTrace(); } out.flush(); out.close(); }
From source file:com.hydroLibCreator.action.Creator.java
private void buildDrumKitXML() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try {/*ww w .ja va2 s . co m*/ DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException parserException) { parserException.printStackTrace(); } Element drumkit_info = document.createElement("drumkit_info"); document.appendChild(drumkit_info); Attr xmlns = document.createAttribute("xmlns"); xmlns.setValue("http://www.hydrogen-music.org/drumkit"); Attr xmlns_xsi = document.createAttribute("xmlns:xsi"); xmlns_xsi.setValue("http://www.w3.org/2001/XMLSchema-instance"); drumkit_info.setAttributeNode(xmlns); drumkit_info.setAttributeNode(xmlns_xsi); Node nameNode = createNameNode(document); drumkit_info.appendChild(nameNode); Node authorNode = createAuthorNode(document); drumkit_info.appendChild(authorNode); Node infoNode = createInfoNode(document); drumkit_info.appendChild(infoNode); Node licenseNode = createLicenseNode(document); drumkit_info.appendChild(licenseNode); Node instrumentListNode = createInstrumentListNode(document); drumkit_info.appendChild(instrumentListNode); // write the XML document to disk try { // create DOMSource for source XML document Source xmlSource = new DOMSource(document); // create StreamResult for transformation result Result result = new StreamResult(new FileOutputStream(destinationPath + "/drumkit.xml")); // create TransformerFactory TransformerFactory transformerFactory = TransformerFactory.newInstance(); // create Transformer for transformation Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); // transform and deliver content to client transformer.transform(xmlSource, result); } // handle exception creating TransformerFactory catch (TransformerFactoryConfigurationError factoryError) { System.err.println("Error creating " + "TransformerFactory"); factoryError.printStackTrace(); } catch (TransformerException transformerError) { System.err.println("Error transforming document"); transformerError.printStackTrace(); } catch (IOException ioException) { ioException.printStackTrace(); } }
From source file:com.fredck.FCKeditor.connector.ConnectorServlet.java
/** * Manage the Get requests (GetFolders, GetFoldersAndFiles, CreateFolder).<br> * /*ww w . ja v a 2 s . c o m*/ * The servlet accepts commands sent in the following format:<br> * connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath<br> * <br> * It execute the command and then return the results to the client in XML * format. * */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("ConnectorServlet.doGet"); if (debug) System.out.println("--- BEGIN DOGET ---"); response.setContentType("text/xml; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); String currentPath = baseDir + typeStr + currentFolderStr; String currentDirPath = getServletContext().getRealPath(currentPath); File currentDir = new File(currentDirPath); if (!currentDir.exists()) { currentDir.mkdir(); } Document document = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } Node root = CreateCommonXml(document, commandStr, typeStr, currentFolderStr, request.getContextPath() + currentPath); if (debug) System.out.println("Command = " + commandStr); if (commandStr.equals("GetFolders")) { getFolders(currentDir, root, document); } else if (commandStr.equals("GetFoldersAndFiles")) { getFolders(currentDir, root, document); getFiles(currentDir, root, document); } else if (commandStr.equals("CreateFolder")) { String newFolderStr = request.getParameter("NewFolderName"); File newFolder = new File(currentDir, newFolderStr); String retValue = "110"; if (newFolder.exists()) { retValue = "101"; } else { try { boolean dirCreated = newFolder.mkdir(); if (dirCreated) retValue = "0"; else retValue = "102"; } catch (SecurityException sex) { retValue = "103"; } } setCreateFolderResponse(retValue, root, document); } document.getDocumentElement().normalize(); try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); if (debug) { StreamResult dbgResult = new StreamResult(System.out); transformer.transform(source, dbgResult); System.out.println(""); System.out.println("--- END DOGET ---"); } } catch (Exception ex) { ex.printStackTrace(); } out.flush(); out.close(); }
From source file:abfab3d.io.input.STSReader.java
/** * Parse the manifest file//w w w .ja v a 2s . c o m * @param src The manifest file * @return */ private STSManifest parseManifest(InputStream src) throws IOException { String field = null; String val = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(src); NodeList model_list = doc.getElementsByTagName("model"); if (model_list == null) { throw new IllegalArgumentException("File contains no model element"); } Element model = (Element) model_list.item(0); if (model == null) { throw new IllegalArgumentException("File contains no model element"); } field = "units"; val = model.getAttribute(field); String units = val; if (units != null && units.length() != 0) { mf.setUnits(Double.parseDouble(units)); } STSManifest ret_val = new STSManifest(); int len; field = "parts"; NodeList part_list = doc.getElementsByTagName("part"); if (part_list == null) { throw new IllegalArgumentException("File contains no part elements"); } len = part_list.getLength(); ArrayList<STSPart> plist = new ArrayList<STSPart>(); for (int i = 0; i < len; i++) { Element part = (Element) part_list.item(i); field = "file"; val = part.getAttribute(field); String file = val; field = "material"; val = part.getAttribute(field); String material = val; plist.add(new STSPart(file, material)); } ret_val.setParts(plist); NodeList metadata_list = doc.getElementsByTagName("entry"); NodeList material_list = doc.getElementsByTagName("material"); if (material_list != null) { HashMap<String, String> map = new HashMap<String, String>(); len = material_list.getLength(); for (int i = 0; i < len; i++) { Element entry = (Element) material_list.item(i); String key = entry.getAttribute("id"); String value = entry.getAttribute("urn"); if (key != null && key.length() > 0 && value != null && value.length() > 0) { map.put(key, value); } } ret_val.setMaterials(map); } if (metadata_list != null) { HashMap<String, String> map = new HashMap<String, String>(); len = metadata_list.getLength(); for (int i = 0; i < len; i++) { Element entry = (Element) metadata_list.item(i); String key = entry.getAttribute("key"); String value = entry.getAttribute("value"); if (key != null && key.length() > 0 && value != null && value.length() > 0) { map.put(key, value); } } ret_val.setMetadata(map); } return ret_val; } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException saxe) { saxe.printStackTrace(); } catch (Exception e) { printf("Cannot parse field: %s val: %s\n", field, val); e.printStackTrace(); } return null; }
From source file:org.coronastreet.gpxconverter.Strava.java
private void loadOutFile() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {/* w ww . j a va 2 s.c o m*/ DocumentBuilder db = dbf.newDocumentBuilder(); log("Loading TCX template file."); outDoc = db .parse(this.getClass().getResourceAsStream("/org/coronastreet/gpxconverter/tcxtemplate.xml")); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:com.baobao121.baby.common.ConnectorServlet.java
/** * Manage the Get requests (GetFolders, GetFoldersAndFiles, CreateFolder).<br> * //w w w . jav a 2 s . c o m * The servlet accepts commands sent in the following format:<br> * connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath<br> * <br> * It execute the command and then return the results to the client in XML * format. * */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (debug) System.out.println("--- BEGIN DOGET ---"); response.setContentType("text/xml; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); String currentPath = baseDir + typeStr + currentFolderStr; String currentDirPath = getServletContext().getRealPath(currentPath); File currentDir = new File(currentDirPath); if (!currentDir.exists()) { currentDir.mkdir(); } Document document = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } Node root = CreateCommonXml(document, commandStr, typeStr, currentFolderStr, request.getContextPath() + currentPath); if (debug) System.out.println("Command = " + commandStr); if (commandStr.equals("GetFolders")) { getFolders(currentDir, root, document); } else if (commandStr.equals("GetFoldersAndFiles")) { getFolders(currentDir, root, document); getFiles(currentDir, root, document); } else if (commandStr.equals("CreateFolder")) { String newFolderStr = request.getParameter("NewFolderName"); File newFolder = new File(currentDir, newFolderStr); String retValue = "110"; if (newFolder.exists()) { retValue = "101"; } else { try { boolean dirCreated = newFolder.mkdir(); if (dirCreated) retValue = "0"; else retValue = "102"; } catch (SecurityException sex) { retValue = "103"; } } setCreateFolderResponse(retValue, root, document); } document.getDocumentElement().normalize(); try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); if (debug) { StreamResult dbgResult = new StreamResult(System.out); transformer.transform(source, dbgResult); System.out.println(""); System.out.println("--- END DOGET ---"); } } catch (Exception ex) { ex.printStackTrace(); } out.flush(); out.close(); }
From source file:com.rapidsist.portal.cliente.editor.ConnectorServlet.java
/** * Manage the Get requests (GetFolders, GetFoldersAndFiles, CreateFolder).<br> * * The servlet accepts commands sent in the following format:<br> * connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath<br><br> * It execute the command and then return the results to the client in XML format. * *//*www . ja v a2 s. co m*/ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("PASO POR EL METODO doGet DEL SERVLET ConnectorServlet"); //OBTIENE EL USUARIO QUE OPERA EL EDITOR HTML HttpSession session = SesionUsuario.compruebaSesionUsuario(request, response); Usuario usuario = (Usuario) session.getAttribute("Usuario"); //OBTIENE LA CLAVE DE LA EMPRESA Y LA CLAVE DEL PORTAL ASIGNADOS AL USUARIO String sCveGpoEmpresa = usuario.sCveGpoEmpresa; String sCvePortal = usuario.sCvePortal; //CREA LA CARPETA UserFiles EN CASO DE NO EXISTIR. baseDir = "/UserFiles/"; String realBaseDir = getServletContext().getRealPath(baseDir); File baseFile = new File(realBaseDir); if (!baseFile.exists()) { baseFile.mkdir(); } //CREA LA CARPETA CveGpoEmpresa EN CASO DE NO EXISTIR. baseDir = "/UserFiles/" + sCveGpoEmpresa + "/"; realBaseDir = getServletContext().getRealPath(baseDir); baseFile = new File(realBaseDir); if (!baseFile.exists()) { baseFile.mkdir(); } //CREA LA CARPETA sCvePortal EN CASO DE NO EXISTIR LA CUAL ES LA RAIZ DEL REPOSITORIO DE ARCHIVOS. baseDir = "/UserFiles/" + sCveGpoEmpresa + "/" + sCvePortal + "/"; realBaseDir = getServletContext().getRealPath(baseDir); baseFile = new File(realBaseDir); if (!baseFile.exists()) { baseFile.mkdir(); } response.setContentType("text/xml; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); String currentPath = baseDir + typeStr + currentFolderStr; String currentDirPath = getServletContext().getRealPath(currentPath); File currentDir = new File(currentDirPath); if (!currentDir.exists()) { currentDir.mkdir(); } Document document = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } Node root = CreateCommonXml(document, commandStr, typeStr, currentFolderStr, request.getContextPath() + currentPath); if (commandStr.equals("GetFolders")) { getFolders(currentDir, root, document); } else if (commandStr.equals("GetFoldersAndFiles")) { getFolders(currentDir, root, document); getFiles(currentDir, root, document); } else if (commandStr.equals("CreateFolder")) { String newFolderStr = request.getParameter("NewFolderName"); File newFolder = new File(currentDir, newFolderStr); String retValue = "110"; if (newFolder.exists()) { retValue = "101"; } else { try { boolean dirCreated = newFolder.mkdir(); if (dirCreated) retValue = "0"; else retValue = "102"; } catch (SecurityException sex) { retValue = "103"; } } setCreateFolderResponse(retValue, root, document); } document.getDocumentElement().normalize(); try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); } catch (Exception ex) { ex.printStackTrace(); } out.flush(); out.close(); }
From source file:crds.pub.FCKeditor.connector.ConnectorServlet.java
/** * Manage the Get requests (GetFolders, GetFoldersAndFiles, CreateFolder).<br> * * The servlet accepts commands sent in the following format:<br> * connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath<br><br> * It execute the command and then return the results to the client in XML format. * *///from ww w .j a v a2s .c om public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); FormUserOperation formUser = Constant.getFormUserOperation(request); String fck_task_id = (String) session.getAttribute("fck_task_id"); if (fck_task_id == null) { fck_task_id = "temp_task_id"; } response.setContentType("text/xml; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); String currentPath = baseDir + formUser.getCompany_code() + currentFolderStr + fck_task_id + currentFolderStr + typeStr + currentFolderStr; String currentDirPath = getServletContext().getRealPath(currentPath); File currentDir = new File(currentDirPath); if (!currentDir.exists()) { currentDir.mkdirs(); } Document document = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } //???IP String server_ip = (String) session.getAttribute("server_ip"); if (server_ip == null) { server_ip = CommonMethod.getServerIP(request) + ":" + request.getServerPort();//???IP? } String url = "http://" + server_ip + currentPath.substring(2, currentPath.length()); Node root = CreateCommonXml(document, commandStr, typeStr, currentFolderStr, url); if (commandStr.equals("GetFolders")) { getFolders(currentDir, root, document); } else if (commandStr.equals("GetFoldersAndFiles")) { getFolders(currentDir, root, document); getFiles(currentDir, root, document); } else if (commandStr.equals("CreateFolder")) { String newFolderStr = request.getParameter("NewFolderName"); File newFolder = new File(currentDir, newFolderStr); String retValue = "110"; if (newFolder.exists()) { retValue = "101"; } else { try { boolean dirCreated = newFolder.mkdir(); if (dirCreated) retValue = "0"; else retValue = "102"; } catch (SecurityException sex) { retValue = "103"; } } setCreateFolderResponse(retValue, root, document); } document.getDocumentElement().normalize(); try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); if (debug) { StreamResult dbgResult = new StreamResult(System.out); transformer.transform(source, dbgResult); } } catch (Exception ex) { ex.printStackTrace(); } out.flush(); out.close(); }
From source file:org.coronastreet.gpxconverter.Converter.java
private void loadInFile(String file) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {/*from w w w. ja va 2s. c o m*/ DocumentBuilder db = dbf.newDocumentBuilder(); inDoc = db.parse(file); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } }