freemarker.template.TemplateNumberModel#org.springframework.extensions.surf.util.I18NUtil源码实例Demo

下面列出了freemarker.template.TemplateNumberModel#org.springframework.extensions.surf.util.I18NUtil 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public void testShallowFilesAndFoldersListWithLocale() throws Exception
{
    Locale savedLocale = I18NUtil.getContentLocaleOrNull();
    try
    {
        I18NUtil.setContentLocale(Locale.CANADA);
        List<FileInfo> files = fileFolderService.list(workingRootNodeRef);
        // check
        String[] expectedNames = new String[]
        { NAME_L0_FILE_A, NAME_L0_FILE_B, NAME_L0_FOLDER_A, NAME_L0_FOLDER_B, NAME_L0_FOLDER_C };
        checkFileList(files, 2, 3, expectedNames);
    }
    finally
    {
        I18NUtil.setContentLocale(savedLocale);
    }
}
 
源代码2 项目: alfresco-repository   文件: CopyServiceImpl.java
/**
 * Builds name by appending copy label.
 */
String buildNewName(final String name)
{
    String baseName = FilenameUtils.getBaseName(name);
    String extension = FilenameUtils.getExtension(name);

    String newName = I18NUtil.getMessage(COPY_OF_LABEL, baseName);

    // append extension, if any, to filename
    if (extension != null && !extension.isEmpty())
    {
        newName = newName + FilenameUtils.EXTENSION_SEPARATOR_STR + extension;
    }

    return newName;
}
 
源代码3 项目: alfresco-repository   文件: PatchServiceImpl.java
private boolean validatePatchImpl(List<Patch> patches)
{
    boolean success = true;
    int serverSchemaVersion = descriptorService.getServerDescriptor().getSchema();
    for (Patch patch : patches)
    {
        if (patch.getFixesToSchema() > serverSchemaVersion)
        {
            logger.error(I18NUtil.getMessage(MSG_VALIDATION_FAILED, patch.getId(), serverSchemaVersion, patch
                    .getFixesToSchema(), patch.getTargetSchema()));
            success = false;
        }
    }
    if (!success)
    {
        this.transactionService.setAllowWrite(false, vetoName);
    }
    return success;
}
 
源代码4 项目: alfresco-repository   文件: MailActionExecuter.java
/**
 * Attempt to localize the subject, using the subject parameter as the message key.
 * 
 * @param subject Message key for subject lookup
 * @param params Parameters for the message
 * @param locale Locale to use
 * @return The localized message, or subject if the message format could not be found
 */
private String getLocalizedSubject(String subject, Object[] params, Locale locale)
{
    String localizedSubject = null;
    if (locale == null)
    {
        localizedSubject = I18NUtil.getMessage(subject, params);
    }
    else 
    {
        localizedSubject = I18NUtil.getMessage(subject, locale, params);
    }
    
    if (localizedSubject == null)
    {
        return subject;
    }
    else
    {
        return localizedSubject;
    }
    
}
 
@Override
protected String applyInternal() throws Exception
{
    // We don't need to catch the potential InvalidQNameException here as it will be caught
    // in AbstractPatch and correctly handled there
    QName qnameType = QName.createQName(this.qnameStringType);
    QName qnameAspect = QName.createQName(this.qnameStringAspect);

    Long maxNodeId = patchDAO.getMaxAdmNodeID();
    
    Pair<Long, QName> type = qnameDAO.getQName(qnameType);
    Pair<Long, QName> aspect = qnameDAO.getQName(qnameAspect);
    
    if (type != null && aspect != null)
    {
        for (Long i = 0L; i < maxNodeId; i+=BATCH_SIZE)
        {
            Work work = new Work(type, aspect, i);
            retryingTransactionHelper.doInTransaction(work, false, true);
        }
    }

    return I18NUtil.getMessage(MSG_SUCCESS, qnameAspect, qnameType);
}
 
源代码6 项目: alfresco-repository   文件: TaskFormProcessor.java
private String getMessageValue(WorkflowTask task)
{
    String message = I18NUtil.getMessage(MessageFieldProcessor.MSG_VALUE_NONE);
    
    String description = (String)task.getProperties().get(WorkflowModel.PROP_DESCRIPTION);
    if (description != null)
    {
        String taskTitle = task.getTitle();
        if (taskTitle == null || !taskTitle.equals(description))
        {
            message = description;
        }
    }
    
    return message;
}
 
