Package com.dotmarketing.portlets.htmlpages.model

Examples of com.dotmarketing.portlets.htmlpages.model.HTMLPage


        respectFrontendRoles)) {
      throw new DotSecurityException("You don't have permission to wirte in the destination folder.");
    }

    boolean isNew = false;
    HTMLPage newHTMLPage;
    if (forceOverwrite) {
      newHTMLPage = getWorkingHTMLPageByPageURL(source.getPageUrl(), destination);
      if (newHTMLPage == null) {
        isNew = true;
      }
    } else {
      isNew = true;
    }

    newHTMLPage = new HTMLPage();
    newHTMLPage.copy(source);

    // gets page url before extension
    String pageURL = UtilMethods.getFileName(source.getPageUrl());

    // gets file extension
    String fileExtension = UtilMethods.getFileExtension(source.getPageUrl());

    if (!forceOverwrite) {
      newHTMLPage.setPageUrl(getCopyHTMLPageName(pageURL, fileExtension, destination));

      if (!UtilMethods.getFileName(newHTMLPage.getPageUrl()).equals(pageURL))
        newHTMLPage.setFriendlyName(source.getFriendlyName() + " (COPY)");
    }

    Template destinationTemplate = reMapping.getDestinationTemplate();

    List<MultiTree> associatedSourceContentlets = null;

    //Checking if contentlets just need to be remapped or need to be copied on destination
    if (copyMode == HTMLPageAPI.CopyMode.USE_SOURCE_CONTENT) {
      associatedSourceContentlets = getHTMLPageMultiTree(source);
    } else if (copyMode == HTMLPageAPI.CopyMode.COPY_SOURCE_CONTENT) {
      associatedSourceContentlets = getHTMLPageMultiTree(source);

      Contentlet contentlet;
      FolderAPI folderAPI = APILocator.getFolderAPI();
      Host systemHost = hostAPI.findSystemHost(user, respectFrontendRoles);
      Folder systemFolder = folderAPI.findSystemFolder();
      Host destinationHost = hostAPI.find(destination.getHostId(), user, respectFrontendRoles);

      for (MultiTree multiTree : associatedSourceContentlets) {
        contentlet = contentletAPI.findContentletByIdentifier(multiTree.getChild(), false, 0, user,
            respectFrontendRoles);

        Host contentletHost = null;
        if(!UtilMethods.isSet(contentlet.getHost()) && !contentlet.getHost().equals(systemHost.getInode())) {
          contentletHost = hostAPI.find(contentlet.getHost(), user, respectFrontendRoles);
        }
        Folder contentletFolder = null;
        if(!UtilMethods.isSet(contentlet.getFolder()) && !contentlet.getFolder().equals(systemFolder.getInode())) {
          contentletFolder = folderAPI.find(contentlet.getFolder(),user,false);
        }

        if (contentletFolder != null) {
          Folder contentletDestFolder = folderAPI.createFolders(APILocator.getIdentifierAPI().find(contentletFolder).getPath(), destinationHost,user,false);
          contentlet = contentletAPI.copyContentlet(contentlet, contentletDestFolder, user, respectFrontendRoles);
        } else if (contentletHost != null) {
          contentlet = contentletAPI.copyContentlet(contentlet, destinationHost, user, respectFrontendRoles);
        } else {
          contentlet = contentletAPI.copyContentlet(contentlet, user, respectFrontendRoles);
        }

        multiTree.setChild(contentlet.getIdentifier());
      }
    }

    //Creating the new pages associations mapping with containers
    List<MultiTree> newContentletAssociation = new LinkedList<MultiTree>();
    if (copyMode != HTMLPageAPI.CopyMode.BLANK_HTMLPAGE) {
      for (MultiTree multiTree : associatedSourceContentlets) {
        String sourceContainerId = multiTree.getParent2();
        String destinationContainerId = null;
        for (int i = 0; i < reMapping.getContainersRemap().size(); i++) {
          ContainerRemapTuple tuple = reMapping.getContainersRemap().get(i);
          if(tuple.getSourceContainer().getIdentifier().equals(sourceContainerId)) {
            destinationContainerId = tuple.getDestinationContainer().getIdentifier();
          }
        }
        if(destinationContainerId != null) {
          newContentletAssociation.add(new MultiTree("", destinationContainerId, multiTree.getChild()));
        }
      }
    }
        newHTMLPage.setTemplateId(destinationTemplate.getIdentifier());
    //Persisting the new page
    if (isNew) {
      // creates new identifier for this webasset and persists it
      Identifier newIdentifier = com.dotmarketing.business.APILocator.getIdentifierAPI().createNew(newHTMLPage, destination);
     
      newHTMLPage.setIdentifier(newIdentifier.getInode());
     
      // persists the webasset
      save(newHTMLPage);
    } else {
      saveHTMLPage(newHTMLPage, destinationTemplate, destination, user, respectFrontendRoles);
    }
   
    if(source.isLive()){
      APILocator.getVersionableAPI().setWorking(newHTMLPage);
      APILocator.getVersionableAPI().setLive(newHTMLPage);
    }
       

    //Saving the new content mapping
    if (copyMode != HTMLPageAPI.CopyMode.BLANK_HTMLPAGE) {
      MultiTree newMultiTree;
      for (MultiTree multiTree : newContentletAssociation) {
        newMultiTree = new MultiTree(newHTMLPage.getIdentifier(), multiTree.getParent2(), multiTree.getChild());
        MultiTreeFactory.saveMultiTree(newMultiTree);
      }
    }

    // Copy permissions
