コード例 #1
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sendcode_screen);
    setTitle(LOG_TAG);

    serverProvider = new ServerProvider(this);
    SessionManager.init(this);
    SessionManager.readSession();
    BookManager.BuildBook(getResources().openRawResource(R.raw.json));

    if (SessionManager.getS().isAuthKeyOk()) {
      Log.i(LOG_TAG, "auth_key loaded from preferences.");
    } else {
      Log.i(LOG_TAG, "Generating new Auth key...");

      new AuthKeyGenerator().execute();
    }

    sendCodeButton = (Button) findViewById(R.id.button222);
    sendCodeButton.setOnClickListener(sendCodeButtonClickListener);

    tel1Text = (EditText) findViewById(R.id.tel1);
    tel2Text = (EditText) findViewById(R.id.tel2);
    control = IMControl.getInstance();
    control.setServer(serverProvider.getServerInfo());

    connectAction();
  }
コード例 #2
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/xml;charset=UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=export.xml");
    PrintWriter out = response.getWriter();
    try {
      DatabaseWrapper db = new DatabaseWrapper();

      // fill database wrapper with data
      db.setUsers(userMgr.findAll());
      db.setBooks(bookMgr.findAll());
      db.setAuthors(authorMgr.findAll());
      db.setBookings(bookingMgr.findAll());
      db.setBorrows(borrowMgr.findAll());
      db.setExemplars(exemplarMgr.findAll());
      db.setGenres(genreMgr.findAll());
      db.setPublishers(publisherMgr.findAll());

      // Step 2 - convert to xml
      JAXBContext jaxbContext = JAXBContext.newInstance(DatabaseWrapper.class);

      Marshaller marshaller = jaxbContext.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

      marshaller.marshal(db, out);

    } catch (Exception ex) {
      ex.printStackTrace(out);
    } finally {
      out.close();
    }
  }
コード例 #3
0
  /**
   * Import book exemplars
   *
   * @param nodes
   * @return
   */
  private Boolean processExemplars(NodeList nodes) {
    NodeList exemplars = nodes.item(0).getChildNodes();

    for (int i = 0; i < exemplars.getLength(); i++) {
      if (exemplars.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element exemplarNode = (Element) exemplars.item(i);

        Exemplar exemplar = new Exemplar();

        exemplar.setIdexemplar(Integer.parseInt(getTagValue("idexemplar", exemplarNode)));
        exemplar.setAquired(
            DatatypeConverter.parseDateTime(getTagValue("aquired", exemplarNode)).getTime());
        exemplar.setState(Integer.parseInt(getTagValue("state", exemplarNode)));

        Book book = bookMgr.findByIdbook(Integer.parseInt(getTagValue("book", exemplarNode)));
        if (book == null) {
          continue;
        }

        exemplar.setBook(book);

        try {
          exemplarMgr.save(exemplar);
        } catch (EJBException ex) {
          ex.printStackTrace(System.out);
        }
      }
    }
    return true;
  }
コード例 #4
0
  /**
   * Import books
   *
   * @param nodes
   * @return
   */
  private Boolean processBooks(NodeList nodes) {
    NodeList books = nodes.item(0).getChildNodes();

    for (int i = 0; i < books.getLength(); i++) {
      if (books.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element bookNode = (Element) books.item(i);

        Book book = new Book();

        book.setIdbook(Integer.parseInt(getTagValue("idbook", bookNode)));
        book.setCode(getTagValue("code", bookNode));
        book.setEdition(Integer.parseInt(getTagValue("edition", bookNode)));
        book.setPages(Integer.parseInt(getTagValue("pages", bookNode)));
        book.setPlace(getTagValue("place", bookNode));
        book.setYear(DatatypeConverter.parseDateTime(getTagValue("year", bookNode)).getTime());
        book.setType(getTagValue("type", bookNode));
        book.setName(getTagValue("name", bookNode));

        // find and set publisher
        Publisher publisher =
            publisherMgr.findByIdpublisher(Integer.parseInt(getTagValue("publisher", bookNode)));
        if (publisher == null) {
          continue;
        }

        book.setPublisher(publisher);

        // find and set genre
        Genre genre = genreMgr.findByIdgenre(Integer.parseInt(getTagValue("genre", bookNode)));
        if (genre == null) {
          continue;
        }

        book.setGenre(genre);

        // setup book authors
        List<String> authors = getTagsValues("authorCollection", bookNode);

        if (book.getAuthorCollection() == null) {
          book.setAuthorCollection(new ArrayList<Author>());
        }

        for (String authorId : authors) {
          Author author = authorMgr.findByIdauthor(Integer.parseInt(authorId));
          if (author != null) {
            //						book.getAuthorCollection().add(author);
            author.getBooksCollection().add(book);
            authorMgr.save(author);
          }
        }

        try {
          bookMgr.save(book);
        } catch (EJBException ex) {
          ex.printStackTrace(System.out);
        }
      }
    }
    return true;
  }
