Ejemplo n.º 1
0
 /**
  * Gets the list JSON data.
  *
  * @param tasks task iterator
  * @return list JSON data
  */
 private void getJson(Iterator<Document> documents) throws IOException {
   StringBuilder jsonBuilder = new StringBuilder("{");
   while (documents.hasNext()) {
     Document instance = documents.next();
     int id = instance.getId();
     String name = instance.getName();
     jsonBuilder.append("\"").append(id).append("\":\"").append(name).append("\"");
     if (documents.hasNext()) {
       jsonBuilder.append(",");
     }
   }
   jsonBuilder.append("}");
   // Returns JSON data back to page
   HttpServletResponse response = ServletActionContext.getResponse();
   response.setContentType("text/html;charset=UTF-8");
   response.getWriter().write(jsonBuilder.toString());
 }
Ejemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see com.gcrm.dao.IDocumentDao#save(com.gcrm.domain.Document,
  * java.io.File)
  */
 @SuppressWarnings("resource")
 public Document save(Document document, File f) throws Exception {
   if (f != null) {
     InputStream stream = new BufferedInputStream(new FileInputStream(f));
     byte[] input = new byte[stream.available()];
     stream.read(input);
     document.setFileContent(input);
   }
   return super.makePersistent(document);
 }