use of java.text.MessageFormat in project pcgen by PCGen.
the class InfoModel method get.
/**
* Acts as a hash for producing the contents of this model.
*
* @see freemarker.template.TemplateHashModel#get(java.lang.String)
*/
@Override
public TemplateModel get(String key) throws TemplateModelException {
CaseInsensitiveString cis = new CaseInsensitiveString(key);
MessageFormat info = cdo.get(MapKey.INFO, cis);
StringBuffer sb = new StringBuffer(100);
if (info != null) {
info.format(getVars(cis), sb, null);
} else {
//TODO: This should actually throw an error but we can't for
//now due to it breaking too many thing...
//So we are just logging it for now.
//--Connor Petty
Logging.errorPrint("CDOMObject [" + cdo.getDisplayName() + "] does not have INFO of type " + key);
// throw new TemplateModelException(
// "CDOMObject did not have INFO of type " + key);
}
return FacetLibrary.getFacet(ObjectWrapperFacet.class).wrap(id, sb.toString());
}
use of java.text.MessageFormat in project tdi-studio-se by Talend.
the class RunProcessContext method displayJobEndMessage.
/**
* DOC yexiaowei Comment method "displayJobEndMessage".
*
* @param exitCode
*/
private void displayJobEndMessage(int exitCode) {
//$NON-NLS-1$
final String endingPattern = Messages.getString("ProcessComposite.endPattern");
MessageFormat mf = new MessageFormat(endingPattern);
String byeMsg = mf.format(new Object[] { process.getLabel(), new Date(), new Integer(exitCode) });
//$NON-NLS-1$ //$NON-NLS-2$
byeMsg = (processMessageManager.isLastMessageEndWithCR() ? "" : "\n") + byeMsg;
processMessageManager.addMessage(new ProcessMessage(MsgType.CORE_OUT, byeMsg));
}
use of java.text.MessageFormat in project intellij-community by JetBrains.
the class GroovyGenerateEqualsHelper method initPrimitiveHashcodeFormats.
@SuppressWarnings("HardCodedStringLiteral")
private static void initPrimitiveHashcodeFormats() {
PRIMITIVE_HASHCODE_FORMAT.put("byte", new MessageFormat("(int) {0}"));
PRIMITIVE_HASHCODE_FORMAT.put("short", new MessageFormat("(int) {0}"));
PRIMITIVE_HASHCODE_FORMAT.put("int", new MessageFormat("{0}"));
PRIMITIVE_HASHCODE_FORMAT.put("long", new MessageFormat("(int) ({0} ^ ({0} >>> 32))"));
PRIMITIVE_HASHCODE_FORMAT.put("boolean", new MessageFormat("({0} ? 1 : 0)"));
PRIMITIVE_HASHCODE_FORMAT.put("float", new MessageFormat("({0} != +0.0f ? Float.floatToIntBits({0}) : 0)"));
PRIMITIVE_HASHCODE_FORMAT.put("double", new MessageFormat("(int) ({1} ^ ({1} >>> 32))"));
PRIMITIVE_HASHCODE_FORMAT.put("char", new MessageFormat("(int) {0}"));
PRIMITIVE_HASHCODE_FORMAT.put("void", new MessageFormat("0"));
PRIMITIVE_HASHCODE_FORMAT.put("void", new MessageFormat("({0} ? 1 : 0)"));
}
use of java.text.MessageFormat in project pcgen by PCGen.
the class Tips method writePOT.
private static void writePOT(Iterable<String> tips, Writer bw) throws IOException {
// header stuff
Calendar now = Calendar.getInstance();
bw.write("msgid \"\"\n" + "msgstr \"\"\n" + "\"Project-Id-Version: PCGen-tips 6.x/SVN?\\n\"\n" + "\"Report-Msgid-Bugs-To: \\n\"\n" + "\"POT-Creation-Date: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now) + "\\n\"\n" + "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" + "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" + "\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n" + "\"MIME-Version: 1.0\\n\"\n" + "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" + "\"Content-Transfer-Encoding: 8bit\\n\"\n\n");
// filecontent
//$NON-NLS-1$
Format msgid = new MessageFormat("msgid \"{0}\"");
//$NON-NLS-1$
String msgstr = "msgstr \"\"";
for (String tip : tips) {
bw.write(msgid.format(new Object[] { escape(tip) }));
bw.write("\n");
bw.write(msgstr);
bw.write("\n\n");
}
}
use of java.text.MessageFormat in project pcgen by PCGen.
the class InfoLst method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject cdo, String value) {
if (value.charAt(0) == '|') {
return new ParseResult.Fail(getTokenName() + " arguments may not start with PIPE : " + value);
}
if (value.charAt(value.length() - 1) == '|') {
return new ParseResult.Fail(getTokenName() + " arguments may not end with PIPE : " + value);
}
int pipeLoc = value.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
return new ParseResult.Fail(getTokenName() + " expecting '|', format is: InfoName|Info value was: " + value, context);
}
String key = value.substring(0, pipeLoc);
//key length 0 caught by charAt(0) test above
String val = value.substring(pipeLoc + 1);
if (val.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " expecting non-empty value, " + "format is: InfoName|Info value was: " + value, context);
}
if (val.startsWith(Constants.PIPE)) {
return new ParseResult.Fail(getTokenName() + " expecting non-empty value, " + "format is: InfoName|Info value was: " + value, context);
}
try {
MessageFormat mf = new MessageFormat(val);
CaseInsensitiveString cis = new CaseInsensitiveString(key);
context.getObjectContext().put(cdo, MapKey.INFO, cis, mf);
} catch (IllegalArgumentException e) {
return new ParseResult.Fail(getTokenName() + " expected a valid MessageFormat, but received error: " + e.getMessage() + " when parsing: " + value, context);
}
return ParseResult.SUCCESS;
}
Aggregations