Exemplo n.º 1
0
 public String checkDependencies(String templateInode)
     throws DotDataException, DotRuntimeException, DotSecurityException, PortalException,
         SystemException {
   HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
   User user = userWebAPI.getLoggedInUser(req);
   boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);
   return templateAPI.checkDependencies(templateInode, user, respectFrontendRoles);
 }
Exemplo n.º 2
0
 private Map<String, Object> buildTemplateMap(Template template)
     throws DotDataException, DotStateException, DotSecurityException {
   if (template == null) return null;
   Host parentHost = null;
   if (template instanceof TemplateWrapper) {
     parentHost = ((TemplateWrapper) template).getHost();
   } else {
     try {
       parentHost = templateAPI.getTemplateHost(template);
     } catch (DotDataException e) {
       Logger.warn(this, "Could not find host for template = " + template.getIdentifier());
     }
   }
   Map<String, Object> templateMap = template.getMap();
   if (parentHost != null) {
     templateMap.put("hostName", parentHost.getHostname());
     templateMap.put("hostId", parentHost.getIdentifier());
     templateMap.put("fullTitle", parentHost.getHostname() + " " + templateMap.get("title"));
   } else {
     templateMap.put("fullTitle", templateMap.get("title"));
   }
   return templateMap;
 }
Exemplo n.º 3
0
 public Map<String, Object> fetchTemplateImage(String id)
     throws DotDataException, DotSecurityException {
   Map<String, Object> toReturn = new HashMap<String, Object>();
   Template template = null;
   try {
     template =
         templateAPI.findWorkingTemplate(id, APILocator.getUserAPI().getSystemUser(), false);
   } catch (DotSecurityException e) {
     Logger.error(this, e.getMessage());
   }
   if (template != null) {
     Identifier imageIdentifier = APILocator.getIdentifierAPI().find(template.getImage());
     if (UtilMethods.isSet(imageIdentifier.getAssetType())
         && imageIdentifier.getAssetType().equals("contentlet")) {
       Contentlet imageContentlet = TemplateFactory.getImageContentlet(template);
       if (imageContentlet != null) {
         toReturn.put("inode", imageContentlet.getInode());
         toReturn.put("name", imageContentlet.getTitle());
         toReturn.put("identifier", imageContentlet.getIdentifier());
         toReturn.put(
             "extension",
             com.dotmarketing.util.UtilMethods.getFileExtension(imageContentlet.getTitle()));
       }
     } else {
       File imgFile = TemplateFactory.getImageFile(template);
       if (imgFile != null) {
         toReturn.put("inode", imgFile.getInode());
         toReturn.put("name", imgFile.getFileName());
         toReturn.put("identifier", imgFile.getIdentifier());
         toReturn.put(
             "extension",
             com.dotmarketing.util.UtilMethods.getFileExtension(imgFile.getFileName()));
       }
     }
   }
   return toReturn;
 }
Exemplo n.º 4
0
  public Map<String, Object> fetchTemplates(
      Map<String, String> query,
      Map<String, String> queryOptions,
      int start,
      int count,
      List<String> sort)
      throws PortalException, SystemException, DotDataException, DotSecurityException {

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);
    if (count <= 0) count = 10;

    List<Template> fullListTemplates = new ArrayList<Template>();
    List<Template> totalTemplates = new ArrayList<Template>();
    Host host = hostAPI.find(query.get("hostId"), user, respectFrontendRoles);

    try {
      String filter = query.get("fullTitle");
      if (UtilMethods.isSet(filter)) {
        filter = filter.replaceAll("\\*", "");
        filter = filter.replaceAll("\\?", "");
      }

      if (UtilMethods.isSet(query.get("hostId"))) {
        int startF = start;
        int countF = count;
        if (start == 0) {
          Template t = new Template();
          t.setOwner(user.getUserId());
          t.setModUser(user.getUserId());
          t.setInode("0");
          t.setTitle("--- " + LanguageUtil.get(user, "All-Hosts") + " ---");
          t.setIdentifier("0");
          fullListTemplates.add(t);
          totalTemplates.add(t);
          countF = count - 1;
        } else {
          startF = start - 1;
        }
        fullListTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(
                user, host.getHostname(), filter, true, startF, countF));
        totalTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(user, host.getHostname(), filter, true, 0, 1000));
      }

      // doesn't currently respect archived
      if (fullListTemplates.size() == 0) {
        fullListTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(
                user, "", filter, true, start, start > 0 ? count : count + 1));
        totalTemplates.addAll(templateAPI.findTemplatesUserCanUse(user, "", filter, true, 0, 1000));
      }

    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
      throw new DotDataException(e.getMessage(), e);
    }
    // Collections.sort(fullListTemplates, new TemplateComparator(baseHostId));
    Map<String, Object> results = new HashMap<String, Object>();
    List<Map<String, Object>> list = new LinkedList<Map<String, Object>>();

    boolean shouldIncludeTemplate = true;
    String toInclude = queryOptions.get("includeTemplate");
    for (Template template : fullListTemplates) {
      Map<String, Object> contMap = buildTemplateMap(template);
      list.add(contMap);
    }
    if (toInclude != null && shouldIncludeTemplate) {
      Template template =
          templateAPI.findWorkingTemplate(
              toInclude, APILocator.getUserAPI().getSystemUser(), false);
      if (template != null) {
        list.add(buildTemplateMap(template));
      }
    }

    //		totalTemplates = templateAPI.findTemplatesAssignedTo(host);
    //		if(start >= list.size()) start =  list.size() - 1;
    //		if(start < 0)  start  = 0;
    //		if(start + count >= list.size()) count = list.size() - start;
    //		List<Map<String, Object>> templates = list.subList(start, start + count);

    results.put("totalResults", totalTemplates.size());

    results.put("list", list);

    return results;
  }
Exemplo n.º 5
0
 public Map<String, Object> fetchByIdentity(String id)
     throws DotDataException, DotSecurityException {
   return buildTemplateMap(templateAPI.findWorkingTemplate(id, userWebAPI.getSystemUser(), false));
 }