Guest User

Untitled

a guest
Oct 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. File file = new File("C:\DocuApi\imageDemoApp\src\main\resources\static\feed_shopy.xml");
  4. JAXBContext jaxbContext;
  5. try {
  6. jaxbContext = JAXBContext.newInstance("com.stack.image.dto");
  7. Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller();
  8.  
  9. System.out.println("Parsed XML successfully");
  10.  
  11. List<String> imageList = new ArrayList<String>();
  12. List<String> nonImageList = new ArrayList<String>();
  13.  
  14.  
  15. SHOP shop = (SHOP)jaxbUnMarshaller.unmarshal(file);
  16. List<SHOPITEM> shopItems = shop.getSHOPITEM();
  17. for(SHOPITEM shopItem: shopItems){
  18. IMAGES images = shopItem.getIMAGES();
  19. List<String> imageURIs = images.getIMAGE();
  20. for(String imguri: imageURIs){
  21. Image image;
  22. try {
  23. image = ImageIO.read(new URL(imguri));
  24. if(image != null){
  25.  
  26. imageList.add(imguri);
  27. }else{
  28. nonImageList.add(imguri);
  29. }
  30. } catch (MalformedURLException e) {
  31.  
  32. nonImageList.add(imguri);
  33. e.printStackTrace();
  34. } catch (IOException e) {
  35.  
  36. nonImageList.add(imguri);
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41.  
  42. System.out.println("Size of imageList is- " + imageList.size());
  43. System.out.println("Size of nonImageList is- " + nonImageList.size());
  44. for(String imageUrl: nonImageList){
  45. System.out.println("NonImage URL " + imageUrl);
  46. }
  47. } catch (JAXBException e) {
  48. e.printStackTrace();
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment