Package com.dotmarketing.portlets.contentlet.model

Examples of com.dotmarketing.portlets.contentlet.model.Contentlet$ContentletHashMap


      if(doc == null){
        /*Get the XSL source*/
        java.io.File binFile = null;
        Identifier xslId = APILocator.getIdentifierAPI().find(host, XSLPath);
        if(xslId!=null && InodeUtils.isSet(xslId.getId()) && xslId.getAssetType().equals("contentlet")){
          Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(xslId.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), userAPI.getSystemUser(),false);
          if(cont!=null && InodeUtils.isSet(cont.getInode())){
            binFile = cont.getBinary(FileAssetAPI.BINARY_FIELD);
          }
        }else{
          File xslFile = fileAPI.getFileByURI(XSLPath, host, true, userAPI.getSystemUser(),false);
          binFile = fileAPI.getAssetIOFile (xslFile);
        }
       
       
        /*Get the XML Source from file or from URL*/
        if(!XMLPath.startsWith("http")){
          Identifier xmlId = APILocator.getIdentifierAPI().find(host, XMLPath);
          if(xmlId!=null && InodeUtils.isSet(xmlId.getId()) && xmlId.getAssetType().equals("contentlet")){
            Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(xmlId.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), userAPI.getSystemUser(),false);
            if(cont!=null && InodeUtils.isSet(cont.getInode())){
              xmlSource = new StreamSource(new InputStreamReader(new FileInputStream(cont.getBinary(FileAssetAPI.BINARY_FIELD)), "UTF8"));
            }
          }else{
            File xmlFile = fileAPI.getFileByURI(XMLPath, host, true,userAPI.getSystemUser(),false);
            xmlSource = new StreamSource(new InputStreamReader(new FileInputStream(fileAPI.getAssetIOFile(xmlFile)), "UTF8"));
          }
