Package com.dotmarketing.portlets.htmlpages.model

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


      hf.setSelectedparentPath(APILocator.getIdentifierAPI().find(parentFolder).getPath());
    } catch (Exception e) {
      Logger.info(this, e.getMessage());
    }
    // This can't be done on the WebAsset so it needs to be done here.
    HTMLPage htmlpage = (HTMLPage) req.getAttribute(WebKeys.HTMLPAGE_EDIT);
    htmlpage.setParent(parentFolder.getInode());

    // removes the extension .jsp from page url
    String pageName = htmlpage.getPageUrl();
    if (pageName != null) {
      pageName = pageName.replaceAll("." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION"), "");
    }
    // to remove the page extension on the bean
    hf.setPageUrl(pageName);
View Full Code Here


    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    // Retreiving the current HTMLPage
    HTMLPage existingHTMLPage = (HTMLPage) req.getAttribute(WebKeys.HTMLPAGE_EDIT);

    boolean previousShowMenu = existingHTMLPage.isShowOnMenu();

    // parent folder or inode for this file
    Folder parentFolder = APILocator.getFolderAPI().find(req.getParameter("parent"), user, false);
    // http://jira.dotmarketing.net/browse/DOTCMS-5899
    Identifier id = null;
    if (UtilMethods.isSet(existingHTMLPage.getIdentifier()))
      id = APILocator.getIdentifierAPI().find(existingHTMLPage);
    if (id != null && UtilMethods.isSet(id.getInode())) {
      String URI = id.getURI();
      String uriPath = URI.substring(0, URI.lastIndexOf("/") + 1);
      if (!uriPath.equals(APILocator.getIdentifierAPI().find(parentFolder).getPath())) {
        id.setURI(APILocator.getIdentifierAPI().find(parentFolder).getPath() + existingHTMLPage.getPageUrl());
        APILocator.getIdentifierAPI().save(id);
      }
    }

    req.setAttribute(WebKeys.PARENT_FOLDER, parentFolder); // Since the
                                // above query
                                // is expensive,
                                // save it into
                                // request
                                // object

    String template = req.getParameter("template");

    if (!UtilMethods.isSet(template)) {
      SessionMessages.add(httpReq, "error", "message.htmlpage.select.Template");
      throw new Exception(LanguageUtil.get(user, "message.htmlpage.select.Template"));
    }

    // Adds template children from selected box
    Identifier templateIdentifier = APILocator.getIdentifierAPI().find(template);

    // Checking permissions
    _checkPermissions(existingHTMLPage, parentFolder, user, httpReq);

    // parent identifier for this file
    Identifier identifier = null;
    if (UtilMethods.isSet(existingHTMLPage.getInode()))
      identifier = APILocator.getIdentifierAPI().find(existingHTMLPage);

    // Creating the new page
    HTMLPage newHtmlPage = new HTMLPage();
    req.setAttribute(WebKeys.HTMLPAGE_FORM_EDIT, newHtmlPage);
    BeanUtils.copyProperties(newHtmlPage, form);
    if (UtilMethods.isSet(newHtmlPage.getFriendlyName())) {
      newHtmlPage.setFriendlyName(newHtmlPage.getFriendlyName());
    } else {
      newHtmlPage.setFriendlyName(newHtmlPage.getTitle());
    }
    // add VELOCITY_PAGE_EXTENSION to the pagename
    if (!newHtmlPage.getPageUrl().endsWith("." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION"))) {
      newHtmlPage.setPageUrl(newHtmlPage.getPageUrl() + "." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION"));
    }

    // 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 = APILocator.getIdentifierAPI().find(host, newHtmlPage.getURI(parentFolder));

    // if this is a new htmlpage and there is already an identifier with
    // this uri, return
    if (!InodeUtils.isSet(existingHTMLPage.getInode()) && InodeUtils.isSet(testIdentifier.getInode())) {
      existingHTMLPage.setParent(parentFolder.getInode());
      SessionMessages.add(httpReq, "error", "message.htmlpage.error.htmlpage.exists");
      throw new ActionException("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 (InodeUtils.isSet(existingHTMLPage.getInode()) && (!testIdentifier.getInode().equalsIgnoreCase(identifier.getInode()))
        && InodeUtils.isSet(testIdentifier.getInode())) {
      SessionMessages.add(httpReq, "error", "message.htmlpage.error.htmlpage.exists");
      // when there is an error saving should unlock working asset
      WebAssetFactory.unLockAsset(existingHTMLPage);
      throw new ActionException("Another page with the same page url exists in this folder");
    }

    if (UtilMethods.isSet(template)) {
      newHtmlPage.setTemplateId(templateIdentifier.getInode());
    }

    HTMLPage workingAsset = null;
    // Versioning
    if (InodeUtils.isSet(existingHTMLPage.getInode())) {
      // Creation the version asset
      WebAssetFactory.createAsset(newHtmlPage, user.getUserId(), parentFolder, identifier, false);
      HibernateUtil.flush();

      LiveCache.removeAssetFromCache(existingHTMLPage);
      workingAsset = (HTMLPage) WebAssetFactory.saveAsset(newHtmlPage, identifier);

      // if we need to update the identifier
      if (InodeUtils.isSet(parentFolder.getInode()) && !workingAsset.getURI(parentFolder).equals(identifier.getURI())) {

        // assets cache
        LiveCache.removeAssetFromCache(newHtmlPage);
        LiveCache.removeAssetFromCache(existingHTMLPage);
        LiveCache.clearCache(host.getIdentifier());
        WorkingCache.removeAssetFromCache(newHtmlPage);
        CacheLocator.getIdentifierCache().removeFromCacheByVersionable(newHtmlPage);

        CacheLocator.getIdentifierCache().removeFromCacheByVersionable(existingHTMLPage);

        APILocator.getIdentifierAPI().updateIdentifierURI(workingAsset, parentFolder);

      }

      CacheLocator.getHTMLPageCache().remove(workingAsset);

    } // Creating the new page
    else {
      WebAssetFactory.createAsset(newHtmlPage, user.getUserId(), parentFolder);
      workingAsset = newHtmlPage;
    }

    HibernateUtil.flush();
    HibernateUtil.getSession().refresh(workingAsset);

    if (RefreshMenus.shouldRefreshMenus(workingAsset)) {
      RefreshMenus.deleteMenu(workingAsset);
      if(identifier!=null)
          CacheLocator.getNavToolCache().removeNavByPath(identifier.getHostId(), identifier.getParentPath());
    }

    // Setting the new working page to publish tasks
    req.setAttribute(WebKeys.HTMLPAGE_FORM_EDIT, workingAsset);
    String this_page = workingAsset.getURI(parentFolder);
    req.setAttribute(WebKeys.HTMLPAGE_REFERER, this_page);
   
    ActivityLogger.logInfo(this.getClass(), "save HTMLpage action", "User " + user.getPrimaryKey() + " save page " + workingAsset.getTitle(), HostUtil.hostNameUtil(req, _getUser(req)));

  }
View Full Code Here

    // wraps request to get session object
    ActionRequestImpl reqImpl = (ActionRequestImpl) req;
    HttpServletRequest httpReq = reqImpl.getHttpServletRequest();

    // gets the current template being edited from the request object
    HTMLPage currentHTMLPage = (HTMLPage) req.getAttribute(WebKeys.HTMLPAGE_EDIT);

    // gets folder parent
    String parentInode = req.getParameter("parent");
    Folder parent = null;
    if (parentInode != null && parentInode.length() != 0 && !parentInode.equalsIgnoreCase("")) {
      // the parent is being passed through the request
      parent = (Folder) InodeFactory.getInode(parentInode, Folder.class);
      Logger.debug(this, "Parent Folder=" + parent.getInode());
    } else {
      parent = APILocator.getFolderAPI().findParentFolder(currentHTMLPage, user, false);

      Logger.debug(this, "Parent Folder=" + parent.getInode());
    }

    // Checking permissions
    _checkCopyAndMovePermissions(currentHTMLPage, parent, user, httpReq, "copy");

    HTMLPageFactory.copyHTMLPage(currentHTMLPage, parent);

    ActivityLogger.logInfo(this.getClass(), "copy HTMLpage action", "User " + user.getPrimaryKey() + " copying page" + currentHTMLPage.getTitle(), HostUtil.hostNameUtil(req, _getUser(req)));

    SessionMessages.add(httpReq, "message", "message.htmlpage.copy");
  }
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

        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().findWorkingVersion(id, APILocator.getUserAPI().getSystemUser(),false);
  }
View Full Code Here

    private static boolean moveHTMLPage ( HTMLPage currentHTMLPage, Folder parent, Host host, User user ) throws DotStateException, DotDataException, DotSecurityException {

        Identifier identifier = APILocator.getIdentifierAPI().find( currentHTMLPage );

        //gets working container
        HTMLPage workingWebAsset = (HTMLPage) APILocator.getVersionableAPI().findWorkingVersion( identifier, APILocator.getUserAPI().getSystemUser(), false );
        //gets live container
        HTMLPage liveWebAsset = (HTMLPage) APILocator.getVersionableAPI().findLiveVersion( identifier, APILocator.getUserAPI().getSystemUser(), false );

        Boolean existPageName;
        if ( parent != null ) {
            existPageName = HTMLPageFactory.existsPageName( parent, workingWebAsset.getPageUrl() );
        } else {
            existPageName = HTMLPageFactory.existsPageName( host, workingWebAsset.getPageUrl() );
        }
        if ( existPageName ) {
            return false;
        }

        //Getting the current parent folder of the HTMLPage
        Folder oldParent = APILocator.getFolderAPI().findParentFolder( workingWebAsset, APILocator.getUserAPI().getSystemUser(), false );
        Host oldParentHost = hostAPI.findParentHost(workingWebAsset, APILocator.getUserAPI().getSystemUser(), false);

        //moving folders
        /*oldParent.deleteChild(workingWebAsset);
        if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
          oldParent.deleteChild(liveWebAsset);
        }

        //parent.addChild(workingWebAsset);
        if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
          parent.addChild(liveWebAsset);
        }*/

        //updating caches
        WorkingCache.removeAssetFromCache( workingWebAsset );
        CacheLocator.getIdentifierCache().removeFromCacheByVersionable( workingWebAsset );

        /*
         * This code is commented fix the task DOTCMS-6883
         * if ((liveWebAsset!=null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
          LiveCache.removeAssetFromCache(liveWebAsset);
        }*/

        if ( parent != null ) {

            User systemUser;
            Host newHost;
            try {
                systemUser = APILocator.getUserAPI().getSystemUser();
                newHost = hostAPI.findParentHost( parent, systemUser, false );
            } catch ( DotDataException e ) {
                Logger.error( HTMLPageFactory.class, e.getMessage(), e );
                throw new DotRuntimeException( e.getMessage(), e );
            } catch ( DotSecurityException e ) {
                Logger.error( HTMLPageFactory.class, e.getMessage(), e );
                throw new DotRuntimeException( e.getMessage(), e );
            }

            identifier.setHostId( newHost.getIdentifier() );
            identifier.setURI( workingWebAsset.getURI( parent ) );
        } else {//Directly under the host
            identifier.setHostId( host.getIdentifier() );
            identifier.setURI( '/' + currentHTMLPage.getPageUrl() );
        }

        //HibernateUtil.saveOrUpdate(identifier);
        APILocator.getIdentifierAPI().save( identifier );
       
        //Add to Preview and Live Cache
        if ( (liveWebAsset != null) && (InodeUtils.isSet( liveWebAsset.getInode() )) ) {
            LiveCache.removeAssetFromCache( liveWebAsset );
            LiveCache.addToLiveAssetToCache( liveWebAsset );
        }
        WorkingCache.removeAssetFromCache( workingWebAsset );
        WorkingCache.addToWorkingAssetToCache( workingWebAsset );
        CacheLocator.getIdentifierCache().removeFromCacheByVersionable( workingWebAsset );

        //republishes the page to reset the VTL_SERVLETURI variable
        if ( (liveWebAsset != null) && (InodeUtils.isSet( liveWebAsset.getInode() )) ) {
            PageServices.invalidate( liveWebAsset );
        }

        //Wipe out menues
        //RefreshMenus.deleteMenus();
        if ( parent != null ) {
          if(oldParent!=null) {
            RefreshMenus.deleteMenu(oldParent);
          } else if(oldParentHost!=null) {
            RefreshMenus.deleteMenu(oldParentHost);
          }
         
            RefreshMenus.deleteMenu(parent );
            CacheLocator.getNavToolCache().removeNav(parent.getHostId(), parent.getInode());
        } else if(oldParent != null ){
            RefreshMenus.deleteMenu( oldParent );
        } else if(oldParentHost != null) {
          RefreshMenus.deleteMenu(oldParentHost);
        }
       
        if(oldParent!=null)
          CacheLocator.getNavToolCache().removeNav(oldParent.getHostId(), oldParent.getInode());

        if(APILocator.getPermissionAPI().isInheritingPermissions(workingWebAsset))
            APILocator.getPermissionAPI().removePermissions(workingWebAsset);

        /*
         And finally if everything is ok lets update the html page, as we are moving the page
         the mod date should change, this will avoid cache problems specially Push Publishing cache problems.
          */
        if ( (liveWebAsset != null) && (InodeUtils.isSet( liveWebAsset.getInode() )) ) {
            //Update the live version
            liveWebAsset.setModDate( new Date() );
            liveWebAsset.setModUser( user.getUserId() );
            HibernateUtil.saveOrUpdate( liveWebAsset );
        }
        //Update the working version
        workingWebAsset.setModDate( new Date() );
        workingWebAsset.setModUser( user.getUserId() );
View Full Code Here

            Identifier id = APILocator.getIdentifierAPI().find( currentHTMLPage );
            currentHTMLPage = (HTMLPage) APILocator.getVersionableAPI().findWorkingVersion( id, APILocator.getUserAPI().getSystemUser(), false );
        }

        //gets the new information for the template from the request object
        HTMLPage newHTMLPage = new HTMLPage();
        //Copy the current page
        newHTMLPage.copy( currentHTMLPage );

        //gets page url before extension
        String pageURL = com.dotmarketing.util.UtilMethods.getFileName( currentHTMLPage.getPageUrl() );
        //gets file extension
        String fileExtension = com.dotmarketing.util.UtilMethods.getFileExtension( currentHTMLPage.getPageUrl() );

        Boolean existPageName;
        if ( parent != null ) {
            existPageName = HTMLPageFactory.existsPageName( parent, pageURL + "." + fileExtension );
        } else {
            existPageName = HTMLPageFactory.existsPageName( host, pageURL + "." + fileExtension );
        }

        boolean isCopy = false;
        if ( existPageName ) {
            pageURL = pageURL + "_copy";
            isCopy = true;
        }

        newHTMLPage.setPageUrl( pageURL + "." + fileExtension );

        if ( isCopy )
            newHTMLPage.setFriendlyName( currentHTMLPage.getFriendlyName() + " (COPY)" );

        //gets current template from html page and attach it to the new page
        Template currentTemplate = HTMLPageFactory.getHTMLPageTemplate( currentHTMLPage );
        newHTMLPage.setTemplateId( currentTemplate.getIdentifier() );

        //persists the webasset
        HibernateUtil.saveOrUpdate( newHTMLPage );

        //Add the new page to the folder
        //parent.addChild(newHTMLPage);

        //creates new identifier for this webasset and persists it
        Identifier newIdent;
        if ( parent != null ) {
            newIdent = APILocator.getIdentifierAPI().createNew( newHTMLPage, parent );
        } else {
            newIdent = APILocator.getIdentifierAPI().createNew( newHTMLPage, host );
        }
        newHTMLPage.setIdentifier( newIdent.getId() );
        HibernateUtil.saveOrUpdate( newHTMLPage );

        WorkingCache.removeAssetFromCache( newHTMLPage );
        WorkingCache.addToWorkingAssetToCache( newHTMLPage );
        LiveCache.removeAssetFromCache( newHTMLPage );
View Full Code Here

     
      // removing both old and new parent
      CacheLocator.getNavToolCache().removeNavByPath(ident.getHostId(), ident.getParentPath());
      CacheLocator.getNavToolCache().removeNav(folder.getHostId(), folder.getInode());

      HTMLPage tempPage = new HTMLPage();
      tempPage.copy(page);
      // sets filename for this new file
     
      String newNamePage = newName + "." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
     
      tempPage.setPageUrl(newNamePage);
      tempPage.setFriendlyName(newNamePage);

      Identifier testIdentifier = APILocator.getIdentifierAPI().find(host, tempPage.getURI(folder));

      if(InodeUtils.isSet(testIdentifier.getInode()) || page.isLocked())
        return false;

      List<Versionable> versions = APILocator.getVersionableAPI().findAllVersions(ident);
     
      boolean islive = false;
      HTMLPage workingVersion = null;
     
      for (Versionable version : versions) {
            HTMLPage htmlpage = (HTMLPage)version;
        // sets filename for this new file
            htmlpage.setPageUrl(newNamePage);
            htmlpage.setFriendlyName(newNamePage);

         
        HibernateUtil.saveOrUpdate(htmlpage);
        if (htmlpage.isLive())
          islive = true;
        if (htmlpage.isWorking())
          workingVersion = htmlpage;
      }
     
       LiveCache.removeAssetFromCache(workingVersion);
       WorkingCache.removeAssetFromCache(workingVersion);
View Full Code Here

   
    if(cfform.getModDate() == null)
      cfform.setModDate(new java.util.Date());
     
    //add the html page to the Communication
    HTMLPage page = (HTMLPage) InodeFactory.getChildOfClass(c, HTMLPage.class);
    if (InodeUtils.isSet(page.getIdentifier())) {
      cfform.setHtmlPage(page.getIdentifier());
    }
   
    VirtualLink vl = (VirtualLink) InodeFactory.getChildOfClass(c, VirtualLink.class);
    if (InodeUtils.isSet(vl.getInode())) {
      cfform.setTrackBackLinkInode(vl.getInode());
View Full Code Here

      throw new ActionException(dhe.getMessage());
    }

   
    // wipe the old HTML page entries
    HTMLPage page = (HTMLPage) InodeFactory.getChildOfClass(c, HTMLPage.class);
    if (InodeUtils.isSet(page.getInode()))
      c.deleteChild(page);
   
    if (req.getParameter("typeContent").equals("HTMLPage")) {
      //try to get the Communication's page
      if (InodeUtils.isSet(cfform.getHtmlPage())) {
        page = (HTMLPage) InodeFactory.getInode(String.valueOf(cfform.getHtmlPage()), HTMLPage.class);
        if (InodeUtils.isSet(page.getInode())) {
          c.addChild(page);
          c.setHtmlPage(page.getIdentifier());
        }
      }
    }
   
    // wipe the old VirtualLink entries
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.