下面列出了java.text.MessageFormat#format ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
String valueStr = stringFse.expandString(methodContext.getEnvMap());
List<? extends Object> argList = argListFma.get(methodContext.getEnvMap());
if (argList != null) {
try {
valueStr = MessageFormat.format(valueStr, argList.toArray());
} catch (IllegalArgumentException e) {
throw new MiniLangRuntimeException("Exception thrown while formatting the string attribute: " + e.getMessage(), this);
}
}
Object value;
if (UtilValidate.isNotEmpty(this.messageFieldName)) {
value = new MessageString(valueStr, this.messageFieldName, true);
} else {
value = valueStr;
}
List<Object> toList = listFma.get(methodContext.getEnvMap());
if (toList == null) {
toList = new LinkedList<Object>();
listFma.put(methodContext.getEnvMap(), toList);
}
toList.add(value);
return true;
}
protected String outputFiles(Map map, MessageFormat format, boolean first) {
StringBuffer sb = new StringBuffer();
for (Iterator i=map.entrySet().iterator();i.hasNext();) {
Map.Entry entry = (Map.Entry)i.next();
if (!first) {
sb.append(',');
}
else {
first = false;
}
format.format(new Object[]{entry.getValue(), entry.getKey()}, sb, null);
}
return sb.toString();
}
/**
* Validates the contents of the dialog's input fields. If the selected file exists, it is also checked for validity.
*
* @return true, if the input is valid, false otherwise
*/
public boolean performValidate() {
getStatusBar().clear();
final String filename = getFilename();
if ( filename.trim().length() == 0 ) {
getStatusBar().setStatus( StatusType.ERROR, getResources().getString( "excelexportdialog.targetIsEmpty" ) ); //$NON-NLS-1$
return false;
}
final File f = new File( filename );
if ( f.exists() ) {
if ( f.isFile() == false ) {
getStatusBar().setStatus( StatusType.ERROR, getResources().getString( "excelexportdialog.targetIsNoFile" ) ); //$NON-NLS-1$
return false;
}
if ( f.canWrite() == false ) {
getStatusBar()
.setStatus( StatusType.ERROR, getResources().getString( "excelexportdialog.targetIsNotWritable" ) ); //$NON-NLS-1$
return false;
}
final String message = MessageFormat.format( getResources().getString( "excelexportdialog.targetExistsWarning" ), //$NON-NLS-1$
new Object[] { filename } );
getStatusBar().setStatus( StatusType.WARNING, message );
}
return true;
}
protected void unexpectedX(String token) throws SAXException {
throw new SAXParseException(MessageFormat.format(
"Unexpected {0} appears at line {1} column {2}",
new Object[]{
token,
new Integer(getLocator().getLineNumber()),
new Integer(getLocator().getColumnNumber()) }),
getLocator());
}
@Override
public WritableByteChannel append() throws IOException {
PooledFTPConnection connection = connect(uri);
Info info = info(uri, connection.getFtpClient());
if ((info != null) && info.isDirectory()) {
throw new IOException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.exists_not_file"), uri)); //$NON-NLS-1$
}
return Channels.newChannel(connection.getOutputStream(getPath(uri), WriteMode.APPEND));
}
@Test
public void generatingACredential_returnsAnErrorMessageForUnknownType() throws Exception {
String message = MessageFormat.format(ErrorMessages.INVALID_TYPE_WITH_GENERATE_PROMPT, new Object[0]);
final MockHttpServletRequestBuilder postRequest = post("/api/v1/data")
.header("Authorization", "Bearer " + ALL_PERMISSIONS_TOKEN)
.accept(APPLICATION_JSON)
.contentType(APPLICATION_JSON)
.content("{\"type\":\"foo\",\"name\":\"" + CREDENTIAL_NAME + "\"}");
mockMvc.perform(postRequest)
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON))
.andExpect(jsonPath("$.error").value(message));
}
/**
* Deletes an entry from the keystore.
*/
private void doDeleteEntry(String alias) throws Exception {
if (keyStore.containsAlias(alias) == false) {
MessageFormat form = new MessageFormat
(rb.getString("Alias.alias.does.not.exist"));
Object[] source = {alias};
throw new Exception(form.format(source));
}
keyStore.deleteEntry(alias);
}
@Override
public String getLocalizedMessage() {
String message = getBundleDefaultMessage();
return MessageFormat.format(message,mQuery.getName());
}
public static String ERROR_ProjectDoesNotHaveSrcFolder(Location location) {
return MessageFormat.format("Error, using location `{0}` as a Go workspace, "
+ "but location does not contain a `src` directory. ", location);
}
public String getPartitionConsumerReturnOffsetPath(int poolId, String topic, int partition, String consumer) {
return MessageFormat.format(PARTITION_CONSUMER_RETURN_OFFSET, rootPath, poolId, topic, partition, consumer);
}
@Override
protected String getCandidacyInformationLinkEnglish() {
String message = getStringFromDefaultBundle("link.candidacy.information.english.degreeChange");
return MessageFormat.format(message, Installation.getInstance().getInstituitionURL());
}
/**
* Handle add remote.
*/
private void handleAddRemote() {
String sDescriptorPath = editor.getFile().getParent().getLocation().toString() + '/';
AddRemoteServiceDialog dialog = new AddRemoteServiceDialog(this, sDescriptorPath);
dialog.open();
if (dialog.getReturnCode() == Window.CANCEL)
return;
String sServiceType = dialog.getSelectedServiceTypeName();
if (sServiceType != null &&
!sServiceType.equals("UIMA-AS JMS") &&
!sServiceType.equals("SOAP") &&
!sServiceType.equals("Vinci")) {
return;
}
String sURI = dialog.getSelectedUri();
String sKey = dialog.getSelectedKey();
if (!isNewKey(sKey)) {
Utility.popMessage("Duplicate Key", "You have specified a duplicate key. Please try again.",
MessageDialog.ERROR);
return;
}
PrintWriter printWriter = setupToPrintFile(dialog.genFilePath);
if (null != printWriter) {
if (!sServiceType.equals("UIMA-AS JMS")) {
String vnsHostPort = "";
if (dialog.vnsHost.length() > 0) {
vnsHostPort = MessageFormat.format(" <parameter name=\"VNS_HOST\" value=\"{0}\"/>\n",
new Object[] { dialog.vnsHost });
}
if (dialog.vnsPort.length() > 0) {
vnsHostPort += MessageFormat.format(" <parameter name=\"VNS_PORT\" value=\"{0}\"/>\n",
new Object[] { dialog.vnsPort });
}
if (vnsHostPort.length() > 0)
vnsHostPort = "\n <parameters>" + vnsHostPort + " </parameters>";
printWriter.println(MessageFormat.format(REMOTE_TEMPLATE, new Object[] { dialog.aeOrCc, sURI,
sServiceType, dialog.timeout, vnsHostPort }));
} else {
// is UIMA-AS JMS
StringBuilder sb = new StringBuilder();
addParam(sb, "timeout", dialog.timeout);
addParam(sb, "getmetatimeout", dialog.getmetaTimeout);
addParam(sb, "cpctimeout", dialog.cpcTimeout);
addParam(sb, "binary_serialization", dialog.binary_serialization);
addParam(sb, "ignore_process_errors", dialog.ignore_process_errors);
printWriter.println(MessageFormat.format(REMOTE_JMS_TEMPLATE, new Object[] {
sURI, // brokerUrl
dialog.endpoint, // endpoint
sb.toString()
}));
}
printWriter.close();
boolean bSuccess = addDelegate(dialog.genFilePath, sKey, sKey, dialog.isImportByName);
if (bSuccess) {
boolean bAutoAddToFlow = dialog.getAutoAddToFlow();
if (bAutoAddToFlow) {
addNodeToFlow(sKey);
}
refresh();
}
}
}
/**
* Reads a policy configuration into the Policy object using a
* Reader object. <p>
*
* @param policy the policy Reader object.
*
* @exception ParsingException if the policy configuration contains
* a syntax error.
*
* @exception IOException if an error occurs while reading the policy
* configuration.
*/
public void read(Reader policy)
throws ParsingException, IOException
{
if (!(policy instanceof BufferedReader)) {
policy = new BufferedReader(policy);
}
/**
* Configure the stream tokenizer:
* Recognize strings between "..."
* Don't convert words to lowercase
* Recognize both C-style and C++-style comments
* Treat end-of-line as white space, not as a token
*/
st = new StreamTokenizer(policy);
st.resetSyntax();
st.wordChars('a', 'z');
st.wordChars('A', 'Z');
st.wordChars('.', '.');
st.wordChars('0', '9');
st.wordChars('_', '_');
st.wordChars('$', '$');
st.wordChars(128 + 32, 255);
st.whitespaceChars(0, ' ');
st.commentChar('/');
st.quoteChar('\'');
st.quoteChar('"');
st.lowerCaseMode(false);
st.ordinaryChar('/');
st.slashSlashComments(true);
st.slashStarComments(true);
/**
* The main parsing loop. The loop is executed once
* for each entry in the config file. The entries
* are delimited by semicolons. Once we've read in
* the information for an entry, go ahead and try to
* add it to the policy vector.
*
*/
lookahead = st.nextToken();
GrantEntry ge = null;
while (lookahead != StreamTokenizer.TT_EOF) {
if (peek("grant")) {
ge = parseGrantEntry();
// could be null if we couldn't expand a property
if (ge != null)
add(ge);
} else if (peek("keystore") && keyStoreUrlString==null) {
// only one keystore entry per policy file, others will be
// ignored
parseKeyStoreEntry();
} else if (peek("keystorePasswordURL") && storePassURL==null) {
// only one keystore passwordURL per policy file, others will be
// ignored
parseStorePassURL();
} else if (ge == null && keyStoreUrlString == null &&
storePassURL == null && peek("domain")) {
if (domainEntries == null) {
domainEntries = new TreeMap<>();
}
DomainEntry de = parseDomainEntry();
if (de != null) {
String domainName = de.getName();
if (!domainEntries.containsKey(domainName)) {
domainEntries.put(domainName, de);
} else {
MessageFormat form =
new MessageFormat(ResourcesMgr.getString(
"duplicate.keystore.domain.name"));
Object[] source = {domainName};
throw new ParsingException(form.format(source));
}
}
} else {
// error?
}
match(";");
}
if (keyStoreUrlString == null && storePassURL != null) {
throw new ParsingException(ResourcesMgr.getString
("keystorePasswordURL.can.not.be.specified.without.also.specifying.keystore"));
}
}
private static String toClassDisplayName(File inputFile, String basicTestName, String generalTestName) {
return MessageFormat.format(Messages.GenerateTestsMojo_12, inputFile.getName(), basicTestName, generalTestName,
inputFile.getParentFile().getPath());
}
private static String format(String property, Object... args) {
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
return MessageFormat.format(text, args);
}
public QualifierNotExistsException(long id) {
super(MessageFormat.format("Qualifier with {0} id not exists", id));
}
public static String getMessage (String key, String fill)
{
Object[] args = { fill };
return MessageFormat.format(fBundle.getString(key), args);
}
public UnsealConnectorException(UnsealConnectorExceptionValues errorCodeValue, CryptoResult<?> result, Object... params) {
super(MessageFormat.format(errorCodeValue.getMessage(), params), errorCodeValue.getErrorCode());
this.result = result;
}
public static String getMessage (String key, String fill)
{
Object[] args = { fill };
return MessageFormat.format(fBundle.getString(key), args);
}
public IntraHubBusinessConnectorException(IntraHubBusinessConnectorExceptionValues errorCodeValue, Throwable e, Object... params) {
super(MessageFormat.format(errorCodeValue.getMessage(), params), errorCodeValue.getErrorCode(), e);
}