/**
 * Apply Client and Repository language locale based on the 'Accept-Language' request header
 *
 * @param req HttpServletRequest
 */
public void setLanguageFromRequestHeader(HttpServletRequest req)
{
    Locale locale = null;

    String acceptLang = req.getHeader("Accept-Language");
    if (acceptLang != null && acceptLang.length() > 0)
    {
        StringTokenizer tokenizer = new StringTokenizer(acceptLang, ",; ");
        // get language and convert to java locale format
        String language = tokenizer.nextToken().replace('-', '_');
        locale = I18NUtil.parseLocale(language);
        I18NUtil.setLocale(locale);
    }
    else
    {
        I18NUtil.setLocale(Locale.getDefault());
    }
}
 
源代码8 项目: alfresco-data-model   文件: ContentData.java
/**
 * Create a compound set of data representing a single instance of <i>content</i>.
 * <p>
 * In order to ensure data integrity, the {@link #getMimetype() mimetype}
 * must be set if the {@link #getContentUrl() content URL} is set.
 * 
 * @param contentUrl the content URL.  If this value is non-null, then the
 *      <b>mimetype</b> must be supplied.
 * @param mimetype the content mimetype.  This is mandatory if the <b>contentUrl</b> is specified.
 * @param size the content size.
 * @param encoding the content encoding.  This is mandatory if the <b>contentUrl</b> is specified.
 * @param locale the locale of the content (may be <tt>null</tt>).  If <tt>null</tt>, the
 *      {@link I18NUtil#getLocale() default locale} will be used.
 */
public ContentData(String contentUrl, String mimetype, long size, String encoding, Locale locale)
{
    if (contentUrl != null && (mimetype == null || mimetype.length() == 0))
    {
        mimetype = MimetypeMap.MIMETYPE_BINARY;
    }
    checkContentUrl(contentUrl, mimetype, encoding);
    this.contentUrl = contentUrl;
    this.mimetype = mimetype;
    this.size = size;
    this.encoding = encoding;
    if (locale == null)
    {
        locale = I18NUtil.getLocale();
    }
    this.locale = locale;
}
 
public String getLabelByCode(String code)
{
    // get the translated language label
    String label;

    label = I18NUtil.getMessage(MESSAGE_PREFIX + code);

    // if not found, get the default name (found in content-filter-lang.xml)
    if(label == null || label.length() == 0)
    {
        label = languagesByCode.get(code);
    }

    // if not found, return the language code
    if(label == null || label.length() == 0)
    {
        label = code + " (label not found)";
    }

    return label;
}
 
源代码10 项目: alfresco-data-model   文件: SearchDateConversion.java
/**
 * @param dateAndResolution
 * @return String date
 */
public static String getDateStart(Pair<Date, Integer> dateAndResolution)
{
    Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
    cal.setTime(dateAndResolution.getFirst());
    switch (dateAndResolution.getSecond())
    {
        case Calendar.YEAR:
            cal.set(Calendar.MONTH, cal.getActualMinimum(Calendar.MONTH));
        case Calendar.MONTH:
            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
        case Calendar.DAY_OF_MONTH:
            cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
        case Calendar.HOUR_OF_DAY:
            cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
        case Calendar.MINUTE:
            cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
        case Calendar.SECOND:
            cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
        case Calendar.MILLISECOND:
        default:
    }
    SimpleDateFormat formatter = CachingDateFormat.getSolrDatetimeFormat();
    formatter.setTimeZone(UTC_TIMEZONE);
    return formatter.format(cal.getTime());
}
 
源代码11 项目: alfresco-data-model   文件: SearchDateConversion.java
/**
 * @param dateAndResolution
 * @return String date
 */
public static String getDateEnd(Pair<Date, Integer> dateAndResolution)
{
    Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
    cal.setTime(dateAndResolution.getFirst());
    switch (dateAndResolution.getSecond())
    {
        case Calendar.YEAR:
            cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH));
        case Calendar.MONTH:
            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        case Calendar.DAY_OF_MONTH:
            cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
        case Calendar.HOUR_OF_DAY:
            cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
        case Calendar.MINUTE:
            cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
        case Calendar.SECOND:
            cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND));
        case Calendar.MILLISECOND:
        default:
    }
    SimpleDateFormat formatter = CachingDateFormat.getSolrDatetimeFormat();
    formatter.setTimeZone(UTC_TIMEZONE);
    return formatter.format(cal.getTime());
}
 
