Package com.dotmarketing.beans

Examples of com.dotmarketing.beans.Host


      }

      if(tags!=null) {
        for (Tag tag : tags) {
          String hostId = tag.getHostId();
          Host host = null;
          try{
            host = APILocator.getHostAPI().find(hostId, user, true);
          }
          catch (Exception e){
            Logger.error(this, "Unable to get host from tag Id:"+ tag.getHostId());
          }
          if (host!=null){
            Map<String,Object> tagMap = new HashMap<String,Object>();
            String hostName = "";
            if(host.isSystemHost())
              hostName = LanguageUtil.get(APILocator.getUserAPI().getSystemUser(), "tag-all-hosts");
            else
              hostName = host.getHostname();
            tagMap.put("tagId", tag.getTagId());
            tagMap.put("tagname", tag.getTagName());
            tagMap.put("hostId", tag.getHostId());
            tagMap.put("hostName", hostName);
            items.add(tagMap);
View Full Code Here


     * @throws IOException
     * @throws DotDataException
     * @throws NoSuchUserException
     */
      private InputStream loadFile(String filePath) throws DotSecurityException, FileNotFoundException, NoSuchUserException, DotDataException{
      Host h = APILocator.getHostAPI().findByName(filePath.substring(0,filePath.indexOf("DOTHOST")), userAPI.getSystemUser(), true);
      String fp = filePath.substring(filePath.indexOf('/'),filePath.length());
      Identifier ident = APILocator.getIdentifierAPI().find(h, fp);
     
      String uri = LiveCache.getPathFromCache(ident.getURI(), h);

View Full Code Here

     * @throws IOException
     * @throws DotDataException
     * @throws NoSuchUserException
     */
      public static String readFile(String filePath) throws IOException,DotSecurityException, DotDataException {
        Host h = APILocator.getHostAPI().findByName(filePath.substring(0,filePath.indexOf("DOTHOST")), userAPI.getSystemUser(), true);
      String fp = filePath.substring(filePath.indexOf('/'),filePath.length());
        Identifier ident = APILocator.getIdentifierAPI().find(h, fp);
       
      String uri = LiveCache.getPathFromCache(ident.getURI(), h);

View Full Code Here

    }
    return v;
  }

  private Path buildRootPath(String filePath){
    Host h;
    try {
      h = APILocator.getHostAPI().findByName(filePath.substring(0,filePath.indexOf("DOTHOST")), APILocator.getUserAPI().getSystemUser(), true);
    } catch (DotDataException e) {
      Logger.error(PHPEngine.class,e.getMessage(),e);
      throw new DotReindexStateException(e.getMessage(), e);
View Full Code Here

      List<Host> hostList = new ArrayList<Host>();

      String hosts = loadPluginConfigProperty(pluginId, "hosts.name");
      if(UtilMethods.isSet(hosts)){
        for(String hostname : hosts.split(",")){ 
          Host host = hostAPI.findByName(hostname, systemUser, false);
          hostList.add(host);
        }
      }else{
        Host host = hostAPI.findDefaultHost(systemUser, false);
        hostList.add(host);
      }

      Enumeration resources = jar.entries();
      while(resources.hasMoreElements()){

        JarEntry entry = (JarEntry) resources.nextElement();
        // find the files inside the dotcms folder in the jar to copy on backend with this reg expression ("dotcms\\/.*\\.([^\\.]+)$")
        if(entry.getName().matches("dotcms\\/.*\\.([^\\.]+)$") ){

          String filePathAndName=entry.getName().substring(7);
          String filePath = "";
          if(filePathAndName.lastIndexOf("/") != -1){
            filePath = filePathAndName.substring(0, filePathAndName.lastIndexOf("/"));
          }
          String fileName = filePathAndName.substring(filePathAndName.lastIndexOf("/")+1);
          String pluginFolderPath = "/plugins/"+pluginId;

          Logger.debug(this,"files in dotcms:"+filePathAndName+"\n");
          //Create temporary file with the inputstream to be used in the FileFactory
          InputStream input = jar.getInputStream(entry);
          File temporaryFile = new File("file.temp");
          OutputStream output=new FileOutputStream(temporaryFile);
          byte buf[]=new byte[1024];
          int len;
          while((len=input.read(buf))>0){
            output.write(buf,0,len);
          }
          output.close();
          input.close();

          for(Host host : hostList){

            Folder folder = APILocator.getFolderAPI().findFolderByPath(pluginFolderPath + "/" + filePath,host,APILocator.getUserAPI().getSystemUser(),false);
            if( !InodeUtils.isSet(folder.getInode())){     
              folder = APILocator.getFolderAPI().createFolders(pluginFolderPath + "/" + filePath, host,APILocator.getUserAPI().getSystemUser(),false);
            }
            //GetPrevious version if exists
            IFileAsset currentFile = null;
            Identifier currentId = APILocator.getIdentifierAPI().find(host, pluginFolderPath+"/"+filePathAndName);
            if(currentId!=null && InodeUtils.isSet(currentId.getId()) && currentId.getAssetType().equals("contentlet")){
              Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(currentId.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), APILocator.getUserAPI().getSystemUser(),false);
              if(cont!=null && InodeUtils.isSet(cont.getInode())){
                currentFile = APILocator.getFileAssetAPI().fromContentlet(cont);
                cont.setStringProperty(FileAssetAPI.TITLE_FIELD, UtilMethods.getFileName(fileName));
                cont.setFolder(folder.getInode());
                cont.setHost(host.getIdentifier());
                cont.setBinary(FileAssetAPI.BINARY_FIELD, temporaryFile);
                APILocator.getContentletAPI().checkin(cont, APILocator.getUserAPI().getSystemUser(),false);
                APILocator.getVersionableAPI().setWorking(cont);
                APILocator.getVersionableAPI().setLive(cont);
                if (cont.isLive()){
                  LiveCache.removeAssetFromCache(cont);
                  LiveCache.addToLiveAssetToCache(cont);
                }else{
                  LiveCache.removeAssetFromCache(cont);
                  LiveCache.addToLiveAssetToCache(cont);
                }
                WorkingCache.removeAssetFromCache(cont);
                WorkingCache.addToWorkingAssetToCache(cont);
              }
            }else if(currentId!=null && InodeUtils.isSet(currentId.getId())){
              currentFile = APILocator.getFileAPI().getFileByURI(pluginFolderPath+"/"+filePathAndName, host, true, APILocator.getUserAPI().getSystemUser(),false);
              com.dotmarketing.portlets.files.model.File file = new com.dotmarketing.portlets.files.model.File();
              file.setFileName(fileName);
              file.setFriendlyName(UtilMethods.getFileName(fileName));
              file.setTitle(UtilMethods.getFileName(fileName));
              file.setMimeType(APILocator.getFileAPI().getMimeType(fileName));
              file.setOwner(systemUser.getUserId());
              file.setModUser(systemUser.getUserId());
              file.setModDate(new Date());
              file.setParent(folder.getIdentifier());
              file.setSize((int)temporaryFile.length());
             
              HibernateUtil.saveOrUpdate(file);
              APILocator.getFileAPI().invalidateCache(file);
              // get the file Identifier
              Identifier ident = null;
              if (InodeUtils.isSet(currentFile.getInode())){
                ident = APILocator.getIdentifierAPI().find((com.dotmarketing.portlets.files.model.File)currentFile);
                APILocator.getFileAPI().invalidateCache((com.dotmarketing.portlets.files.model.File)currentFile);
              }else{
                ident = new Identifier();
              }
              //Saving the file, this creates the new version and save the new data
              com.dotmarketing.portlets.files.model.File workingFile = null;
              workingFile = APILocator.getFileAPI().saveFile(file, temporaryFile, folder, systemUser, false);
             
              APILocator.getVersionableAPI().setWorking(workingFile);
              APILocator.getVersionableAPI().setLive(workingFile);

              APILocator.getFileAPI().invalidateCache(workingFile);
              ident = APILocator.getIdentifierAPI().find(workingFile);

              //updating caches
              if (workingFile.isLive()){
                LiveCache.removeAssetFromCache(workingFile);
                LiveCache.addToLiveAssetToCache(workingFile);
              }else{
                LiveCache.removeAssetFromCache(file);
                LiveCache.addToLiveAssetToCache(file);
              }
              WorkingCache.removeAssetFromCache(workingFile);
              WorkingCache.addToWorkingAssetToCache(workingFile);
             
              //Publish the File
              PublishFactory.publishAsset(workingFile, systemUser, false);

            }else{
              Contentlet cont = new Contentlet();
              cont.setStructureInode(folder.getDefaultFileType());
              cont.setStringProperty(FileAssetAPI.TITLE_FIELD, UtilMethods.getFileName(fileName));
              cont.setFolder(folder.getInode());
              cont.setHost(host.getIdentifier());
              cont.setBinary(FileAssetAPI.BINARY_FIELD, temporaryFile);
              APILocator.getContentletAPI().checkin(cont, APILocator.getUserAPI().getSystemUser(),false);
              APILocator.getVersionableAPI().setWorking(cont);
              APILocator.getVersionableAPI().setLive(cont);
              if (cont.isLive()){
View Full Code Here

          try{

            tag = TagFactory.getTag(tagName, userId, hostId);
            String tagStorageForHost = "";
            Host host = APILocator.getHostAPI().find(hostId, APILocator.getUserAPI().getSystemUser(),true);

            if(host==null) {

              HttpSession session = WebContextFactory.get().getSession();
              hostId = (String) session.getAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID);
              host = APILocator.getHostAPI().find(hostId, APILocator.getUserAPI().getSystemUser(),true);
            }
            tagAPI.addTagInode(tagName,
                APILocator.getUserProxyAPI().getUserProxy(userId, APILocator.getUserAPI().getSystemUser(), false).getInode(),
                hostId);

            if(host!=null && host.getIdentifier()!=null && host.getIdentifier().equals(Host.SYSTEM_HOST))
              tagStorageForHost = Host.SYSTEM_HOST;
            else {
              try {
                tagStorageForHost = host.getMap().get("tagStorage").toString();
              } catch(NullPointerException e) {
                tagStorageForHost = Host.SYSTEM_HOST;
              }
            }
View Full Code Here

   */
  public List<Tag> getSuggestedTag(String tagName, String selectedHostOrFolderId) {
    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    try{
      User currentUser = com.liferay.portal.util.PortalUtil.getUser(req);
      Host host = APILocator.getHostAPI().find(selectedHostOrFolderId, currentUser, false);
      if(!UtilMethods.isSet(host) || !UtilMethods.isSet(host.getInode())){
        selectedHostOrFolderId = APILocator.getFolderAPI().find(selectedHostOrFolderId, currentUser, false).getHostId();
      }
    }catch(Exception e){
      Logger.error(TagAjax.class,e.getMessage());
    }
View Full Code Here

        if(!validateParams(null, hostIdentifier, null)) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }

        Host host=APILocator.getHostAPI().find(hostIdentifier, getUser(), false);

        List<Date> snaps=APILocator.getTimeMachineAPI().getAvailableTimeMachineForSite(host);

        Collections.sort(snaps, new Comparator<Date>() {
           @Override
View Full Code Here

        if(!validateParams(datestr, hostIdentifier, null)) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }

        Host host=APILocator.getHostAPI().find(hostIdentifier, getUser(), false);

        List<String> langs=APILocator.getTimeMachineAPI().getAvailableLangForTimeMachine(
                                 host, new Date(Long.parseLong(datestr)));

        List<Map<String,String>> list=new ArrayList<Map<String,String>>();
View Full Code Here

        try {
            // validating
            if(datestr!=null)
                Long.parseLong(datestr);
            if(hostIdentifier!=null) {
                Host hh=APILocator.getHostAPI().find(hostIdentifier, getUser(), false);
                if(hh==null || !UtilMethods.isSet(hh.getIdentifier()))
                    throw new Exception();
            }
            if(langid!=null) {
                Language ll=APILocator.getLanguageAPI().getLanguage(langid);
                if(ll==null || !UtilMethods.isSet(ll.getId()))
View Full Code Here

TOP

Related Classes of com.dotmarketing.beans.Host

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.