Package com.dotmarketing.business

Examples of com.dotmarketing.business.VersionableAPI


        if (arg0.endsWith(VELOCITY_CONTAINER_EXTENSION)) {

            try {
                //Integer.parseInt(x);
                Identifier identifier = APILocator.getIdentifierAPI().find(x);
                VersionableAPI versionableAPI=APILocator.getVersionableAPI();
                Container container = null;
                if (preview) {
                  container=(Container)versionableAPI.findWorkingVersion(identifier, user, true);
                } else {
                  container=(Container)versionableAPI.findLiveVersion(identifier, user, true);
                }

                Logger.debug(this,"DotResourceLoader:\tWriting out container inode = " + container.getInode());

                result = ContainerServices.buildVelocity(container, identifier, preview);
            } catch (NumberFormatException e) {
              CacheLocator.getVeloctyResourceCache().addMiss(arg0);
                Logger.warn(this,"getResourceStream: Invalid resource path provided = " + arg0 + ", request discarded.");
                try {
            return new ByteArrayInputStream("".getBytes("UTF-8"));
          } catch (UnsupportedEncodingException e1) {
            Logger.error(DotResourceLoader.class,e1.getMessage(),e1);
          }
            }
        }else if (arg0.endsWith(VELOCITY_CONTENT_EXTENSION)) {
            String language = "";
            if (x.indexOf("_") > -1) {
                Logger.debug(this,"x=" + x);
                language = x.substring(x.indexOf("_") + 1, x.length());
                Logger.debug(this,"language=" + language);
                x = x.substring(0, x.indexOf("_"));
                Logger.debug(this,"x=" + x);
            }
            try {
                //Integer.parseInt(x);
                //Identifier identifier = (Identifier) InodeFactory.getInode(x, Identifier.class);
              Identifier identifier = APILocator.getIdentifierAPI().find(x);
                Contentlet contentlet = null;
                if(CacheLocator.getVeloctyResourceCache().isMiss(arg0)){
                  if(LanguageWebAPI.canDefaultContentToDefaultLanguage()) {
                     LanguageAPI langAPI = APILocator.getLanguageAPI();
                     language = Long.toString(langAPI.getDefaultLanguage().getId());
                  } else {
                    throw new ResourceNotFoundException("Contentlet is a miss in the cache");
                  }
              }
               
                try {
                  contentlet = conAPI.findContentletByIdentifier(identifier.getInode(), !preview,new Long(language) , APILocator.getUserAPI().getSystemUser(), true);
                } catch (DotContentletStateException e) {
                    contentlet = null;
                }
               
                if(contentlet == null || !InodeUtils.isSet(contentlet.getInode()) || contentlet.isArchived()){
                   
                    LanguageAPI langAPI = APILocator.getLanguageAPI();
                    long lid = langAPI.getDefaultLanguage().getId();
                    if(lid!=Long.parseLong(language)) {
                        Contentlet cc = conAPI.findContentletByIdentifier(identifier.getInode(), !preview,lid , APILocator.getUserAPI().getSystemUser(), true);
                        if(cc!=null && UtilMethods.isSet(cc.getInode())
                                 && !cc.isArchived() && LanguageWebAPI.canApplyToAllLanguages(cc)) {
                            contentlet = cc;
                        } else {
                            CacheLocator.getVeloctyResourceCache().addMiss(arg0);
                            throw new ResourceNotFoundException("Contentlet is a miss in the cache");
                        }
                    }
                }

                Logger.debug(this,"DotResourceLoader:\tWriting out contentlet inode = " + contentlet.getInode());

                result = ContentletServices.buildVelocity(contentlet, identifier, preview);
            } catch (NumberFormatException e) {
                Logger.warn(this,"getResourceStream: Invalid resource path provided = " + arg0 + ", request discarded.");
                try {
            return new ByteArrayInputStream("".getBytes("UTF-8"));
          } catch (UnsupportedEncodingException e1) {
            Logger.error(DotResourceLoader.class,e1.getMessage(),e1);
          }
            } catch (DotContentletStateException e) {
              CacheLocator.getVeloctyResourceCache().addMiss(arg0);
                Logger.debug(this,"getResourceStream: Invalid resource path provided = " + arg0 + ", request discarded.");
                try {
            return new ByteArrayInputStream("".getBytes("UTF-8"));
          } catch (UnsupportedEncodingException e1) {
            Logger.error(DotResourceLoader.class,e1.getMessage(),e1);
          }
            }
        }else if (arg0.endsWith(VELOCITY_FIELD_EXTENSION)) {
          //long contentletInode;
          //long fieldInode;
          if (x.indexOf("_") > -1) {
            String fieldID = x.substring(x.indexOf("_") + 1, x.length());
            String conInode = x.substring(0,x.indexOf("_"));
            //contentletInode = Integer.parseInt(conInode);
            //fieldInode = Integer.parseInt(fieldID);
            result = FieldServices.buildVelocity(fieldID, conInode, preview);
          }

        }else if (arg0.endsWith(VELOCITY_CONTENT_MAP_EXTENSION)) {
            try {
              String language = "";
              if (x.indexOf("_") > -1) {
                  Logger.debug(this,"x=" + x);
                  language = x.substring(x.indexOf("_") + 1, x.length());
                  Logger.debug(this,"language=" + language);
                  x = x.substring(0, x.indexOf("_"));
                  Logger.debug(this,"x=" + x);
              }

              Contentlet contentlet = null;
              if(CacheLocator.getVeloctyResourceCache().isMiss(arg0)){
                throw new ResourceNotFoundException("Contentlet is a miss in the cache");
              }
             
              try {
                  contentlet = conAPI.findContentletByIdentifier(new String(x), !preview,new Long(language) , APILocator.getUserAPI().getSystemUser(), true);
              }
              catch(Exception ex) {
                  contentlet = null;
              }
             
              if(contentlet == null || !InodeUtils.isSet(contentlet.getInode())){
                  CacheLocator.getVeloctyResourceCache().addMiss(arg0);
                  throw new ResourceNotFoundException("Contentlet is a miss in the cache");
                }

              Logger.debug(this,"DotResourceLoader:\tWriting out contentlet inode = " + contentlet.getInode());

              result = ContentletMapServices.buildVelocity(contentlet, preview);
            } catch (DotContentletStateException e) {
              CacheLocator.getVeloctyResourceCache().addMiss(arg0);
                Logger.debug(this,"getResourceStream: Invalid resource path provided = " + arg0 + ", request discarded.");
                try {
            return new ByteArrayInputStream("".getBytes("UTF-8"));
          } catch (UnsupportedEncodingException e1) {
            Logger.error(DotResourceLoader.class,e1.getMessage(),e1);
          }
            }
        }else if (arg0.endsWith(VELOCITY_HTMLPAGE_EXTENSION)) {
            try {
                //Integer.parseInt(x);
                //Identifier identifier = (Identifier) InodeFactory.getInode(x, Identifier.class);
              Identifier identifier = APILocator.getIdentifierAPI().find(x);
              VersionableAPI versionableAPI=APILocator.getVersionableAPI();
                HTMLPage page = null;
                if (preview) {
                  page=(HTMLPage) versionableAPI.findWorkingVersion(identifier, user, true);
                } else {
                  page=(HTMLPage) versionableAPI.findLiveVersion(identifier, user, true);
                }

                Logger.debug(this,"DotResourceLoader:\tWriting out HTMLpage inode = " + page.getInode());

                if (!InodeUtils.isSet(page.getInode())) {
                    throw new ResourceNotFoundException("Page " + arg0 + "not found error 404");
                } else {
                  result = PageServices.buildStream(page, preview);
                }
            } catch (NumberFormatException e) {
                Logger.warn(this,"getResourceStream: Invalid resource path provided = " + arg0 + ", request discarded.");
                throw new ResourceNotFoundException("Invalid resource path provided = " + arg0);
            }
        }else if (arg0.endsWith(VELOCITY_HOST_EXTENSION)) {

                //Integer.parseInt(x)

                Host host= APILocator.getHostAPI().find(x, APILocator.getUserAPI().getSystemUser(), false);

                 if (!InodeUtils.isSet(host.getInode()))
                Logger.debug(this,"host not found");
                 else
                  result = HostServices.buildStream(host, preview);


        }else if (arg0.endsWith(VELOCITY_TEMPLATE_EXTENSION)) {
            try {
                //Integer.parseInt(x);
                //Identifier identifier = (Identifier) InodeFactory.getInode(x, Identifier.class);
              Identifier identifier = APILocator.getIdentifierAPI().find(x);
              VersionableAPI versionableAPI=APILocator.getVersionableAPI();
                Template template = null;
                if (preview) {
                  template = (Template) versionableAPI.findWorkingVersion(identifier, user, true);
                } else {
                  template = (Template) versionableAPI.findLiveVersion(identifier, user, true);
                }

                Logger.debug(this,"DotResourceLoader:\tWriting out Template inode = " + template.getInode());

                result = TemplateServices.buildVelocity(template, preview);
View Full Code Here


      String htmlpage_inode = (String) contentletFormData.get("htmlpage_inode");
      String contentcontainer_inode = (String) contentletFormData.get("contentcontainer_inode");

      final IdentifierAPI identifierAPI = APILocator.getIdentifierAPI();
      final VersionableAPI versionableAPI = APILocator.getVersionableAPI();

      Identifier htmlParentId = identifierAPI.findFromInode(htmlpage_inode);
      HTMLPage htmlParent = (HTMLPage) versionableAPI.findWorkingVersion(htmlParentId, user, false);
      Logger.debug(this, "Added Contentlet to parent=" + htmlParent.getInode());

      Identifier containerParentId = null;
      Container containerParent = null;
      try{
        containerParentId =  identifierAPI.findFromInode(contentcontainer_inode);
        containerParent = (Container) versionableAPI.findWorkingVersion(containerParentId, user, false);
      }
      catch(Exception e){
        if(e instanceof DotSecurityException){
          SessionMessages.add(req, "message", "User needs 'View' Permissions on container");
          throw new DotSecurityException("User have no View Permissions on container");
View Full Code Here

TOP

Related Classes of com.dotmarketing.business.VersionableAPI

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.