public void checkNewLine(long groupId, String templateId)
      throws PortalException, SystemException {

    JournalTemplate template = journalTemplatePersistence.findByG_T(groupId, templateId);

    String xsl = template.getXsl();

    if ((xsl != null) && (xsl.indexOf("\\n") != -1)) {
      xsl = StringUtil.replace(xsl, new String[] {"\\n", "\\r"}, new String[] {"\n", "\r"});

      template.setXsl(xsl);

      journalTemplatePersistence.update(template, false);
    }
  }
Exemple #2
0
  public JournalTemplateResourceImpl(JournalTemplate template, String parentPath, String name) {

    super(
        parentPath,
        name,
        template.getTemplateId(),
        template.getCreateDate(),
        template.getModifiedDate(),
        template.getXsl().length());

    setModel(template);
    setClassName(JournalTemplate.class.getName());
    setPrimaryKey(template.getPrimaryKey());

    _template = template;
  }
  public JournalTemplate copyTemplate(
      long userId, long groupId, String oldTemplateId, String newTemplateId, boolean autoTemplateId)
      throws PortalException, SystemException {

    // Template

    User user = userPersistence.findByPrimaryKey(userId);
    oldTemplateId = oldTemplateId.trim().toUpperCase();
    newTemplateId = newTemplateId.trim().toUpperCase();
    Date now = new Date();

    JournalTemplate oldTemplate = journalTemplatePersistence.findByG_T(groupId, oldTemplateId);

    if (autoTemplateId) {
      newTemplateId = String.valueOf(counterLocalService.increment());
    } else {
      validate(newTemplateId);

      JournalTemplate newTemplate = journalTemplatePersistence.fetchByG_T(groupId, newTemplateId);

      if (newTemplate != null) {
        throw new DuplicateTemplateIdException();
      }
    }

    long id = counterLocalService.increment();

    JournalTemplate newTemplate = journalTemplatePersistence.create(id);

    newTemplate.setGroupId(groupId);
    newTemplate.setCompanyId(user.getCompanyId());
    newTemplate.setUserId(user.getUserId());
    newTemplate.setUserName(user.getFullName());
    newTemplate.setCreateDate(now);
    newTemplate.setModifiedDate(now);
    newTemplate.setTemplateId(newTemplateId);
    newTemplate.setStructureId(oldTemplate.getStructureId());
    newTemplate.setNameMap(oldTemplate.getNameMap());
    newTemplate.setDescriptionMap(oldTemplate.getDescriptionMap());
    newTemplate.setXsl(oldTemplate.getXsl());
    newTemplate.setLangType(oldTemplate.getLangType());
    newTemplate.setCacheable(oldTemplate.isCacheable());
    newTemplate.setSmallImage(oldTemplate.isSmallImage());
    newTemplate.setSmallImageId(counterLocalService.increment());
    newTemplate.setSmallImageURL(oldTemplate.getSmallImageURL());

    journalTemplatePersistence.update(newTemplate, false);

    // Small image

    if (oldTemplate.getSmallImage()) {
      Image image = imageLocalService.getImage(oldTemplate.getSmallImageId());

      byte[] smallImageBytes = image.getTextObj();

      imageLocalService.updateImage(newTemplate.getSmallImageId(), smallImageBytes);
    }

    // Resources

    addTemplateResources(newTemplate, true, true);

    return newTemplate;
  }