Beispiel #1
0
  public static void main(String[] args) {
    if (args.length < 5) {
      LOG.error("args: <fb-ip> <password> <user> <service> <action> *[key=value]");
      System.exit(1);
    } else {
      ip = args[0];
      password = args[1];
      user = args[2];
      serviceName = args[3];
      actionName = args[4];
      for (int i = 5; i < args.length; i++) {
        String[] parts = args[i].split("=");
        if (parts.length == 2) {
          if (params == null) {
            params = new HashMap<String, Object>();
          }
          try {
            Integer ipart = Integer.parseInt(parts[1]);
            params.put(parts[0], ipart);
          } catch (NumberFormatException e) {
            params.put(parts[0], parts[1]);
          }
        } else {
          LOG.error(args[i] + "not a valid parameter (key=value");
        }
      }
    }
    // Create a new FritzConnection with username and password
    FritzConnection fc = new FritzConnection(ip, user, password);
    try {
      // The connection has to be initiated. This will load the tr64desc.xml respectively
      // igddesc.xml
      // and all the defined Services and Actions.
      fc.init();
    } catch (IOException | JAXBException e) {
      LOG.error(e.getLocalizedMessage(), e);
    }

    // Get the Service. Returns null if not existing
    Service service = fc.getService(serviceName);
    if (service == null) {
      LOG.error("service " + serviceName + " does not exist");
      System.exit(1);
    }
    // Get the Action. Returns null if not existing
    Action action = service.getAction(actionName);
    if (action == null) {
      LOG.error("action " + actionName + " does not exist for service " + serviceName);
      System.exit(1);
    }
    try {
      // Execute the action without any In-Parameter.
      Response response1 = action.execute(params);
      for (String key : response1.getData().keySet()) {
        System.out.println(key + " = " + response1.getData().get(key));
      }
    } catch (UnsupportedOperationException | IOException e) {
      LOG.error(e.getLocalizedMessage(), e);
    }
  }
  @Override
  public void integrateXMLs(String xmlFileName) {
    // Will collect Bikelists from all XML files.
    List<Bikelist> listOfBikeList = new ArrayList<Bikelist>();

    try {
      // Folder where all the XML files are stored.
      File f = new File("data");
      // Searching every xml file in the data folder.
      for (final File fileEntry : f.listFiles()) {
        int i = fileEntry.getName().lastIndexOf(".");
        String extension = fileEntry.getName().substring(i + 1);

        if (fileEntry.isFile()
            && !fileEntry.getName().equalsIgnoreCase("IntegratedXMLFile.xml")
            && extension.equals("xml")) {
          JAXBContext context = JAXBContext.newInstance(JAXB_CONTEXT_PACKAGE);
          Bikelist b = (Bikelist) context.createUnmarshaller().unmarshal(fileEntry);

          listOfBikeList.add(b);
        }
      }

      // A final list of bikes gathered from different bikelists.
      Bikelist bikelistclass = new Bikelist();
      List<Bike> finalBikeList = bikelistclass.getBike();

      // Merging bikelists from all the XML files
      for (Bikelist bikelist : listOfBikeList) {
        for (Bike bike : bikelist.getBike()) {
          finalBikeList.add(bike);
        }
      }

      // have to merge this list with list from the Integrated XML file.

      JAXBContext context1 = JAXBContext.newInstance(JAXB_CONTEXT_PACKAGE);
      f = new File("xmlfiles" + File.separator + "IntegratedXML.xml");

      FileOutputStream fos = null;
      try {
        JAXBContext jaxbContext = JAXBContext.newInstance(JAXB_CONTEXT_PACKAGE);
        Marshaller marshaller = jaxbContext.createMarshaller();
        fos = new FileOutputStream(XML_FILES_FOLDER + File.separator + "integratedXMLFile.xml");

        marshaller.marshal(bikelistclass, fos);
      } catch (IOException | JAXBException e) {
        e.printStackTrace();
      } finally {
        try {
          fos.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

    } catch (JAXBException e) {
      e.printStackTrace();
    }
  }
 boolean checkPP(String pib) {
   try {
     List<PoslovniPartneri> poslovniPartneri;
     poslovniPartneri = ppDao.findAll();
     for (PoslovniPartneri pp : poslovniPartneri) {
       if (pp.getFirma().getPib().equals(pib)) {
         return true;
       }
     }
     return false;
   } catch (IOException | JAXBException e) {
     e.printStackTrace();
     return false;
   }
 }