Package com.dotmarketing.beans

Examples of com.dotmarketing.beans.Host


                //Verify if we want to move inside the same app
                if ( !refererHost.equals( serverName ) ) {

                    //Trying to find the host in our list of host
                    Host foundHost = APILocator.getHostAPI().findByName( refererHost, systemUser, false );
                    if ( !UtilMethods.isSet( foundHost ) ) {
                        foundHost = APILocator.getHostAPI().findByAlias( refererHost, systemUser, false );
                    }

                    //If the host was not found it means it is a external url
View Full Code Here


            if ( file.isDirectory() && file.getName().startsWith("tm_")) {
                File hostDir = new File(file.getAbsolutePath() + File.separator + "live");
                if ( hostDir.exists() && hostDir.isDirectory() ) {
                    for(String hostname : hostDir.list()) {
                        try {
                            Host host=APILocator.getHostAPI().findByName(hostname, APILocator.getUserAPI().getSystemUser(), false);
                            if(host!=null && UtilMethods.isSet(host.getIdentifier()))
                                list.add(host);
                        }catch(Exception ex) {
                            Logger.warn(this, ex.getMessage(),ex);
                        }
                    }
View Full Code Here

        folderIdent.getURI().length() - 1);

    folderChildPath = folderChildPath.substring(0, folderChildPath
        .lastIndexOf("/"));

    Host host = hostAPI.findParentHost(thisFolder, systemUser, false);

    Identifier id = identAPI.loadFromCache(host, folderIdent.getURI()
        + "/index."
        + Config.getStringProperty("VELOCITY_PAGE_EXTENSION"));

    Logger.debug(this, "Performing check for folders [" + (folderIdent.getURI() + "/index." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION")) + "], Identifier Check ["
     + (id != null) + "], Children Count [" + itemsChildrenList2.size() + "], Host Identifier [" + host.getIdentifier() + "], Identifier " +
     ((id != null) ? id.getInode() : "") + "]");

    boolean isIndexPageAlreadyConfigured = false;

    if ((id != null) && InodeUtils.isSet(id.getInode())) {
      stringbuf = "<url><loc>"
          + XMLUtils
              .xmlEscape("http://"
                  + host.getHostname()
                  + folderIdent.getURI())
          + "</loc><lastmod>" + modifiedDateStringValue
          + "</lastmod><changefreq>daily</changefreq></url>\n";

      Logger.debug(this, "Writing the XMLConfiguration for Folder[" + XMLUtils
              .xmlEscape("http://"
                  + host.getHostname()
                  + folderIdent.getURI()) + "]"
      );

      isIndexPageAlreadyConfigured = true;

      writeFile(stringbuf);
      addRegistryProcessed();
    }

    if (currentLevel < numberOfLevels) {

      for (Permissionable childChild2 : itemsChildrenList2) {
        if (childChild2 instanceof Folder) {
          Folder folderChildChild2 = (Folder) childChild2;
          Identifier childChild2Ident = identAPI
              .find(folderChildChild2.getIdentifier());

          if (currentLevel <= numberOfLevels) {
            buildSubFolderSiteMapMenu(folderChildChild2,
                numberOfLevels, currentLevel + 1,
                orderDirection);
          } else {
            stringbuf = "<url><loc>"
                + XMLUtils
                    .xmlEscape("http://"
                        + host.getHostname()
                        + childChild2Ident.getURI())
                + "</loc><lastmod>"
                + modifiedDateStringValue
                + "</lastmod><changefreq>daily</changefreq></url>\n";

            Logger.debug(this, "Writing the XMLConfiguration Second Level Check for [" + XMLUtils
                    .xmlEscape("http://"
                        + host.getHostname()
                        + childChild2Ident.getURI()) + "]");

            writeFile(stringbuf);
            addRegistryProcessed();
          }
        } else if (childChild2 instanceof Link) {
          Link link2 = (Link) childChild2;
          if (link2.isLive() && !link2.isDeleted()) {
            if (link2.getUrl().startsWith(host.getHostname())) {
              stringbuf = "<url><loc>"
                  + XMLUtils.xmlEscape(link2.getProtocal()
                      + link2.getUrl())
                  + "</loc><lastmod>"
                  + modifiedDateStringValue
                  + "</lastmod><changefreq>daily</changefreq></url>\n";
              writeFile(stringbuf);
              addRegistryProcessed();
            }
          }
        } else if (childChild2 instanceof HTMLPage) {
          HTMLPage page2 = (HTMLPage) childChild2;
          Identifier childChild2Ident = identAPI.find(page2
              .getIdentifier());
          if (page2.isLive() && !page2.isDeleted()) {
            String indexPageConfiguration = "/index."+ Config.getStringProperty("VELOCITY_PAGE_EXTENSION");

            String pathToPageUrl = XMLUtils.xmlEscape("http://" + host.getHostname() + childChild2Ident.getURI());

            if (pathToPageUrl.endsWith(indexPageConfiguration) && isIndexPageAlreadyConfigured) {
              Logger.debug(this, "Index Page is already configured, skipping the process [" + pathToPageUrl + "]");
              continue;
            }

            pathToPageUrl = pathToPageUrl.replace(indexPageConfiguration, "");

            stringbuf = "<url><loc>" + pathToPageUrl + "</loc><lastmod>" + modifiedDateStringValue + "</lastmod><changefreq>daily</changefreq></url>\n";

            Logger.debug(this, "Writing the XMLConfiguration for an HTML Page with out index." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION","html") + " extension [" + pathToPageUrl + "]");

            writeFile(stringbuf);

            addRegistryProcessed();
          }
        } else if (childChild2 instanceof com.dotmarketing.portlets.files.model.File) {
          com.dotmarketing.portlets.files.model.File file2 = (com.dotmarketing.portlets.files.model.File) childChild2;
          Identifier childChild2Ident = identAPI.find(file2
              .getIdentifier());
          if (file2.isLive() && !file2.isDeleted()) {
            stringbuf = "<url><loc>"
                + XMLUtils.xmlEscape("http://"
                    + host.getHostname()
                    + childChild2Ident.getURI() + "/"
                    + file2.getFileName())
                + "</loc><lastmod>"
                + modifiedDateStringValue
                + "</lastmod><changefreq>daily</changefreq></url>\n";
            writeFile(stringbuf);
            addRegistryProcessed();
          }
        } else if (childChild2 instanceof Contentlet) {
          Contentlet fileContent = (Contentlet)childChild2;
          if (fileContent.isLive() && !fileContent.isArchived()) {
            Identifier identifier = APILocator.getIdentifierAPI().find(fileContent);
            stringbuf = "<url><loc>"
                + XMLUtils.xmlEscape("http://"
                    + host.getHostname()
                    + UtilMethods.encodeURIComponent(identifier.getParentPath()+fileContent.getStringProperty(FileAssetAPI.FILE_NAME_FIELD)))
                + "</loc><lastmod>"
                + modifiedDateStringValue
                + "</lastmod><changefreq>daily</changefreq></url>\n";
            writeFile(stringbuf);
View Full Code Here

public class FolderAPITest {
   
    @Test
    public void renameFolder() throws Exception {
        User user = APILocator.getUserAPI().getSystemUser();
        Host demo = APILocator.getHostAPI().findByName("demo.dotcms.com", user, false);
        Folder ftest = APILocator.getFolderAPI().createFolders("/folderTest"+System.currentTimeMillis(), demo, user, false);
        Folder ftest1 = APILocator.getFolderAPI().createFolders(ftest.getPath()+"/ff1", demo, user, false);
        Folder ftest2 = APILocator.getFolderAPI().createFolders(ftest.getPath()+"/ff1/ff2", demo, user, false);
        Folder ftest3 = APILocator.getFolderAPI().createFolders(ftest.getPath()+"/ff1/ff2/ff3", demo, user, false);
       
View Full Code Here

      User systemUser = APILocator.getUserAPI().getSystemUser();
      if (request.getParameter("cmd") != null && request.getParameter("cmd").equals(Constants.ADD)) {
        String inode = request.getParameter("parent");
        Folder parentFolder = APILocator.getFolderAPI().find(inode, systemUser, false);
        if (!InodeUtils.isSet(parentFolder.getInode())) {
          Host host;
          host = (Host) hostAPI.find(inode, systemUser, false);
          if (host != null) {
            ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.folder.ishostfolder"));
          }
        }
View Full Code Here

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       
        try {
            Host host = WebAPILocator.getHostWebAPI().getCurrentHost(req);
            boolean live = !WebAPILocator.getUserWebAPI().isLoggedToBackend(req);
            User user = WebAPILocator.getUserWebAPI().getLoggedInUser(req);
            String reqURI=req.getRequestURI();
            String uri = reqURI.substring(reqURI.indexOf('/', 1));
           
            if(!reqURI.endsWith(".css")) {
                String path=live ? LiveCache.getPathFromCache(uri, host.getIdentifier()) : WorkingCache.getPathFromCache(uri, host.getIdentifier());
                if(UtilMethods.isSet(path)) {
                    req.getRequestDispatcher("/dotAsset?path=" + path).forward(req, resp);
                }
                else {
                    resp.sendError(404);
                }
                return;
            }
           
            // choose compiler based on the request URI
            Class<? extends CSSCompiler> compilerClass = reqURI.startsWith("/DOTSASS/") ? SassCompiler.class
                                           (reqURI.startsWith("/DOTLESS/") ? LessCompiler.class : null);
            CSSCompiler compiler = compilerClass.getConstructor(Host.class,String.class,boolean.class).newInstance(host,uri,live);
           
            // check if the asset exists
            String actualUri =  uri.substring(0, uri.lastIndexOf('.')) + "." + compiler.getDefaultExtension();
            Identifier ident = APILocator.getIdentifierAPI().find(host, actualUri);
            if(ident==null || !InodeUtils.isSet(ident.getId())) {
                resp.sendError(404);
                return;
            }
           
            // get the asset in order to build etag and check permissions
            long defLang=APILocator.getLanguageAPI().getDefaultLanguage().getId();
            FileAsset fileasset;
            try {
                fileasset = APILocator.getFileAssetAPI().fromContentlet(
                    APILocator.getContentletAPI().findContentletByIdentifier(ident.getId(), live, defLang, user, true));
            }
            catch(DotSecurityException ex) {
                resp.sendError(403);
                return;
            }
           
            boolean userHasEditPerms = false;
            if(!live) {
                userHasEditPerms = APILocator.getPermissionAPI().doesUserHavePermission(fileasset,PermissionAPI.PERMISSION_EDIT,user);
                if(req.getParameter("recompile")!=null && userHasEditPerms) {
                    CacheLocator.getCSSCache().remove(host.getIdentifier(), actualUri, false);
                    CacheLocator.getCSSCache().remove(host.getIdentifier(), actualUri, true);
                }
            }
           
            CachedCSS cache = CacheLocator.getCSSCache().get(host.getIdentifier(), actualUri, live, user);
           
            byte[] responseData=null;
            Date cacheMaxDate=null;
            CachedCSS cacheObject=null;
           
            if(cache==null || cache.data==null) {
                // do compile!
                synchronized(ident.getId().intern()) {
                    cache = CacheLocator.getCSSCache().get(host.getIdentifier(), actualUri, live, user);
                    if(cache==null || cache.data==null) {
                        Logger.debug(this, "compiling css data for "+host.getHostname()+":"+uri);
                       
                        try {
                            compiler.compile();
                        }
                        catch(Throwable ex) {
                            Logger.error(this, "Error compiling "+host.getHostname()+":"+uri, ex);
                            throw new Exception(ex);
                        }
                       
                        // build cache object
                        ContentletVersionInfo vinfo = APILocator.getVersionableAPI().getContentletVersionInfo(ident.getId(), defLang);
                        CachedCSS newcache = new CachedCSS();
                        newcache.data = compiler.getOutput();
                        newcache.hostId = host.getIdentifier();
                        newcache.uri = actualUri;
                        newcache.live = live;
                        newcache.modDate = vinfo.getVersionTs();
                        newcache.imported = new ArrayList<ImportedAsset>();
                        for(String importUri : compiler.getAllImportedURI()) {
                            // newcache entry for the imported asset
                            ImportedAsset asset = new ImportedAsset();
                            asset.uri = importUri;
                            Identifier ii;
                            if(importUri.startsWith("//")) {
                                importUri=importUri.substring(2);
                                String hn=importUri.substring(0, importUri.indexOf('/'));
                                String uu=importUri.substring(importUri.indexOf('/'));
                                ii = APILocator.getIdentifierAPI().find(APILocator.getHostAPI().findByName(hn, user, live),uu);
                            }
                            else {
                                ii = APILocator.getIdentifierAPI().find(host, importUri);
                            }
                            ContentletVersionInfo impInfo = APILocator.getVersionableAPI().getContentletVersionInfo(ii.getId(), defLang);
                            asset.modDate = impInfo.getVersionTs();
                            newcache.imported.add(asset);
                            Logger.debug(this, host.getHostname()+":"+actualUri+" imports-> "+importUri);
                           
                            // actual cache entry for the imported asset. If needed
                            synchronized(ii.getId().intern()) {
                                if(CacheLocator.getCSSCache().get(ii.getHostId(), importUri, live, user)==null) {
                                    CachedCSS entry = new CachedCSS();
                                    entry.data = null;
                                    entry.hostId = ii.getHostId();
                                    entry.imported = new ArrayList<ImportedAsset>();
                                    entry.live = live;
                                    entry.modDate = impInfo.getVersionTs();
                                    entry.uri = importUri;
                                    CacheLocator.getCSSCache().add(entry);
                                }
                            }
                        }
                        CacheLocator.getCSSCache().add(newcache);
                        cacheMaxDate = newcache.getMaxDate();
                        cacheObject = newcache;
                        responseData = compiler.getOutput();
                    }
                }
            }
           
            if(responseData==null) {
                if(cache!=null && cache.data!=null) {
                    // if css is cached an valid is used as response
                    responseData = cache.data;
                    cacheMaxDate = cache.getMaxDate();
                    cacheObject = cache;
                    Logger.debug(this, "using cached css data for "+host.getHostname()+":"+uri);
                }
                else {
                    resp.sendError(500, "no data!");
                    return;
                }
            }
           
           
            boolean doDownload = true;
           
            if(live) {
                // we use etag dot:inode:cacheMaxDate:filesize and lastMod:cacheMaxDate
                // so the browser downloads it if any of the imported files changes
                doDownload = DownloadUtil.isModifiedEtag(req, resp, fileasset.getInode(),
                        cacheMaxDate.getTime(), fileasset.getFileSize());
            }
           
            if(doDownload) {
                // write the actual response to the user
                resp.setContentType("text/css");
                resp.setHeader("Content-Disposition",
                        "inline; filename=\"" + uri.substring(uri.lastIndexOf('/'), uri.length()) + "\"");
               
                if(!live && userHasEditPerms && req.getParameter("debug")!=null) {
                    // debug information requested
                    PrintWriter out = resp.getWriter();
                    out.println("/*");
                    out.println("Cached CSS: "+host.getHostname()+":"+actualUri);
                    out.println("Size: "+cacheObject.data.length+" bytes");
                    out.println("Imported uris:");
                    for(ImportedAsset asset : cacheObject.imported) {
                        out.println("  "+asset.uri);
                    }
View Full Code Here

        } catch (DotSecurityException e) {
          Logger.error(getClass(), "Couldn't add the Folder to the Bundle. Bundle ID: " + config.getId() + ", Folder ID: " + asset.getAsset(), e);
        }
      } else if(asset.getType().equals("host")) {
        try {
          Host h = APILocator.getHostAPI().find(asset.getAsset(), user, false);
         
          if(h == null){
            Logger.warn(getClass(), "Host id: "+ (asset.getAsset() != null ? asset.getAsset() : "N/A") +" does NOT have working or live version, not Pushed");
          } else {
            hosts.add(asset.getAsset(), h.getModDate());
            hostsSet.add(asset.getAsset());
          }
         
        } catch (DotSecurityException e) {
          Logger.error(getClass(), "Couldn't add the Host to the Bundle. Bundle ID: " + config.getId() + ", Host ID: " + asset.getAsset(), e);
View Full Code Here

        Identifier ident=APILocator.getIdentifierAPI().find(linkId);
        Folder ff = APILocator.getFolderAPI().findFolderByPath(ident.getParentPath(), ident.getHostId(), user, false);
                folders.addOrClean( ff.getInode(), ff.getModDate());
        foldersSet.add(ff.getInode());

        Host hh=APILocator.getHostAPI().find(ident.getHostId(), user, false);
                hosts.addOrClean( hh.getIdentifier(), hh.getModDate());
        hostsSet.add(hh.getIdentifier());

        Link link = APILocator.getMenuLinkAPI().findWorkingLinkById(linkId, user, false);

        if(link!=null) {
View Full Code Here

   * </ul>
   */
  private void setHostDependencies () {
    try {
      for (String id : hostsSet) {
        Host h = APILocator.getHostAPI().find(id, user, false);

        // Template dependencies
        List<Template> templateList = APILocator.getTemplateAPI().findTemplatesAssignedTo(h);
        for (Template template : templateList) {
          templates.addOrClean( template.getIdentifier(), template.getModDate());
          templatesSet.add(template.getIdentifier());
        }

        // Container dependencies
        List<Container> containerList = APILocator.getContainerAPI().findContainersUnder(h);
        for (Container container : containerList) {
          containers.addOrClean( container.getIdentifier(), container.getModDate());
          containersSet.add(container.getIdentifier());
        }

        // Content dependencies
        String luceneQuery = "+conHost:" + h.getIdentifier();

        List<Contentlet> contentList = APILocator.getContentletAPI().search(luceneQuery, 0, 0, null, user, false);
        for (Contentlet contentlet : contentList) {
          contents.addOrClean( contentlet.getIdentifier(), contentlet.getModDate());
          contentsSet.add(contentlet.getIdentifier());
View Full Code Here

      // Add folder even if empty
      folders.addOrClean( f.getInode(), f.getModDate());
      foldersSet.add(f.getInode());

      // Host dependency
      Host h = APILocator.getHostAPI().find(f.getHostId(), user, false);
      hosts.addOrClean( f.getHostId(), h.getModDate());
      hostsSet.add(f.getHostId());

      // Content dependencies
      String luceneQuery = "+conFolder:" + f.getInode();
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.