コード例 #1
0
ファイル: UploadBean.java プロジェクト: natasab/imeji
 /**
  * Upload a file from the web
  *
  * @return
  */
 public String uploadFromLink() {
   try {
     externalUrl = URLDecoder.decode(externalUrl, "UTF-8");
     URL url = new URL(externalUrl);
     title = findFileName(url);
     File tmp = createTmpFile();
     try {
       StorageController externalController = new StorageController("external");
       FileOutputStream fos = new FileOutputStream(tmp);
       externalController.read(url.toString(), fos, true);
       Item item = uploadFile(tmp);
       if (item != null) {
         UserController uc = new UserController(null);
         user = uc.retrieve(getUser().getEmail());
         ItemController ic = new ItemController(user);
         ic.create(item, collection.getId());
       }
       externalUrl = "";
     } finally {
       FileUtils.deleteQuietly(tmp);
     }
   } catch (Exception e) {
     logger.error("Error uploading file from link: " + externalUrl, e);
     fFiles.add(e.getMessage() + ": " + title);
   }
   return "";
 }
コード例 #2
0
ファイル: UploadBean.java プロジェクト: natasab/imeji
 /** Create the {@link Item} for the files which have been uploaded */
 private void createItemForFiles() {
   ItemController ic = new ItemController(user);
   try {
     ic.create(itemList, collection.getId());
     itemList = new ArrayList<Item>();
   } catch (Exception e) {
     logger.error("Error creating files for upload", e);
   }
 }
コード例 #3
0
ファイル: UploadBean.java プロジェクト: natasab/imeji
 /**
  * True if the filename is already used by an {@link Item} in this {@link CollectionImeji}
  *
  * @param filename
  * @return
  */
 private boolean filenameExistsInCollection(String filename) {
   Search s = new Search(SearchType.ITEM, null);
   return s.searchSimpleForQuery(
               SPARQLQueries.selectContainerItemByFilename(
                   collection.getId(), FilenameUtils.getBaseName(filename)),
               null)
           .size()
       > 0;
 }
コード例 #4
0
ファイル: UploadBean.java プロジェクト: natasab/imeji
 /** Load the collection */
 public void loadCollection() {
   if (id != null) {
     collection =
         ObjectLoader.loadCollectionLazy(
             ObjectHelper.getURI(CollectionImeji.class, id), sessionBean.getUser());
     if (collection != null && getCollection().getId() != null) {
       ItemController ic = new ItemController(sessionBean.getUser());
       collectionSize = ic.countContainerSize(collection.getId());
     }
   } else {
     BeanHelper.error(sessionBean.getLabel("error") + "No ID in URL");
   }
 }
コード例 #5
0
ファイル: UploadBean.java プロジェクト: natasab/imeji
 /**
  * Search for an item in the current collection with the same filename. The filename must be
  * unique!
  *
  * @param filename
  * @return
  */
 private Item findItemByFileName(String filename) {
   Search s = new Search(SearchType.ITEM, null);
   List<String> sr =
       s.searchSimpleForQuery(
           SPARQLQueries.selectContainerItemByFilename(
               collection.getId(), FilenameUtils.getBaseName(filename)),
           null);
   if (sr.size() == 0)
     throw new RuntimeException(
         "No item found with the filename " + FilenameUtils.getBaseName(filename));
   if (sr.size() > 1)
     throw new RuntimeException(
         "Filename "
             + FilenameUtils.getBaseName(filename)
             + " not unique ("
             + sr.size()
             + " found).");
   return ObjectLoader.loadItem(URI.create(sr.get(0)), user);
 }
コード例 #6
0
 /** Check that at least one image is editable and if the profile is not empty */
 @Override
 public boolean isImageEditable() {
   return super.isImageDeletable()
       && ObjectCachedLoader.loadProfile(collection.getProfile()).getStatements().size() > 0;
 }
コード例 #7
0
ファイル: UploadBean.java プロジェクト: natasab/imeji
 public void setDiscardComment(String comment) {
   collection.setDiscardComment(comment);
 }
コード例 #8
0
ファイル: UploadBean.java プロジェクト: natasab/imeji
 public String getDiscardComment() {
   return collection.getDiscardComment();
 }