MCPcopy Create free account
hub / github.com/PCGen/pcgen / SourcedateLst

Class SourcedateLst

code/src/java/plugin/lsttokens/SourcedateLst.java:37–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35import pcgen.util.Logging;
36
37public class SourcedateLst extends AbstractNonEmptyToken<CDOMObject>
38 implements CDOMPrimaryToken<CDOMObject>, InstallLstToken
39{
40
41 @Override
42 public String getTokenName()
43 {
44 return "SOURCEDATE";
45 }
46
47 @Override
48 protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value)
49 {
50 Date theDate = getDate(value);
51 if (theDate == null)
52 {
53 return ParseResult.INTERNAL_ERROR;
54 }
55 context.getObjectContext().put(obj, ObjectKey.SOURCE_DATE, theDate);
56 return ParseResult.SUCCESS;
57 }
58
59 private static Date getDate(String value)
60 {
61 DateFormat df = new SimpleDateFormat("yyyy-MM", Locale.ROOT); //$NON-NLS-1$
62 Date theDate;
63 try
64 {
65 theDate = df.parse(value);
66 }
67 catch (ParseException pe)
68 {
69 df = DateFormat.getDateInstance();
70 try
71 {
72 theDate = df.parse(value);
73 }
74 catch (ParseException e)
75 {
76 try
77 {
78 DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy", Locale.ROOT);
79 theDate = formatter.parse(value);
80 }
81 catch (ParseException ipe)
82 {
83 Logging.log(Logging.LST_ERROR, "Error parsing date", ipe);
84 return null;
85 }
86 }
87 }
88 return theDate;
89 }
90
91 @Override
92 public String[] unparse(LoadContext context, CDOMObject obj)
93 {
94 Date date = context.getObjectContext().getObject(obj, ObjectKey.SOURCE_DATE);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected