Package com.dotmarketing.portlets.templates.model

Examples of com.dotmarketing.portlets.templates.model.Template


        //Create a template
        String body = "<html><body> #parseContainer('" + container.getIdentifier() + "') </body></html>";
        String title = "empty test template " + UUIDGenerator.generateUuid();

        Template template = new Template();
        template.setTitle( title );
        template.setBody( body );

        template = APILocator.getTemplateAPI().saveTemplate( template, defaultHost, user, false );

        //Create the html page
        String pageUrl = "testpage_" + new Date().getTime() + "." + pageExt;
View Full Code Here


    // Gets roles
    try {
      List<WebAsset> templates = WebAssetFactory.getAssetsWorkingWithPermission(Template.class, 100000, 0, "title", null, user);
     
      Iterator<WebAsset> templatesIter = templates.iterator();
      Template template;
     
      if (host == null) {
        while (templatesIter.hasNext()) {
          template = (Template) templatesIter.next();
          result.add(template);
        }
      } else {
        Identifier identifier;
        Host systemHost = hostAPI.findSystemHost(user, false);
       
        while (templatesIter.hasNext()) {
          template = (Template) templatesIter.next();
          identifier = identifierAPI.findFromInode(template.getIdentifier());
          if (identifier.getHostId().equals(host.getIdentifier()) || !UtilMethods.isSet(identifier.getHostId()) || ((systemHost != null) && identifier.getHostId().equals(systemHost.getIdentifier()))) {
            result.add(template);
          }
        }
      }
View Full Code Here

    else
        return APILocator.getTemplateAPI().findLiveTemplate(page.getTemplateId(), APILocator.getUserAPI().getSystemUser(), false);
  }

  public static Template getWorkingNotLiveHTMLPageTemplate(HTMLPage page) throws DotDataException, DotStateException, DotSecurityException{
    Template t = getHTMLPageTemplate(page,true);
    if(t.isLive())
        return null;
    else
        return t;
  }
View Full Code Here

        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
View Full Code Here

      if (cmd!=null && cmd.equals("editTemplate")) {

        Logger.debug(DirectorAction.class, "Director :: editTemplate");

        HTMLPage htmlPage = new HTMLPage();
        WebAsset workingTemplate = new Template();
        if (req.getParameter("htmlPage")!=null) {
          htmlPage = (HTMLPage) InodeFactory.getInode(req.getParameter("htmlPage"), HTMLPage.class);
          workingTemplate = HTMLPageFactory.getHTMLPageTemplate(htmlPage, true);
        } else if (req.getParameter("template")!=null) {
          workingTemplate = (Template) InodeFactory.getInode(req.getParameter("template"), Template.class);
        }

        if ("unlockTemplate".equals(subcmd)) {
          WebAssetFactory.unLockAsset(workingTemplate);
        }

        if (workingTemplate.isLocked() && !workingTemplate.getModUser().equals(user.getUserId())) {
          req.setAttribute(WebKeys.HTMLPAGE_EDIT, htmlPage);
          req.setAttribute(WebKeys.TEMPLATE_EDIT, workingTemplate);
          setForward(req,"portlet.ext.director.unlock_template");
          return;
        }
        else if (workingTemplate.isLocked()) {
          //it's locked by the same user
          WebAssetFactory.unLockAsset(workingTemplate);
        }

        java.util.Map params = new java.util.HashMap();
        params.put("struts_action",new String[] {"/ext/templates/edit_template"});
        params.put("cmd",new String[] { "edit" });
        params.put("inode",new String[] { workingTemplate.getInode() + "" });
        params.put("referer",new String[] { referer });

        String af = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq,WindowState.MAXIMIZED.toString(),params);

        _sendToReferral(req, res, af);
View Full Code Here

  public HTMLPage copy(HTMLPage source, Folder destination, boolean forceOverwrite, boolean copyTemplateContainers,
      HTMLPageAPI.CopyMode copyMode, User user, boolean respectFrontendRoles) throws DotDataException,
      DotSecurityException {

    Template sourceTemplate = getHTMLPageTemplate(source);
    Template template;

    if (copyTemplateContainers) {
      Host hostDestination = hostAPI.find(destination.getHostId(), user, respectFrontendRoles);
      template = templateAPI.copy(sourceTemplate, hostDestination, false, true, user, respectFrontendRoles);
    } else {
View Full Code Here

      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);
     
View Full Code Here

    StringBuffer query = new StringBuffer();
    query.append("select asset from asset in class " + HTMLPage.class.getName() + ", " +
        "inode in class " + Inode.class.getName()+", identifier in class " + Identifier.class.getName() +
         ", htmlvi in class "+HTMLPageVersionInfo.class.getName());
    if(UtilMethods.isSet(parent)){
      if(APILocator.getIdentifierAPI().find(parent).getAssetType().equals(new Template().getType()))
        query.append(" where asset.inode = inode.inode and asset.identifier = identifier.id and asset.templateId = '"+parent+"' ");
      else
        query.append(" ,tree in class " + Tree.class.getName() + " where asset.inode = inode.inode " +
              "and asset.identifier = identifier.id and tree.parent = '"+parent+"' and tree.child=asset.inode");
    }else{
View Full Code Here

    HibernateUtil.startTransaction();

    User user = _getUser(req);
   
    // Old template used to compare against edited version
    Template oldTemplate = new Template();
    try {
      Logger.debug(this, "Calling Retrieve method");
      _retrieveWebAsset(req, res, config, form, user, Template.class,
          WebKeys.TEMPLATE_EDIT);

    } catch (Exception ae) {
      _handleException(ae, req);
      return;
    }

    /*
     * We are editing the Template
     */
    if ((cmd != null) && cmd.equals(Constants.EDIT)) {
      try {
        Logger.debug(this, "Calling Edit method");
        _editWebAsset(req, res, config, form, user);
      } catch (Exception ae) {
        if ((referer != null) && (referer.length() != 0)) {
          if (ae.getMessage()!=null && ae.getMessage().equals(WebKeys.EDIT_ASSET_EXCEPTION)) {
            //The web asset edit threw an exception because it's
            // locked so it should redirect back with message
            java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
            params.put("struts_action",new String[] { "/ext/director/direct" });
            params.put("cmd", new String[] { "editTemplate" });
            params.put("template", new String[] { req.getParameter("inode") });
            params.put("referer", new String[] { URLEncoder.encode(referer, "UTF-8") });

            String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);

            _sendToReferral(req, res, directorURL);
            return;
          }
        }
        _handleException(ae, req);
      }
    }

    // *********************** BEGIN GRAZIANO issue-12-dnd-template
    /*
     * We are drawing the Template. In this case we call the _editWebAsset method but in the Template model creation we add the drawed property.
     */
    if ((cmd != null) && cmd.equals(Constants.DESIGN)) {
      try {
        Logger.debug(this, "Calling Design method");
        _editWebAsset(req, res, config, form, user);

      } catch (Exception ae) {
        if ((referer != null) && (referer.length() != 0)) {
          if (ae.getMessage().equals(WebKeys.EDIT_ASSET_EXCEPTION)) {
            //The web asset edit threw an exception because it's
            // locked so it should redirect back with message
            java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
            params.put("struts_action",new String[] { "/ext/director/direct" });
            params.put("cmd", new String[] { "editTemplate" });
            params.put("template", new String[] { req.getParameter("inode") });
            params.put("referer", new String[] { URLEncoder.encode(referer, "UTF-8") });

            String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);

            _sendToReferral(req, res, directorURL);
            return;
          }
        }
        _handleException(ae, req);
      }
    }

    if ((cmd != null) && cmd.equals(Constants.ADD_DESIGN)) {
      try {
        if (Validator.validate(req, form, mapping)) {
          Logger.debug(this, "Calling Save method for design template");
          Logger.debug(this, "Calling Save method");
          // the old template before editing using the inode from el request
          oldTemplate = APILocator.getTemplateAPI().find(req.getParameter("inode"), user, false);
          _saveWebAsset(req, res, config, form, user);
          String subcmd = req.getParameter("subcmd");
          if ((subcmd != null) && subcmd.equals(com.dotmarketing.util.Constants.PUBLISH)) {
            Logger.debug(this, "Calling Publish method");
            _publishWebAsset(req, res, config, form, user, WebKeys.TEMPLATE_FORM_EDIT);
            if(!UtilMethods.isSet(referer)) {
              java.util.Map<String, String[]> params = new java.util.HashMap<String, String[]>();
              params.put("struts_action",new String[] {"/ext/templates/view_templates"});
              referer = PortletURLUtil.getActionURL(req,WindowState.MAXIMIZED.toString(),params);
            }
            // edited template from the form
            Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_FORM_EDIT);
            // call for invalidation on the live cache if the theme changed
            if(template.isDrawed() && !template.getTheme().equals(oldTemplate.getTheme())){
              APILocator.getTemplateAPI().invalidateTemplatePages(template.getInode(), user, false, false);
            }
          }
          try{
                        _sendToReferral(req, res, referer);
                        return;
                    }
                    catch(Exception e){
                        java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
                        params.put("struts_action",new String[] { "/ext/templates/view_templates" });
                        String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);
                        _sendToReferral(req, res, directorURL);
                        return;
                    }
        }
      } catch (Exception ae) {
        _handleException(ae, req);
      }
    }
    // *********************** END GRAZIANO issue-12-dnd-template

    /*
     * If we are updating the Template, copy the information
     * from the struts bean to the hbm inode and run the
     * update action and return to the list
     */
    if ((cmd != null) && cmd.equals(Constants.ADD)) {
      try {

        if (Validator.validate(req, form, mapping)) {

          Logger.debug(this, "Calling Save method");
          // the old template before editing using the inode from el request
          oldTemplate = APILocator.getTemplateAPI().find(req.getParameter("inode"), user, false);
          _saveWebAsset(req, res, config, form, user);
          String subcmd = req.getParameter("subcmd");

          if ((subcmd != null) && subcmd.equals(com.dotmarketing.util.Constants.PUBLISH)) {
            Logger.debug(this, "Calling Publish method");
            _publishWebAsset(req, res, config, form, user,
                WebKeys.TEMPLATE_FORM_EDIT);



          if(!UtilMethods.isSet(referer)) {
            java.util.Map<String, String[]> params = new java.util.HashMap<String, String[]>();
            params.put("struts_action",new String[] {"/ext/templates/view_templates"});
            referer = PortletURLUtil.getActionURL(req,WindowState.MAXIMIZED.toString(),params);
          }
          // edited template from the form
          Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_FORM_EDIT);
          // call for invalidation on the live cache if the theme changed
          if(template.isDrawed() && !template.getTheme().equals(oldTemplate.getTheme())){
            APILocator.getTemplateAPI().invalidateTemplatePages(template.getInode(), user, false, false);
          }


        }

                    try{


                        _sendToReferral(req, res, referer);
                        return;
                    }
                    catch(Exception e){
                        java.util.Map<String,String[]> params = new java.util.HashMap<String,String[]>();
                        params.put("struts_action",new String[] { "/ext/templates/view_templates" });
                        String directorURL = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, WindowState.MAXIMIZED.toString(), params);
                        _sendToReferral(req, res, directorURL);
                        return;

                    }


        }
      } catch (Exception ae) {
        _handleException(ae, req);
      }

    }
    /*
     * If we are deleteing the Template,
     * run the delete action and return to the list
     *
     */
    else if ((cmd != null) && cmd.equals(Constants.DELETE)) {
      try {
        Logger.debug(this, "Calling Delete method");
        _deleteWebAsset(req, res, config, form, user,
            WebKeys.TEMPLATE_EDIT);

      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);
    }
    else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.FULL_DELETE))
    {
      try
      {
        Logger.debug(this,"Calling Full Delete Method");
        WebAsset webAsset = (WebAsset) req.getAttribute(WebKeys.TEMPLATE_EDIT);
        if(WebAssetFactory.deleteAsset(webAsset,user)) {
          SessionMessages.add(httpReq, "message", "message." + webAsset.getType() + ".full_delete");
        } else {
          SessionMessages.add(httpReq, "error", "message." + webAsset.getType() + ".full_delete.error");
        }
      }
      catch(Exception ae)
      {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);
    }
    else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.FULL_DELETE_LIST))
    {
      try
      {
        Logger.debug(this,"Calling Full Delete Method");
        String [] inodes = req.getParameterValues("publishInode");
        StringBuilder dependencies = new StringBuilder();
        boolean returnValue = false;

        for(String inode  : inodes)  {
          String result = APILocator.getTemplateAPI().checkDependencies(inode, user, false);

          WebAsset webAsset = (WebAsset) InodeFactory.getInode(inode,Template.class);

          if(UtilMethods.isSet(result)) {
            dependencies.append(LanguageUtil.get(user, "template-name")).append(": ").append(webAsset.getFriendlyName()).append("\n");
            dependencies.append(LanguageUtil.get(user, "Pages-URLs")).append(": ").append(result);
          } else {
            returnValue = WebAssetFactory.deleteAsset(webAsset,user);
          }

          dependencies.append("\n");
        }

        if(returnValue)
        {
          SessionMessages.add(httpReq,"message","message.template.full_delete");
        }
        else
        {
          SessionMessages.add(httpReq,"error","message.template.full_delete.error");
          Logger.debug(this," Template cannot be deleted if it has existing relationships");
        }
      }
      catch(Exception ae)
      {
        SessionMessages.add(httpReq,"error","message.template.full_delete.error");
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);
    }
    /*
     * If we are undeleting the Template,
     * run the undelete action and return to the list
     *
     */
    else if ((cmd != null)
        && cmd.equals(com.dotmarketing.util.Constants.UNDELETE)) {
      try {
        Logger.debug(this, "Calling UnDelete method");
        _undeleteWebAsset(req, res, config, form, user,
            WebKeys.TEMPLATE_EDIT);

      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);

    }
    /*
     * If we are deleting the Template version,
     * run the deeleteversion action and return to the list
     */
    else if ((cmd != null)
        && cmd.equals(com.dotmarketing.util.Constants.DELETEVERSION)) {
      try {
        Logger.debug(this, "Calling Delete Version Method");
        _deleteVersionWebAsset(req, res, config, form, user,
            WebKeys.TEMPLATE_EDIT);

      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);
    }
    /*
     * If we are unpublishing the Template,
     * run the unpublish action and return to the list
     */
    else if ((cmd != null)
        && cmd.equals(com.dotmarketing.util.Constants.UNPUBLISH)) {
      try {
        Logger.debug(this, "Calling Unpublish Method");
        _unPublishWebAsset(req, res, config, form, user,
            WebKeys.TEMPLATE_EDIT);

      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);

    }
    /*
     * If we are getting the Template version back,
     * run the getversionback action and return to the list
     */
    else if ((cmd != null)
        && cmd.equals(com.dotmarketing.util.Constants.GETVERSIONBACK)) {
      try {
        Logger.debug(this, "Calling Get Version Back Method");
        _getVersionBackWebAsset(req, res, config, form, user);

      } catch (Exception ae) {
        _handleException(ae, req);
      }
      _sendToReferral(req, res, referer);
    }
    /*
     * If we are getting the Template versions,
     * run the assetversions action and return to the list
     */
    else if ((cmd != null)
        && cmd.equals(com.dotmarketing.util.Constants.ASSETVERSIONS)) {
      try {
        Logger.debug(this, "Calling Get Versions Method");
        _getVersionsWebAsset(req, res, config, form, user,
            WebKeys.TEMPLATE_EDIT, WebKeys.TEMPLATE_VERSIONS);

      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
    }
    /*
     * If we are unlocking the Template,
     * run the unlock action and return to the list
     */
    else if ((cmd != null)
        && cmd.equals(com.dotmarketing.util.Constants.UNLOCK)) {
      try {
        Logger.debug(this, "Calling Unlock Method");
        _unLockWebAsset(req, res, config, form, user,
            WebKeys.TEMPLATE_EDIT);

      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);

    }
    /*
     * If we are copying the Template,
     * run the copy action and return to the list
     */
    else if ((cmd != null)
        && cmd.equals(com.dotmarketing.util.Constants.COPY)) {
      try {
        Logger.debug(this, "Calling Copy Method");
        _copyWebAsset(req, res, config, form, user);
      } catch (Exception ae) {
        _handleException(ae, req);
      }
      _sendToReferral(req, res, referer);
    } else
      Logger.debug(this, "Unspecified Action");

    HibernateUtil.commitTransaction();

    _setupEditTemplatePage(reqImpl, res, config, form, user);

    // *********************** BEGIN GRAZIANO issue-12-dnd-template
    boolean isDrawed = req.getAttribute(WebKeys.TEMPLATE_IS_DRAWED)!=null?(Boolean)req.getAttribute(WebKeys.TEMPLATE_IS_DRAWED):false;

    // If we are into the design mode we are redirected at the new portlet action
    if(((null!=cmd) && cmd.equals(Constants.DESIGN))){
      req.setAttribute(WebKeys.OVERRIDE_DRAWED_TEMPLATE_BODY, false);
      setForward(req, "portlet.ext.templates.design_template");
    }else if(isDrawed){
      req.setAttribute(WebKeys.OVERRIDE_DRAWED_TEMPLATE_BODY, true);
      // create the javascript parameters for left side (Page Width, Layout ecc..) of design template
      Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_EDIT);
      TemplateLayout parameters = DesignTemplateUtil.getDesignParameters(template.getDrawedBody());
      req.setAttribute(WebKeys.TEMPLATE_JAVASCRIPT_PARAMETERS, parameters);
      setForward(req, "portlet.ext.templates.design_template");
    }else
      setForward(req, "portlet.ext.templates.edit_template");
    // *********************** END GRAZIANO issue-12-dnd-template   
View Full Code Here

  private void _setupEditTemplatePage(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user) throws Exception {

    //Getting the host that can be assigned to the container
    PermissionAPI perAPI = APILocator.getPermissionAPI();
    Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_EDIT);
        Host templateHost = hostAPI.findParentHost(template, user, false);

    //Getting the host that can be assigned to the template
    List<Host> hosts = APILocator.getHostAPI().findAll(user, false);
    hosts.remove(APILocator.getHostAPI().findSystemHost(user, false));
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.templates.model.Template

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.