Package com.dotmarketing.beans

Examples of com.dotmarketing.beans.Identifier


        sitemapIndex.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        sitemapIndex.append("<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd\">");

        for (Contentlet itemChild : itemsList) {
            if (itemChild.isWorking() && !itemChild.isArchived()) {
              Identifier identifier = APILocator.getIdentifierAPI().find(itemChild);
              sitemapIndex.append("<sitemap>");
              sitemapIndex.append("<loc>"+ XMLUtils.xmlEscape("http://"
                  + host.getHostname()
                  + UtilMethods.encodeURIComponent(identifier.getParentPath()+itemChild.getStringProperty(FileAssetAPI.FILE_NAME_FIELD)))
              + "</loc>");
              sitemapIndex.append("<lastmod>"+UtilMethods.dateToHTMLDate(itemChild.getModDate(), "yyyy-MM-dd")+"</lastmod>");
              sitemapIndex.append("</sitemap>");
            }
        }
View Full Code Here


   * </ul>
   */
  private void setLinkDependencies() {
    for(String linkId : linksSet) {
      try {
        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) {

          if(link.getLinkType().equals(Link.LinkType.INTERNAL.toString())) {
            Identifier id = APILocator.getIdentifierAPI().find(link.getInternalLinkIdentifier());

            // add file/content dependencies
            if (InodeUtils.isSet(id.getInode()) && id.getAssetType().equals("contentlet")) {
              List<Contentlet> contentList = APILocator.getContentletAPI().search("+identifier:"+id.getId(), 0, 0, "moddate", user, false);

              for (Contentlet contentlet : contentList) {
                contents.addOrClean(contentlet.getIdentifier(), contentlet.getModDate());
                contentsSet.add(contentlet.getIdentifier());
              }

            // add htmlpages dependencies
            } else if(InodeUtils.isSet(id.getInode()) && id.getAssetType().equals("htmlpage")) {
              HTMLPage page = APILocator.getHTMLPageAPI().loadLivePageById(id.getId(), user, false);

              if(page==null) {
                page = APILocator.getHTMLPageAPI().loadWorkingPageById(id.getId(), user, false);
              }

              htmlPages.addOrClean(id.getId(), page.getModDate());
              htmlPagesSet.add(id.getId());
            }
          }
        }

      } catch (Exception e) {
View Full Code Here

      IdentifierAPI idenAPI = APILocator.getIdentifierAPI();
      FolderAPI folderAPI = APILocator.getFolderAPI();
      List<Container> containerList = new ArrayList<Container>();

      for (String pageId : htmlPagesSet) {
        Identifier iden = idenAPI.find(pageId);

        // Host dependency
        Host h = APILocator.getHostAPI().find(iden.getHostId(), user, false);
        hosts.addOrClean( iden.getHostId(), h.getModDate());
        hostsSet.add(iden.getHostId());
        Folder folder = folderAPI.findFolderByPath(iden.getParentPath(), iden.getHostId(), user, false);
        folders.addOrClean( folder.getInode(), folder.getModDate());
        foldersSet.add(folder.getInode());
        HTMLPage workingPage = APILocator.getHTMLPageAPI().loadWorkingPageById(pageId, user, false);
        HTMLPage livePage = APILocator.getHTMLPageAPI().loadLivePageById(pageId, user, false);
View Full Code Here

            String value = "";
            if(UtilMethods.isSet(APILocator.getContentletAPI().getFieldValue(con, ff))){
              value = APILocator.getContentletAPI().getFieldValue(con, ff).toString();
            }
            //Identifier id = (Identifier) InodeFactory.getInode(value, Identifier.class);
            Identifier id = APILocator.getIdentifierAPI().find(value);
            if (InodeUtils.isSet(id.getInode()) && id.getAssetType().equals("contentlet")) {
              contentsWithDependenciesToProcess.addAll(
                  APILocator.getContentletAPI()
                  .search("+identifier:"+id.getId(), 0, 0, "moddate", user, false));
            }
          } catch (Exception ex) {
            Logger.debug(this, ex.toString());
            throw new DotStateException("Problem occured while publishing file");
          }
View Full Code Here

  public File getNewFile(){
    return new File();
  }
 
  public IFileAsset getFile(String identifier, boolean live){
    Identifier id;
    String p = null;
    try {
      id = APILocator.getIdentifierAPI().find(identifier);
        if(live){
        p = LiveCache.getPathFromCache(id.getURI(), id.getHostId());
        }else{
        p = WorkingCache.getPathFromCache(id.getURI(), id.getHostId());
        }
    } catch (Exception e1) {
      Logger.error(FileTool.class,e1.getMessage(),e1);
      return new File();
    }
        p = p.substring(5, p.lastIndexOf("."));
        IFileAsset file = null;
    try {
      if(id!=null && InodeUtils.isSet(id.getId()) && id.getAssetType().equals("contentlet")){
        Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(id.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), APILocator.getUserAPI().getSystemUser(), false);
        if(cont!=null && InodeUtils.isSet(cont.getInode())){
          file = APILocator.getFileAssetAPI().fromContentlet(cont);
        }
      }else{
        file = fileAPI.find(p, userAPI.getSystemUser(), false);
View Full Code Here

      }catch(DotDataException e){
        Logger.error(this, "Unable to look up comment with inode " + commentsOptions.get("contentInode"), e);
      }

      Structure contentletStructure = StructureCache.getStructureByInode(contentlet.getStructureInode());
      Identifier contentletIdentifier = APILocator.getIdentifierAPI().find(contentlet);

      /*make sure we have a structure in place before saving */
      CommentsWebAPI cAPI = new CommentsWebAPI();
      cAPI.validateComments(contentlet.getInode());

      Structure commentsStructure = StructureCache.getStructureByVelocityVarName(CommentsWebAPI.commentsVelocityStructureName);

      Contentlet contentletComment = new Contentlet();

      // set the default language
      com.dotmarketing.portlets.contentlet.business.Contentlet beanContentlet = (com.dotmarketing.portlets.contentlet.business.Contentlet) InodeFactory.getInode(contentlet.getInode(), com.dotmarketing.portlets.contentlet.business.Contentlet.class);

      contentletComment.setLanguageId(beanContentlet.getLanguageId());

      // Add the default fields
      contentletComment.setStructureInode(commentsStructure.getInode());

      Field field;

      /* Set the title if we have one*/
      if(UtilMethods.isSet(commentsOptions.get("commentTitle"))){

        field = commentsStructure.getFieldVar("title");

        conAPI.setContentletProperty(contentletComment, field, commentsOptions.get("commentTitle"));
      }

      /* Validate if a CommentsCount field exists in the contentlet structure
         if not, then create it and populate it.*/

      field = contentletStructure.getFieldVar("commentscount");
      if (field==null || !InodeUtils.isSet(field.getInode())) {
        List<Field> fields = new ArrayList<Field>();
          field = new Field("CommentsCount", Field.FieldType.TEXT, Field.DataType.INTEGER, contentletStructure,
                      false, false, true, Integer.MAX_VALUE, "0", "0", "",true, true, true);
        FieldFactory.saveField(field);
        for(Field structureField: contentletStructure.getFields()){
          fields.add(structureField);
        }
        fields.add(field);
        FieldsCache.removeFields(contentletStructure);
        FieldsCache.addFields(contentletStructure,fields);
      }

      /* Get the  value from the CommentsCount field for this contentlet, if the value
       * is null, then the contentlet has no comments, otherwise increment its value by one
       * and set it to the contentlet.
       */
     
      String velVar = field.getVelocityVarName();

      int comentsCount = -1;
      try {
        Long countValue = contentlet.getLongProperty(velVar);
        comentsCount  = countValue.intValue();
      } catch (Exception e) {
        Logger.debug(this, e.toString());
      }

      if (comentsCount == -1) {
        try {
          String countValue = (contentlet.getStringProperty(velVar) ==  null) ? field.getDefaultValue() : contentlet.getStringProperty(velVar);
          comentsCount  = countValue.equals("") ? 0 : new Integer(countValue).intValue();
        } catch (Exception e) {
          Logger.debug(this, e.toString());
        }
      }

      ++comentsCount;
      conAPI.setContentletProperty(contentlet, field, comentsCount);
      //Update the contentlet with the new comment count
      /*List<Category> cats = catAPI.getParents(contentlet, user, true);
      Map<Relationship, List<Contentlet>> contentRelationships = new HashMap<Relationship, List<Contentlet>>();

      List<Relationship> rels = RelationshipFactory.getAllRelationshipsByStructure(contentlet.getStructure());
      for (Relationship r : rels) {
        if(!contentRelationships.containsKey(r)){
          contentRelationships.put(r, new ArrayList<Contentlet>());
        }
        List<Contentlet> cons = conAPI.getRelatedContent(contentlet, r, user, true);
        for (Contentlet co : cons) {
          List<Contentlet> l2 = contentRelationships.get(r);
          l2.add(co);
        }
      }
      conAPI.checkinWithoutVersioning(contentlet, contentRelationships, cats, APILocator.getPermissionAPI().getPermissions(contentlet), user, true);
            */
      // Date
      field = commentsStructure.getFieldVar("datePublished");
      conAPI.setContentletProperty(contentletComment, field, new Date());

      // User Id
      field = commentsStructure.getFieldVar("userid");
      conAPI.setContentletProperty(contentletComment, field, userId);

      // Author
      field = commentsStructure.getFieldVar("author");
      conAPI.setContentletProperty(contentletComment, field, VelocityUtil.cleanVelocity(commentsForm.getName()));

      // Email
      field = commentsStructure.getFieldVar("email");
      conAPI.setContentletProperty(contentletComment, field, VelocityUtil.cleanVelocity(commentsForm.getEmail()));

      // WebSite
      field = commentsStructure.getFieldVar("website");
      conAPI.setContentletProperty(contentletComment, field, VelocityUtil.cleanVelocity(commentsForm.getWebsite()));

      // EmailResponse
      field = commentsStructure.getFieldVar("emailResponse");
      conAPI.setContentletProperty(contentletComment, field, (commentsForm.isNotify()?"yes":"no"));

      // IP Address
      field = commentsStructure.getFieldVar("ipAddress");
      conAPI.setContentletProperty(contentletComment, field, request.getRemoteAddr());

      // Comment
      field = commentsStructure.getFieldVar("comment");
      String comment = commentsForm.getComment();
      comment=VelocityUtil.cleanVelocity(comment);


      if (UtilMethods.isSet(commentsOptions.get("commentStripHtml")) && commentsOptions.get("commentStripHtml").equalsIgnoreCase("true")) {
        comment = Html.stripHtml(comment);
      }

      conAPI.setContentletProperty(contentletComment, field, comment);

      // Add the permission
      PermissionAPI perAPI = APILocator.getPermissionAPI();
      List<Permission> pers = perAPI.getPermissions(commentsStructure);




      // new workflows
      if(UtilMethods.isSet(commentsOptions.get("commentsModeration"))){
        if(!UtilMethods.isSet(contentletComment.getStringProperty(Contentlet.WORKFLOW_ACTION_KEY)))
            contentletComment.setStringProperty(Contentlet.WORKFLOW_ACTION_KEY, APILocator.getWorkflowAPI().findEntryAction(contentletComment, user).getId());
        contentletComment.setStringProperty(Contentlet.WORKFLOW_COMMENTS_KEY, commentsForm.getComment());
      }






      // Save the comment
      contentletComment = conAPI.checkin(contentletComment, new HashMap<Relationship, List<Contentlet>>(), new ArrayList<Category>(), pers, user, true);

            // If live I have to publish the asset
            if (UtilMethods.isSet(commentsOptions.get("commentAutoPublish")) && commentsOptions.get("commentAutoPublish").equalsIgnoreCase("true")) {
                APILocator.getVersionableAPI().setLive(contentletComment);
            }

      // Set the relation between the content and the comments
      Identifier contentletCommentIdentifier = APILocator.getIdentifierAPI().find(contentletComment);
      String commentRelationStructureName = commentsStructure.getName().replaceAll("\\s", "_").replaceAll("[^a-zA-Z0-9\\_]", "");
      String contentletRelationStructureName = contentletStructure.getName().replaceAll("\\s", "_").replaceAll("[^a-zA-Z0-9\\_]", "");
      String relationName = contentletRelationStructureName + "-" + commentRelationStructureName;


View Full Code Here

    return result;
  }

  public static void unpublishPageFile(HTMLPage htmlPage) throws DotStateException, DotDataException {

    Identifier identifier = APILocator.getIdentifierAPI().find(htmlPage);
    removePageFile(htmlPage, identifier, false);
  }
View Full Code Here

    removePageFile(htmlPage, identifier, false);
  }

  public static void removePageFile(HTMLPage htmlPage, boolean EDIT_MODE) throws DotStateException, DotDataException {

    Identifier identifier = APILocator.getIdentifierAPI().find(htmlPage);
    removePageFile(htmlPage, identifier, EDIT_MODE);
  }
View Full Code Here

    if (pageID == null || pageID.length() < 1) {
      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }
    Logger.debug(this, "Page to pdf is " + pageID);
    Identifier ident = null;
    Host host;
    try {
      host = hostWebAPI.getCurrentHost(req);
    } catch (PortalException e3) {
      Logger.error(HTMLPDFServlet.class, e3.getMessage(), e3);
      throw new ServletException(e3.getMessage(), e3);
    } catch (SystemException e3) {
      Logger.error(HTMLPDFServlet.class, e3.getMessage(), e3);
      throw new ServletException(e3.getMessage(), e3);
    } catch (DotDataException e3) {
      Logger.error(HTMLPDFServlet.class, e3.getMessage(), e3);
      throw new ServletException(e3.getMessage(), e3);
    } catch (DotSecurityException e3) {
      Logger.error(HTMLPDFServlet.class, e3.getMessage(), e3);
      throw new ServletException(e3.getMessage(), e3);
    }
    try {
      //Long id = Long.valueOf(pageID);
      ident = APILocator.getIdentifierAPI().find(pageID);
    } catch (NumberFormatException e2) {
      boolean external = false;
      String uri = pageID;
      String pointer = null;
      // Is it a virtual link?
      if (uri.endsWith("/"))
        uri = uri.substring(0, uri.length() - 1);
      pointer = VirtualLinksCache.getPathFromCache(host.getHostname()  + ":" + uri);

      if (!UtilMethods.isSet(pointer)) {
        pointer = VirtualLinksCache.getPathFromCache(uri);
      }

      if (UtilMethods.isSet(pointer)) { // is it a virtual link?
        Logger.debug(this, "CMS found virtual link pointer = " + uri + ":" + pointer);

        String auxPointer = pointer;
        if (auxPointer.indexOf("http://") != -|| auxPointer.indexOf("https://") != -1) {
          auxPointer = pointer.replace("https://", "");
          auxPointer = pointer.replace("http://", "");
          int startIndex = 0;
          int endIndex = auxPointer.indexOf("/");
          if (startIndex < endIndex) {
            String localHostName = auxPointer.substring(startIndex,  endIndex);
            Host localHost;
            try {
              localHost = hostWebAPI.findByName(localHostName, APILocator.getUserAPI().getSystemUser(), false);
            } catch (DotDataException e) {
              Logger.error(HTMLPDFServlet.class, e.getMessage(), e);
              throw new ServletException(e.getMessage(), e);
            } catch (DotSecurityException e) {
              Logger.error(HTMLPDFServlet.class, e.getMessage(), e);
              throw new ServletException(e.getMessage(), e);
            }
            external = (localHost == null || !InodeUtils.isSet(localHost.getInode() ) ? true : false);
          } else {
            external = true;
            pageID = pointer;
            uri = pointer;
          }
        }
        if (!external) {
          String ext = Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
          if (!pointer.endsWith(ext)) {
            if (!pointer.endsWith("/"))
              pointer += "/";
            pointer += "index." + ext;

          }
          pageID = pointer;
          uri = pointer;
        }

      }

      // Is it external?
      if (pageID.startsWith("http://") || pageID.startsWith("https://")) {
        if (!external) {
          // Didn't come form a virtual link, so we have to make sure
          // that we should PDF it according to web.xml
          URL url = new URL(pageID);
          if (!hostList.contains(url.getHost())) {
            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
          }
        }

        ITextRenderer renderer = new ITextRenderer();

        renderer.setDocument(pageID);
        Logger.debug(this, "Calling iText render");
        renderer.layout();
        try {
          Logger.debug(this, "Using iText to Create PDF");
          renderer.createPDF(resp.getOutputStream());

        } catch (DocumentException e) {
          Logger.error(this, e.getMessage(), e);
          resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
        return;
      }

      // Is it a wiki?
      String[] path = pageID.split("/");
      if (path.length > 2) {
        String wiki = map.get("/" + path[1]);
        String wikiName = pageID.substring(1); // String of first /
        // Get everything after the second /
        wikiName = wikiName.substring(wikiName.indexOf("/")+1); // Get
        // everything
        // after
        // the
        // second
        // /
        String title = WikiUtils.normalizeTitle(wikiName);
        if (wiki != null) {
          String struct = wiki.split("\\|")[0];
          String field = wiki.split("\\|")[1];

          ContentletAPI capi = APILocator.getContentletAPI();
          String query = "+structureInode:" + struct + " +" + field
              + ":\"" + title
              + "\" +languageId:1* +deleted:false +live:true";
          List<com.dotmarketing.portlets.contentlet.model.Contentlet> cons = null;
          try {
            cons = capi.search(query, 1, 0, "text1", user, true);
          } catch (DotDataException e) {
            Logger.debug(this, "DotDataException: "  + e.getMessage(), e);
          } catch (DotSecurityException e) {
            Logger.debug(this, "DotSecurityException: "  + e.getMessage(), e);
          } catch (Exception e) {
            Logger.debug(this, "ParseException: " + e.getMessage(),  e);
          }
          if (cons != null && cons.size() > 0) {
            com.dotmarketing.portlets.contentlet.model.Contentlet c = cons.get(0);
            req.setAttribute(WebKeys.CLICKSTREAM_IDENTIFIER_OVERRIDE, c.getIdentifier());
          } else {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
          }
          pageID = "/"
              + path[1]
              + "/index."
              + Config
                  .getStringProperty("VELOCITY_PAGE_EXTENSION");
          uri=pageID;

        }
      }

      if (pageID.endsWith("/")) {
        uri = pageID + "index."
            + Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
      } else {
        if (!pageID.endsWith("."
            + Config.getStringProperty("VELOCITY_PAGE_EXTENSION"))) {
          uri = pageID
              + "/index."
              + Config
                  .getStringProperty("VELOCITY_PAGE_EXTENSION");
        }
      }
      try {
        ident = APILocator.getIdentifierAPI().find(host, uri);
      } catch (Exception e) {
        Logger.debug(this, "Exception: " + e.getMessage(), e);      }
    } catch (Exception e1) {
      Logger.debug(this, e1.getMessage(), e1);
    }
    if (ident == null) {
      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }
    if (!InodeUtils.isSet(ident.getInode() )) {
      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    String url = ident.getURI();
    url = url.substring(0, url.lastIndexOf("/")) + "/";
    try {
      if (!perAPI.doesUserHavePermission(ident,PermissionAPI.PERMISSION_READ, user, true)) {
        resp.sendError(HttpServletResponse.SC_FORBIDDEN);
      }
    } catch (DotDataException e1) {
      Logger.error(HTMLPDFServlet.class,e1.getMessage(),e1);
      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.getMessage());
    }

    StringWriter sw = new StringWriter();

    Context context;

    context = VelocityUtil.getWebContext(req, resp);
    context.put("pdfExport", true);

    String pageIdent = ident.getInode() + "";

    try {
      VelocityEngine ve = VelocityUtil.getEngine();
      ve.getTemplate("/" + location + "/" + pageIdent + "." + VELOCITY_HTMLPAGE_EXTENSION).merge(context, sw);
      ITextRenderer renderer = new ITextRenderer();
View Full Code Here

        relativePath = path.substring(index);

      } else {
        String identifier = path.substring(path.lastIndexOf("/") + 1,
            path.indexOf("."));
        Identifier ident = APILocator.getIdentifierAPI().find(identifier);
        relativePath = LiveCache.getPathFromCache(ident.getURI(), ident.getHostId());
      }

    } else if(path.startsWith("/resize_image?")){
      Logger.debug(this, "Fixing resize image servlet");
      return "http://" + host.getHostname() + path;
View Full Code Here

TOP

Related Classes of com.dotmarketing.beans.Identifier

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.