源代码12 项目: alfresco-remote-api   文件: GroupsImpl.java
private AuthorityInfoComparator(String sortBy, boolean sortAsc)
{
    col = AlfrescoCollator.getInstance(I18NUtil.getLocale());
    this.sortBy = sortBy;
    this.nameCache = new HashMap<>();

    if (!sortAsc)
    {
        orderMultiplier = -1;
    }
}
 
/**
 * Validates <a href="https://issues.alfresco.com/jira/browse/ALFCOM-2655">ACT-7225</a>
 */
public void testGetType() throws Exception
{
    Locale savedLocale = I18NUtil.getContentLocaleOrNull();
    try
    {
        I18NUtil.setContentLocale(Locale.CANADA);
        FileFolderServiceType type = fileFolderService.getType(ContentModel.TYPE_FOLDER);
        assertEquals("Type incorrect for folder", FileFolderServiceType.FOLDER, type);
    }
    finally
    {
        I18NUtil.setContentLocale(savedLocale);
    }
}
 
源代码14 项目: alfresco-repository   文件: EmailHelper.java
/**
 * Gets the user's locale.
 *
 * @param userId the user id
 * @return the default locale or the user's preferred locale, if available
 */
public Locale getUserLocaleOrDefault(String userId)
{
    if (userId != null && personService.personExists(userId))
    {
        String localeString = AuthenticationUtil.runAsSystem(() -> (String) preferenceService.getPreference(userId, "locale"));
        if (localeString != null)
        {
            return I18NUtil.parseLocale(localeString);
        }
    }

    return I18NUtil.getLocale();
}
 
源代码15 项目: alfresco-repository   文件: PatchServiceImpl.java
private void applyPatch()
{
    if (state != STATE.APPLYING)
    {
        // nothing to do
        return;
    }

    // perform actual execution
    try
    {
        String msg = I18NUtil.getMessage(
                MSG_APPLYING_PATCH,
                patch.getId(),
                I18NUtil.getMessage(patch.getDescription()));
        logger.info(msg);
        // the patch is executed regardless of the deferred flag value
        report = (patch.isDeferred()) ? patch.applyAsync() : patch.apply();
        state = STATE.APPLIED;
    }
    catch (PatchException e)
    {
        // failed
        report = e.getMessage();
        state = STATE.FAILED;
        // dump the report to log
        logger.error(report);
    }
}
 
源代码16 项目: alfresco-repository   文件: ImapFoldersPatch.java
@Override
protected String applyInternal() throws Exception
{
    checkCommonProperties();
    setUp();
    String msg = null;
    if (imapConfigFolderNodeRef == null)
    {
        // import the content
        final RunAsWork<Object> importRunAs = new RunAsWork<Object>()
        {
            public Object doWork() throws Exception
            {
                importImapConfig();
                importScripts();
                importEmailActions();
                return null;
            }
        };
        
        RetryingTransactionCallback<Object> cb = new RetryingTransactionCallback<Object>()
        {
            public Object execute() throws Throwable 
            {
                AuthenticationUtil.runAs(importRunAs, authenticationContext.getSystemUserName());
                return null;
            }
     
        };
        
        transactionHelper.doInTransaction(cb, false, true);
        msg = I18NUtil.getMessage(MSG_CREATED);
    }
    else
    {
        msg = I18NUtil.getMessage(MSG_EXISTS, imapConfigFolderNodeRef);
    }
    return msg;

}
 
