@Test public void parseText() throws SAXException, IOException { URL url = getClass().getResource("/jabberwocky.txt"); Document instruct = docBuilder.parse(getClass().getResourceAsStream( "/img/model-argb-transparent.xml")); StringWriter strWriter = new StringWriter(); PrintWriter logger = new PrintWriter(strWriter); Document result = ImageParser.parse(url.openConnection(), instruct.getDocumentElement(), logger); assertNull(result); assertTrue("Unexpected error message", strWriter.toString().startsWith("No image handlers available")); }
public static Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { Document doc = null; InputStream is = null; try { is = uc.getInputStream(); doc = parse(is, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { String msg = String.format( "Failed to parse %s resource from %s %n %s", uc.getContentType(), uc.getURL(), e.getMessage()); jlogger.warning(msg); } finally { if (null != is) { try { is.close(); } catch (IOException e) { } } } return doc; }
ImageParser { public static Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { Document doc = null; InputStream is = null; try { is = uc.getInputStream(); doc = parse(is, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { String msg = String.format( "Failed to parse %s resource from %s %n %s", uc.getContentType(), uc.getURL(), e.getMessage()); jlogger.warning(msg); } finally { if (null != is) { try { is.close(); } catch (IOException e) { } } } return doc; } }
ImageParser { public static Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { Document doc = null; InputStream is = null; try { is = uc.getInputStream(); doc = parse(is, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { String msg = String.format( "Failed to parse %s resource from %s %n %s", uc.getContentType(), uc.getURL(), e.getMessage()); jlogger.warning(msg); } finally { if (null != is) { try { is.close(); } catch (IOException e) { } } } return doc; } ImageParser(Document init); }
ImageParser { public static Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { Document doc = null; InputStream is = null; try { is = uc.getInputStream(); doc = parse(is, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { String msg = String.format( "Failed to parse %s resource from %s %n %s", uc.getContentType(), uc.getURL(), e.getMessage()); jlogger.warning(msg); } finally { if (null != is) { try { is.close(); } catch (IOException e) { } } } return doc; } ImageParser(Document init); static int getImageWidth(String imageLoc); static int getImageHeight(String imageLoc); static String getImageType(String imageLoc); static String getSupportedImageTypes(); static Document parse(URLConnection uc, Element instruction,
            PrintWriter logger); Document parseAsInitialized(URLConnection uc, Element instruction,
            PrintWriter logger); static Document parseBase64(String base64Data, Element instruction); static void main(String[] args); }
ImageParser { public static Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { Document doc = null; InputStream is = null; try { is = uc.getInputStream(); doc = parse(is, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { String msg = String.format( "Failed to parse %s resource from %s %n %s", uc.getContentType(), uc.getURL(), e.getMessage()); jlogger.warning(msg); } finally { if (null != is) { try { is.close(); } catch (IOException e) { } } } return doc; } ImageParser(Document init); static int getImageWidth(String imageLoc); static int getImageHeight(String imageLoc); static String getImageType(String imageLoc); static String getSupportedImageTypes(); static Document parse(URLConnection uc, Element instruction,
            PrintWriter logger); Document parseAsInitialized(URLConnection uc, Element instruction,
            PrintWriter logger); static Document parseBase64(String base64Data, Element instruction); static void main(String[] args);  }