View Full Code Here


   
      ica = new InternalContextAdapterImpl(ctx);
      String fieldResourceName = ica.getCurrentTemplateName();
      String conInode = fieldResourceName.substring(fieldResourceName.indexOf("/") + 1, fieldResourceName.indexOf("_"));
     
      Contentlet con = APILocator.getContentletAPI().find(conInode, APILocator.getUserAPI().getSystemUser(), true);
     
     
      User mu = userAPI.loadUserById(con.getModUser(), APILocator.getUserAPI().getSystemUser(), true);
      Role scripting =APILocator.getRoleAPI().loadRoleByKey("Scripting Developer");
      return APILocator.getRoleAPI().doesUserHaveRole(mu, scripting);
    }
    catch(Exception e){
      Logger.warn(this.getClass(), "Scripting called with error" + e);
View Full Code Here

    IFileAsset f =null;
    try {
        Identifier id  = APILocator.getIdentifierAPI().find(host, url);
        if(id!=null && InodeUtils.isSet(id.getId())) {
            if(id.getAssetType().equals("contentlet")){
                Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(id.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
                  if(cont!=null && InodeUtils.isSet(cont.getIdentifier()) && !APILocator.getVersionableAPI().isDeleted(cont)){
                      f = APILocator.getFileAssetAPI().fromContentlet(cont);
                  }
            }
            else {
                   f = fileAPI.getFileByURI(url, host, false, user, false);
View Full Code Here

    }
    if (host != null && InodeUtils.isSet(host.getInode()) && InodeUtils.isSet(folder.getInode())) {
      IFileAsset destinationFile = null;
      java.io.File workingFile = null;
      Folder parent = null;
      Contentlet fileAssetCont = null;
      Identifier identifier  = APILocator.getIdentifierAPI().find(host, path);
      if(identifier!=null && InodeUtils.isSet(identifier.getId()) && identifier.getAssetType().equals("contentlet")){
        fileAssetCont = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
        workingFile = fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD);
        destinationFile = APILocator.getFileAssetAPI().fromContentlet(fileAssetCont);
        parent = APILocator.getFolderAPI().findFolderByPath(identifier.getParentPath(), host, user, false);

        if(fileAssetCont.isArchived()) {
            APILocator.getContentletAPI().unarchive(fileAssetCont, user, false);
        }
      }else if(identifier!=null && InodeUtils.isSet(identifier.getId())){
        destinationFile = fileAPI.getFileByURI(path, host, false, user, false);
        // inode{1}/inode{2}/inode.file_extension
        workingFile = fileAPI.getAssetIOFile((File)destinationFile);

        if(destinationFile.isArchived()) {
            WebAssetFactory.unArchiveAsset((File)destinationFile);
        }
      }

      //http://jira.dotmarketing.net/browse/DOTCMS-1873
      //To clear velocity cache
      if(workingFile!=null){
        DotResourceCache vc = CacheLocator.getVeloctyResourceCache();
        vc.remove(ResourceManager.RESOURCE_TEMPLATE + workingFile.getPath());
      }

      InputStream is = content;
      byte[] currentData = IOUtils.toByteArray(is);

      if(destinationFile==null){
        Contentlet fileAsset = new Contentlet();
        Structure faStructure = StructureCache.getStructureByInode(folder.getDefaultFileType());
        Field fieldVar = faStructure.getFieldVar(FileAssetAPI.BINARY_FIELD);
        fileAsset.setStructureInode(folder.getDefaultFileType());
        fileAsset.setFolder(folder.getInode());
        if (currentData != null) {
          java.io.File tempUserFolder = new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary() + java.io.File.separator + user.getUserId() +
              java.io.File.separator + fieldVar.getFieldContentlet());
          if (!tempUserFolder.exists())
            tempUserFolder.mkdirs();

          java.io.File fileData = new java.io.File(tempUserFolder.getAbsolutePath() + java.io.File.separator + fileName);
          if(fileData.exists())
            fileData.delete();
          // Saving the new working data
          FileChannel writeCurrentChannel = new FileOutputStream(fileData).getChannel();
          writeCurrentChannel.truncate(0);
          ByteBuffer buffer = ByteBuffer.allocate(currentData.length);
          buffer.put(currentData);
          buffer.position(0);
          writeCurrentChannel.write(buffer);
          writeCurrentChannel.force(false);
          writeCurrentChannel.close();
          fileAsset.setStringProperty(FileAssetAPI.TITLE_FIELD, fileName);
          fileAsset.setStringProperty(FileAssetAPI.FILE_NAME_FIELD, fileName);
          fileAsset.setBinary(FileAssetAPI.BINARY_FIELD, fileData);
          fileAsset.setHost(host.getIdentifier());
          fileAsset=APILocator.getContentletAPI().checkin(fileAsset, user, false);

          //Validate if the user have the right permission before
          if(isAutoPub && !perAPI.doesUserHavePermission(fileAsset, PermissionAPI.PERMISSION_PUBLISH, user) ){
            APILocator.getContentletAPI().archive(fileAsset, APILocator.getUserAPI().getSystemUser(), false);
View Full Code Here

        Identifier identTo  = APILocator.getIdentifierAPI().find(host, getPath(toPath));
        boolean destinationExists=identTo!=null && InodeUtils.isSet(identTo.getId());

        if(identifier!=null && identifier.getAssetType().equals("contentlet")){
          Contentlet fileAssetCont = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
          if(!destinationExists) {
              if (getFolderName(fromPath).equals(getFolderName(toPath))) {
                String fileName = getFileName(toPath);
                if(fileName.contains(".")){
                  fileName = fileName.substring(0, fileName.lastIndexOf("."));
                }
                APILocator.getFileAssetAPI().renameFile(fileAssetCont, fileName, user, false);
              } else {
                APILocator.getFileAssetAPI().moveFile(fileAssetCont, toParentFolder, user, false);
              }
          }
          else {
              // if the destination exists lets just create a new version and delete the original file
              Contentlet origin = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
              Contentlet toContentlet = APILocator.getContentletAPI().findContentletByIdentifier(identTo.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
              Contentlet newversion = APILocator.getContentletAPI().checkout(toContentlet.getInode(), user, false);

              // get a copy in a tmp folder to avoid filename change
              java.io.File tmpDir=new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary()
                                +java.io.File.separator+UUIDGenerator.generateUuid());
              java.io.File tmp=new java.io.File(tmpDir, toContentlet.getBinary(FileAssetAPI.BINARY_FIELD).getName());
              FileUtil.copyFile(origin.getBinary(FileAssetAPI.BINARY_FIELD), tmp);

              newversion.setBinary(FileAssetAPI.BINARY_FIELD, tmp);
              newversion = APILocator.getContentletAPI().checkin(newversion, user, false);
              if(autoPublish) {
                  APILocator.getContentletAPI().publish(newversion, user, false);
              }
View Full Code Here

        diff = (currentDate.getTime()-timeOfPublishing)/1000;
        canDelete = diff >= minTimeAllowed;
      }

      if(identifier!=null && identifier.getAssetType().equals("contentlet")){
          Contentlet fileAssetCont = APILocator.getContentletAPI()
              .findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
         
          //Webdav calls the delete method when is creating a new file. But it creates the file with 0 content length.
          //No need to wait 10 seconds with files with 0 length.
          if(canDelete
              || (fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD) != null
                && fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD).length() <= 0)){
           
            try{
                APILocator.getContentletAPI().archive(fileAssetCont, user, false);
            }catch (Exception e) {
                Logger.error(DotWebdavHelper.class, e.getMessage(), e);
View Full Code Here

    try {
      identifier = APILocator.getIdentifierAPI().find(imageIdentifierInode);
    } catch (DotHibernateException e) {
      Logger.error(TemplateFactory.class,e.getMessage(),e);
    }
    Contentlet imageContentlet = new Contentlet();
    if(InodeUtils.isSet(identifier.getInode())){
      imageContentlet = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), APILocator.getUserAPI().getSystemUser(), false);
    }
    return imageContentlet;
  }
View Full Code Here

    }
    if (host != null && InodeUtils.isSet(host.getInode()) && InodeUtils.isSet(folder.getInode())) {
      java.io.File workingFile  = null;
      Identifier identifier  = APILocator.getIdentifierAPI().find(host, path);
      if(identifier!=null && identifier.getAssetType().equals("contentlet")){
                Contentlet cont  = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
          workingFile = cont.getBinary(FileAssetAPI.BINARY_FIELD);
      }else{
        File file = fileAPI.getFileByURI(path, host, false, user, false);
        // inode{1}/inode{2}/inode.file_extension
        workingFile = fileAPI.getAssetIOFile(file);
      }
View Full Code Here

      ident = ifac.loadFromCacheFromInode(inodeOrIdentifier);
    }
   
    if (ident == null || !InodeUtils.isSet(ident.getInode())) {
      try {
        Contentlet con = conAPI.find(inodeOrIdentifier, APILocator.getUserAPI().getSystemUser(), false);
        if (con != null && InodeUtils.isSet(con.getInode())) {
          ident = ifac.find(con.getIdentifier());
          return ident;
        }
      } catch (Exception e) {
        Logger.debug(this, "Unable to find inodeOrIdentifier as content : ", e);
      }
View Full Code Here

        if(!UtilMethods.isSet(ident.getId()))
          return false;

        if(ident.getAssetType().equals("contentlet")) {
            Contentlet cont=(Contentlet)ver;
            ContentletVersionInfo cinfo=vfac.getContentletVersionInfo(cont.getIdentifier(), cont.getLanguageId());
            return cinfo.isDeleted();
        }
        else {
            VersionInfo info = vfac.getVersionInfo(ver.getVersionId());
            if(!UtilMethods.isSet(info.getIdentifier()))
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.contentlet.model.Contentlet$ContentletHashMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.