View Full Code Here


    return MultiTreeFactory.getMultiTree(identifierAPI.findFromInode(htmlPage.getIdentifier()));
  }

  @SuppressWarnings("unchecked")
  public HTMLPage getWorkingHTMLPageByPageURL(String htmlPageURL, Folder folder) throws DotStateException, DotDataException, DotSecurityException {
    HTMLPage ret = null;
    if(folder != null && InodeUtils.isSet(folder.getInode())){
      Host h = APILocator.getHostAPI().find(folder.getHostId(), APILocator.getUserAPI().getSystemUser(), true);
      String p = folder.getPath();
      if(UtilMethods.isSet(p)){
        if(!p.startsWith("/")){
View Full Code Here

  }


  public HTMLPage saveHTMLPage(HTMLPage newHtmlPage, Template template, Folder parentFolder, User user,
      boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
    HTMLPage existingHTMLPage = getWorkingHTMLPageByPageURL(newHtmlPage.getPageUrl(), parentFolder);

    boolean pageExists = (existingHTMLPage != null) && InodeUtils.isSet(existingHTMLPage.getInode());

    if (pageExists) {

            if ( newHtmlPage.getIdentifier() != null && !newHtmlPage.getIdentifier().equals( existingHTMLPage.getIdentifier() ) ) {
                throw new DotDataException( "You are trying to save a page with the same name and location but a different identifier. " +
                        "If you are trying to push Publish you may have to rename the folder [" + parentFolder.getPath() + "]. " +
                        "HTMLPage trying to save [" + newHtmlPage.getIdentifier() + "], found HTMLPage [" + existingHTMLPage.getIdentifier() + "]" );
            }

      if (!permissionAPI.doesUserHavePermission(existingHTMLPage, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
        throw new DotSecurityException("You don't have permission to read the HTML page.");
      }
    }

    if (!permissionAPI.doesUserHavePermission(template, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
      throw new DotSecurityException("You don't have permission to read the template or the template is not published.");
    }

    if (!permissionAPI.doesUserHavePermission(parentFolder, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles)) {
      throw new DotSecurityException("You don't have permission to write in the destination folder.");
    }

    try {
        newHtmlPage.setModUser(user.getUserId());
        newHtmlPage.setModDate(new Date());
       
      boolean previousShowMenu = false;

      // parent identifier for this file
      Identifier identifier = null;

      if (pageExists) {
        previousShowMenu = existingHTMLPage.isShowOnMenu();
        identifier = (Identifier) APILocator.getIdentifierAPI().find(existingHTMLPage);
      }

      // Some checks

      // Get asset host based on the parentFolder of the asset
      Host host = hostAPI.findParentHost(parentFolder, user, false);

      // get an identifier based on this new uri
      Identifier testIdentifier = (Identifier) APILocator.getIdentifierAPI().find(host, newHtmlPage.getURI(parentFolder));
     
      // if this is a new htmlpage and there is already an identifier with
      // this uri, return
      if ((existingHTMLPage != null) && !InodeUtils.isSet(existingHTMLPage.getInode()) && InodeUtils.isSet(testIdentifier.getInode())) {
        existingHTMLPage.setParent(parentFolder.getInode());
        throw new DotDataException("Another page with the same page url exists in this folder");
      }
      // if this is an existing htmlpage and there is already an
      // identifier
      // with this uri, return
      else if (pageExists
          && (!testIdentifier.getInode().equalsIgnoreCase(identifier.getInode()))
          && InodeUtils.isSet(testIdentifier.getInode())) {
        // when there is an error saving should unlock working asset
        unLockAsset(existingHTMLPage);
        throw new DotDataException("Another page with the same page url exists in this folder");
      }
      if (template != null) {
        // Adds template children from selected box
        Identifier templateIdentifier = APILocator.getIdentifierAPI().find(template);

        newHtmlPage.setTemplateId(templateIdentifier.getInode());
      }
     
      boolean existingIdentifier=false;
      Identifier currentIdentifier=null;
      if(UtilMethods.isSet(newHtmlPage.getIdentifier())) {
          currentIdentifier=APILocator.getIdentifierAPI().find(newHtmlPage.getIdentifier());
          existingIdentifier = currentIdentifier==null || !UtilMethods.isSet(currentIdentifier.getId());
      }
     
      boolean existingInode=false;
            if(InodeUtils.isSet(newHtmlPage.getInode())) {
                try {
                    HTMLPage existing=(HTMLPage) HibernateUtil.load(HTMLPage.class, newHtmlPage.getInode());
                    existingInode= existing==null || !UtilMethods.isSet(existing.getInode());
                } catch (Exception ex) {
                    existingInode=true;
                }
            }
     
View Full Code Here

    Identifier ident = APILocator.getIdentifierAPI().find(host, uri);


    Logger.debug(HTMLPageAPIImpl.class, "Page Permissions for URI=" + uri);

    HTMLPage pageProxy = new HTMLPage();
    pageProxy.setIdentifier(ident.getInode());

    // Check if the page is visible by a CMS Anonymous role
    try {
      if (!permissionAPI.doesUserHavePermission(pageProxy,
          PermissionAPI.PERMISSION_READ, user, true)) {
View Full Code Here

    return getHTML(uri, host, liveMode, contentId, user, userAgent);
  }


  public HTMLPage loadWorkingPageById(String pageId, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException {
    HTMLPage page = htmlPageFactory.loadWorkingPageById(pageId);
    if(page == null)
      return page;
    if(!permissionAPI.doesUserHavePermission(page, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles))
      throw new DotSecurityException("User " + user.getUserId() + "has no permissions to read page id " + pageId);
View Full Code Here

    return page;
  }

  public HTMLPage loadLivePageById(String pageId, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException {
    HTMLPage page = htmlPageFactory.loadLivePageById(pageId);
    if(page == null)
      return page;
    if(!permissionAPI.doesUserHavePermission(page, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles))
      throw new DotSecurityException("User " + user.getUserId() + "has no permissions to read page id " + pageId);
View Full Code Here

 
  @Override
  protected HTMLPage get(String key) {

    key = primaryGroup + key;
    HTMLPage htmlPage = null;
      try{
        htmlPage = (HTMLPage)cache.get(key,primaryGroup);
      }catch (DotCacheException e) {
      Logger.debug(this, "Cache Entry not found", e);
    }
View Full Code Here

        // clear the cache
        cache.flushGroup(primaryGroup);
    }

    public void remove(String pageIdentifier){
      HTMLPage page = new HTMLPage();
      page.setIdentifier(pageIdentifier);
      remove(page);
    }
View Full Code Here

        Logger.debug(HTMLPageFactory.class, "Looking for page : " + path);
    Logger.debug(HTMLPageFactory.class, "got id " + id.getInode());

        //if this page does not exist, create it, add it to the course folder, use the course template, etc...
        if(!InodeUtils.isSet(id.getInode())){
            return  new HTMLPage();
        }

      return (HTMLPage) APILocator.getVersionableAPI().findLiveVersion(id,APILocator.getUserAPI().getSystemUser(),false);

  }
View Full Code Here

      return pages.get(0);
  }

  @SuppressWarnings("unchecked")
  public HTMLPage loadLivePageById(String pageId) throws DotDataException, DotStateException, DotSecurityException {
    HTMLPage page = htmlPageCache.get(pageId);
    if(page ==null){
        HibernateUtil hu = new HibernateUtil(HTMLPage.class);
        hu.setSQLQuery("select {htmlpage.*} from htmlpage, inode htmlpage_1_, htmlpage_version_info htmlvi " +
            " where htmlpage_1_.inode = htmlpage.inode and htmlpage.identifier=htmlvi.identifier" +
            " and htmlvi.live_inode=htmlpage.inode " +
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.htmlpages.model.HTMLPage

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.