Example usage for java.text MessageFormat setFormat

List of usage examples for java.text MessageFormat setFormat

Introduction

In this page you can find the example usage for java.text MessageFormat setFormat.

Prototype

public void setFormat(int formatElementIndex, Format newFormat) 

Source Link

Document

Sets the format to use for the format element with the given format element index within the previously set pattern string.

Usage

From source file:com.haulmont.cuba.desktop.sys.vcl.DatePicker.DatePicker.java

@Override
public void setLinkDay(Date linkDay) {
    MessageFormat todayFormat = new MessageFormat(
            AppBeans.get(Messages.class).getMessage("com.haulmont.cuba.desktop", "DatePicker.linkFormat"));
    todayFormat.setFormat(0, new SimpleDateFormat(
            Datatypes.getFormatStrings(AppBeans.get(UserSessionSource.class).getLocale()).getDateFormat()));
    setLinkFormat(todayFormat);//from  ww w  .  j a  va  2  s.  c  o m
    super.setLinkDay(linkDay);
}

From source file:org.springframework.cloud.deployer.resource.maven.MavenArtifactResolver.java

/**
 * Resolve an artifact and return its location in the local repository. Aether performs the normal
 * Maven resolution process ensuring that the latest update is cached to the local repository.
 * In addition, if the {@link MavenProperties#resolvePom} flag is <code>true</code>,
 * the POM is also resolved and cached.//w w  w  .  j a va2s  . co m
 * @param resource the {@link MavenResource} representing the artifact
 * @return a {@link FileSystemResource} representing the resolved artifact in the local repository
 * @throws IllegalStateException if the artifact does not exist or the resolution fails
 */
Resource resolve(MavenResource resource) {
    Assert.notNull(resource, "MavenResource must not be null");
    validateCoordinates(resource);
    RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem,
            this.properties.getLocalRepository());
    ArtifactResult resolvedArtifact;
    try {
        List<ArtifactRequest> artifactRequests = new ArrayList<>(2);
        if (properties.isResolvePom()) {
            artifactRequests.add(
                    new ArtifactRequest(toPomArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));
        }
        artifactRequests
                .add(new ArtifactRequest(toJarArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));

        List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session, artifactRequests);
        resolvedArtifact = results.get(results.size() - 1);
    } catch (ArtifactResolutionException e) {

        ChoiceFormat pluralizer = new ChoiceFormat(new double[] { 0d, 1d, ChoiceFormat.nextDouble(1d) },
                new String[] { "repositories: ", "repository: ", "repositories: " });
        MessageFormat messageFormat = new MessageFormat(
                "Failed to resolve MavenResource: {0}. Configured remote {1}: {2}");
        messageFormat.setFormat(1, pluralizer);
        String repos = properties.getRemoteRepositories().isEmpty() ? "none"
                : StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(), ",", "[",
                        "]");
        throw new IllegalStateException(messageFormat
                .format(new Object[] { resource, properties.getRemoteRepositories().size(), repos }), e);
    }
    return toResource(resolvedArtifact);
}