コード例 #5
0
  /**
   * File upload listener
   *
   * @param event
   * @throws Exception
   */
  public void listener(FileUploadEvent event) throws Exception {
    UploadedFile file = event.getUploadedFile();

    try {

      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(file.getInputStream());
      doc.getDocumentElement().normalize();

      processUsers(doc.getElementsByTagName("users"));
      processAuthors(doc.getElementsByTagName("authors"));
      processPublishers(doc.getElementsByTagName("publishers"));
      processGenres(doc.getElementsByTagName("genres"));
      processBooks(doc.getElementsByTagName("books"));
      processExemplars(doc.getElementsByTagName("exemplars"));
      processBookings(doc.getElementsByTagName("bookings"));
      processBorrows(doc.getElementsByTagName("borrows"));

      userMgr.flush();
      bookMgr.flush();
      authorMgr.flush();
      bookingMgr.flush();
      exemplarMgr.flush();
      genreMgr.flush();
      publisherMgr.flush();
      borrowMgr.flush();

      userMgr.clear();
      bookMgr.clear();
      authorMgr.clear();
      bookingMgr.clear();
      exemplarMgr.clear();
      genreMgr.clear();
      publisherMgr.clear();
      borrowMgr.clear();

    } catch (Exception e) {
      FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Import se nezdařil."));
      e.printStackTrace(System.out);

      return;
    }

    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Import proběhl úspěšně."));
  }
コード例 #6
0
ファイル: BookMain.java プロジェクト: SenyMin/JavaBasic
 public void getData() {
   for (int i = model.getRowCount() - 1; i >= 0; i--) {
     model.removeRow(i);
   }
   ArrayList<Book> list = bm.bookAllData();
   for (Book book : list) {
     String[] data = {String.valueOf(book.getNo()), book.getTitle(), book.getAuthor()};
     model.addRow(data);
   }
 }
コード例 #7
0
ファイル: BookMain.java プロジェクト: SenyMin/JavaBasic
 public void getFindData() {
   for (int i = model.getRowCount() - 1; i >= 0; i--) {
     model.removeRow(i);
   }
   String pub = box.getSelectedItem().toString();
   ArrayList<Book> list = bm.bookFindData(pub);
   tf.setText(pub);
   for (Book book : list) {
     String[] data = {String.valueOf(book.getNo()), book.getTitle(), book.getAuthor()};
     model.addRow(data);
   }
 }
コード例 #8
0
ファイル: BookMain.java プロジェクト: SenyMin/JavaBasic
 @Override
 public void mouseClicked(MouseEvent e) {
   // TODO Auto-generated method stub
   if (e.getSource() == table) {
     if (e.getClickCount() == 2) // 더블클릭
     {
       int row = table.getSelectedRow();
       String no = model.getValueAt(row, 0).toString();
       bp.setPoster(Integer.parseInt(no));
       bp.repaint();
       Book book = bm.bookDetail(Integer.parseInt(no));
       la1.setText("번호:" + no);
       la2.setText("제목:" + book.getTitle());
       la3.setText("저자:" + book.getAuthor());
       la4.setText("출판사:" + book.getPublisher());
       la5.setText("가격:" + book.getPrice());
     }
   } else if (e.getSource() == b) {
     getData();
   }
 }
コード例 #9
0
  /**
   * Import bookings
   *
   * @param nodes
   * @return
   */
  private Boolean processBookings(NodeList nodes) {
    NodeList bookings = nodes.item(0).getChildNodes();

    for (int i = 0; i < bookings.getLength(); i++) {
      if (bookings.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element bookingNode = (Element) bookings.item(i);

        Booking booking = new Booking();

        booking.setIdbooking(Integer.parseInt(getTagValue("idbooking", bookingNode)));
        booking.setState(Integer.parseInt(getTagValue("state", bookingNode)));
        booking.setDate(
            DatatypeConverter.parseDateTime(getTagValue("date", bookingNode)).getTime());

        Book book = bookMgr.findByIdbook(Integer.parseInt(getTagValue("book", bookingNode)));
        if (book == null) {
          continue;
        }

        booking.setBook(book);

        User user = userMgr.findByIduser(Integer.parseInt(getTagValue("user", bookingNode)));
        if (user == null) {
          continue;
        }

        booking.setUser(user);

        try {
          bookingMgr.Save(booking);
        } catch (EJBException ex) {
          ex.printStackTrace(System.out);
        }
      }
    }
    return true;
  }