源代码17 项目: alfresco-remote-api   文件: QuickShareLinksImpl.java
@Override
public void emailSharedLink(String sharedId, QuickShareLinkEmailRequest emailRequest, Parameters parameters)
{
    checkEnabled();
    checkValidShareId(sharedId);
    validateEmailRequest(emailRequest);

    try
    {
        NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
        String sharedNodeName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        QuickShareEmailRequest request = new QuickShareEmailRequest();
        request.setSharedNodeName(sharedNodeName);
        request.setClient(emailRequest.getClient());
        request.setSharedId(sharedId);
        request.setSenderMessage(emailRequest.getMessage());
        request.setLocale(I18NUtil.parseLocale(emailRequest.getLocale()));
        request.setToEmails(emailRequest.getRecipientEmails());
        quickShareService.sendEmailNotification(request);
    }
    catch (InvalidSharedIdException ex)
    {
        throw new EntityNotFoundException(sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
 
源代码18 项目: alfresco-repository   文件: SiteLoadPatch.java
@Override
  protected String applyInternal() throws Exception
  {
  	//skip sites that we don't want imported automatically
if (isDisabled()) 
{
	 if (logger.isDebugEnabled())
	 {
		 logger.debug("Load of site \"" + siteName + "\" is disabled.");
	 }
	 return I18NUtil.getMessage(MSG_SITE_LOAD_DISABLED, siteName);
}
      AuthenticationUtil.pushAuthentication();
      try
      {
          // The site service is funny about permissions,
          //  so even though we're running as the system we
          //  still need to identify us as the admin user
          AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
          
          return applyInternalImpl();
      }
      finally
      {
          AuthenticationUtil.popAuthentication();
      }
  }
 
源代码19 项目: alfresco-repository   文件: SWSDPPatch.java
@Override
protected String applyInternal() throws Exception
{
	SiteInfo siteInfo = siteService.getSite("swsdp");
	if(siteInfo != null)
	{
 	NodeRef nodeRef = siteInfo.getNodeRef();
 	NodeRef surfConfigNodeRef = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, "surf-config");
 	if(surfConfigNodeRef == null)
 	{
         return I18NUtil.getMessage(MSG_MISSING_SURFCONFIG);
 	}
 	else
 	{
  	for(ChildAssociationRef childRef : nodeService.getChildAssocs(surfConfigNodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL))
  	{
  		hiddenAspect.showNode(childRef.getChildRef(), true);
  	}
 	}

     return I18NUtil.getMessage(MSG_SITE_PATCHED);
	}
	else
	{
     return I18NUtil.getMessage(MSG_SKIPPED);
	}
}
 
源代码20 项目: alfresco-data-model   文件: MLText.java
/**
 * The given locale is used to search for a matching value according to:
 * <ul>
 *   <li>An exact locale match</li>
 *   <li>A match of locale ISO language codes</li>
 *   <li>The value for the locale provided in the {@link MLText#MLText(Locale, String) constructor}</li>
 *   <li>An arbitrary value</li>
 *   <li><tt>null</tt></li>
 * </ul>
 * 
 * @param locale the locale to use as the starting point of the value search
 * @return Returns a default <tt>String</tt> value or null if one isn't available.
 *      <tt>null</tt> will only be returned if there are no values associated with
 *      this instance.  With or without a match, the return value may be <tt>null</tt>,
 *      depending on the values associated with the locales.
 */
public String getClosestValue(Locale locale)
{
    if (this.size() == 0)
    {
        return null;
    }
    // Use the available keys as options
    Set<Locale> options = keySet();
    // Get a match
    Locale match = I18NUtil.getNearestLocale(locale, options);
    if (match == null)
    {
        // No close matches for the locale - go for the default locale
        locale = I18NUtil.getLocale();
        match = I18NUtil.getNearestLocale(locale, options);
        if (match == null)
        {
            // just get any locale
            match = I18NUtil.getNearestLocale(null, options);
        }
    }
    // Did we get a match
    if (match == null)
    {
        // We could find no locale matches
        return null;
    }
    else
    {
        return get(match);
    }
}
 
@Override
protected String applyInternal() throws Exception
{
    StoreRef storeRef = importerBootstrap.getStoreRef();
    NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
    if (checkPath != null)
    {
        List<NodeRef> results = searchService.selectNodes(
                rootNodeRef,
                checkPath,
                null,
                namespaceService,
                false);
        if (results.size() > 1)
        {
            throw new PatchException(ERR_MULTIPLE_FOUND, checkPath);
        }
        else if (results.size() == 1)
        {
            // nothing to do - it exists
            return I18NUtil.getMessage(MSG_EXISTS, checkPath);
            
        }
    }
    String path = bootstrapView.getProperty("path");
    List<Properties> bootstrapViews = new ArrayList<Properties>(1);
    bootstrapViews.add(bootstrapView);
    // modify the bootstrapper
    importerBootstrap.setBootstrapViews(bootstrapViews);
    importerBootstrap.setUseExistingStore(true);              // allow import into existing store

    importerBootstrap.bootstrap();
    // done
    return I18NUtil.getMessage(MSG_CREATED, path, rootNodeRef);
}
 
/**
 * @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
 */
@Override
protected String applyInternal() throws Exception
{   
    while (currentIndex < BASE_FILES.length)
    {
        updateTemplates();  
        currentIndex ++;
    }        
    
    return I18NUtil.getMessage("patch.addDutchEmailTemplatesPatch.result");
}
 
public String sendTestMessage()
{
    try
    {
        mailActionExceuter.sendTestMessage();
        Object[] params = {mailActionExceuter.getTestMessageTo()};
        String message = I18NUtil.getMessage("email.outbound.test.send.success", params);
        return message;
    }
    catch (AlfrescoRuntimeException are)
    {
        return (are.getMessage());
    }
}
 
源代码24 项目: alfresco-repository   文件: UsageDAOTest.java
private NodeRef createNode(long parentNodeId)
{
    ChildAssocEntity assoc = nodeDAO.newNode(
            parentNodeId,
            ContentModel.ASSOC_CHILDREN,
            ContentModel.ASSOC_CHILDREN,
            storeRef,
            null,
            ContentModel.TYPE_CONTENT,
            I18NUtil.getLocale(),
            null,
            null);
    
    return assoc.getChildNode().getNodeRef();
}
 
/**
 * @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
 */
@Override
protected String applyInternal() throws Exception
{   
    updateTemplates();        
    return I18NUtil.getMessage("patch.updateWorkflowNotificationTemplates.result");
}
 
@Override
protected String applyInternal() throws Exception
{
    StringBuilder result = new StringBuilder(I18NUtil.getMessage(MSG_START));
    int updateCount = patchDAO.updatePersonSizeCurrentType();
    result.append(I18NUtil.getMessage(MSG_DONE, updateCount));
    return result.toString();
}
 
/**
 * {@inheritDoc}
 */
public Pair<Long, Locale> getLocalePair(Long id)
{
    if (id == null)
    {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }
    
    Pair<Long, String> entityPair = localeEntityCache.getByKey(id);
    if (entityPair == null)
    {
        throw new DataIntegrityViolationException("No locale exists for ID " + id);
    }
    String localeStr = entityPair.getSecond();
    // Convert the locale string to a locale
    Locale locale = null;
    if (LocaleEntity.DEFAULT_LOCALE_SUBSTITUTE.equals(localeStr))
    {
        locale = I18NUtil.getLocale();
    }
    else
    {
        locale = DefaultTypeConverter.INSTANCE.convert(Locale.class, entityPair.getSecond());
    }
    
    return new Pair<Long, Locale>(id, locale);
}
 
@Override
protected NodeRef getBaseTemplate()
{
    List<NodeRef> refs = searchService.selectNodes(
            repository.getRootHome(), 
            XPATH, 
            null, 
            namespaceService, 
            false);
    if (refs.size() != 1)
    {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage("patch.updateFollowingEmailTemplatesPatch.error"));
    }
    return refs.get(0);
}
 
源代码29 项目: alfresco-repository   文件: RepoAdminServiceImpl.java
private String getLocalisedMessage(String msgId, Object... params)
{
    String localisedMsg = I18NUtil.getMessage(msgId, params);
    if (localisedMsg == null)
    {
        localisedMsg = msgId;
    }
    return localisedMsg;
}
 
@Override
protected FieldDefinition makeTransientFieldDefinition()
{
    PropertyFieldDefinition fieldDef = new PropertyFieldDefinition(KEY, DATA_TYPE);
    fieldDef.setRepeating(false);
    fieldDef.setProtectedField(true);
    
    fieldDef.setLabel(I18NUtil.getMessage(MSG_LABEL));
    fieldDef.setDescription(I18NUtil.getMessage(MSG_DESCRIPTION));
    fieldDef.setDataKeyName(PROP_DATA_PREFIX + KEY);
    return fieldDef;
}