Skip to content

Commit 545c79e

Browse files
author
Alexander Lippling
committed
Added support for date
Change-Id: I1dbc2fcd2d1a79e5e8126ba398daac47bdad489b
1 parent a8f5add commit 545c79e

File tree

11 files changed

+135
-4
lines changed

11 files changed

+135
-4
lines changed

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/Array.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package com.sap.prd.mobile.ios.mios.xcodeprojreader;
2121

22+
import java.util.Date;
2223
import java.util.List;
2324

2425
public interface Array extends List<Object>
@@ -47,6 +48,12 @@ public interface Array extends List<Object>
4748

4849
void setBool(int index, Boolean value);
4950

51+
Date getDate(int index);
52+
53+
void setDate(int index, Date value);
54+
55+
void addDate(Date value);
56+
5057
Dict getDict(int index);
5158

5259
void addDict(Dict value);

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/Dict.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package com.sap.prd.mobile.ios.mios.xcodeprojreader;
2121

22+
import java.util.Date;
2223
import java.util.Map;
2324

2425
public interface Dict extends Map<String, Object>
@@ -39,6 +40,10 @@ public interface Dict extends Map<String, Object>
3940

4041
void setBool(String key, Boolean value);
4142

43+
Date getDate(String key);
44+
45+
void setDate(String key, Date value);
46+
4247
Array getArray(String key);
4348

4449
Array getOrCreateAndSetArray(String key);

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/ArrayListArray.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb;
2121

2222
import java.util.ArrayList;
23+
import java.util.Date;
2324

2425
import com.sap.prd.mobile.ios.mios.xcodeprojreader.Array;
2526
import com.sap.prd.mobile.ios.mios.xcodeprojreader.Dict;
@@ -100,6 +101,24 @@ public void setBool(int index, Boolean value)
100101
set(index, value);
101102
}
102103

104+
@Override
105+
public Date getDate(int index)
106+
{
107+
return (Date) get(index);
108+
}
109+
110+
@Override
111+
public void setDate(int index, Date value)
112+
{
113+
set(index, value);
114+
}
115+
116+
@Override
117+
public void addDate(Date value)
118+
{
119+
add(value);
120+
}
121+
103122
@Override
104123
public Dict getDict(int index)
105124
{

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/JAXBArray.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class JAXBArray
4040
@XmlElement(name = "integer", type = Integer.class),
4141
@XmlElement(name = "real", type = Double.class),
4242
@XmlElement(name = "true", type = JAXBTrue.class),
43-
@XmlElement(name = "false", type = JAXBFalse.class)
43+
@XmlElement(name = "false", type = JAXBFalse.class),
44+
@XmlElement(name = "date", type = JAXBDate.class)
4445
})
4546
public Array getElements()
4647
{
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* #%L
3+
* xcode-project-reader
4+
* %%
5+
* Copyright (C) 2012 SAP AG
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb;
21+
22+
import javax.xml.bind.annotation.XmlType;
23+
import javax.xml.bind.annotation.XmlValue;
24+
25+
@XmlType(name = "date")
26+
public class JAXBDate
27+
{
28+
private String value;
29+
30+
@XmlValue
31+
public String getValue()
32+
{
33+
return value;
34+
}
35+
36+
void setValue(String value)
37+
{
38+
this.value = value;
39+
}
40+
}

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/JAXBDict.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public class JAXBDict
3939
@XmlElement(name = "integer", type = Integer.class),
4040
@XmlElement(name = "real", type = Double.class),
4141
@XmlElement(name = "true", type = JAXBTrue.class),
42-
@XmlElement(name = "false", type = JAXBFalse.class)
42+
@XmlElement(name = "false", type = JAXBFalse.class),
43+
@XmlElement(name = "date", type = JAXBDate.class)
4344
})
4445
public Array getElements()
4546
{

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/JAXBPlistElementConverter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
*/
2020
package com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb;
2121

22+
import java.text.SimpleDateFormat;
23+
import java.util.Date;
24+
import java.util.TimeZone;
25+
26+
import javax.xml.bind.DatatypeConverter;
27+
2228
import com.sap.prd.mobile.ios.mios.xcodeprojreader.Array;
2329
import com.sap.prd.mobile.ios.mios.xcodeprojreader.Dict;
2430

@@ -27,10 +33,13 @@ public class JAXBPlistElementConverter
2733
private final JAXBDictAdapter dictAdapter;
2834
private final JAXBArrayAdapter arrayAdapter;
2935

36+
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
37+
3038
public JAXBPlistElementConverter(JAXBDictAdapter dictAdapter, JAXBArrayAdapter arrayAdapter)
3139
{
3240
this.dictAdapter = dictAdapter;
3341
this.arrayAdapter = arrayAdapter;
42+
format.setTimeZone(TimeZone.getTimeZone("UTC"));
3443
}
3544

3645
public Object convertFromJAXB(Object value) throws Exception
@@ -51,6 +60,11 @@ else if (value instanceof JAXBFalse)
5160
{
5261
value = Boolean.FALSE;
5362
}
63+
else if (value instanceof JAXBDate)
64+
{
65+
JAXBDate date = (JAXBDate) value;
66+
value = DatatypeConverter.parseDateTime(date.getValue()).getTime();
67+
}
5468
return value;
5569
}
5670

@@ -68,6 +82,12 @@ else if (value instanceof Boolean)
6882
{
6983
value = ((Boolean) value) ? new JAXBTrue() : new JAXBFalse();
7084
}
85+
else if (value instanceof Date)
86+
{
87+
JAXBDate date = new JAXBDate();
88+
date.setValue(format.format((Date) value));
89+
value = date;
90+
}
7191
return value;
7292
}
7393
}

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/JAXBPlistParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import com.sap.prd.mobile.ios.mios.xcodeprojreader.Plist;
4343

44-
// TODO unsupported element types: Date, Data
44+
// TODO unsupported element type: Data
4545
public class JAXBPlistParser
4646
{
4747
public Plist load(String projectFile) throws SAXException, ParserConfigurationException, FileNotFoundException,

src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/LinkedHashMapDict.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb;
2121

22+
import java.util.Date;
2223
import java.util.LinkedHashMap;
2324

2425
import com.sap.prd.mobile.ios.mios.xcodeprojreader.Array;
@@ -76,6 +77,18 @@ public void setBool(String key, Boolean value)
7677
put(key, value);
7778
}
7879

80+
@Override
81+
public Date getDate(String key)
82+
{
83+
return (Date) get(key);
84+
}
85+
86+
@Override
87+
public void setDate(String key, Date value)
88+
{
89+
put(key, value);
90+
}
91+
7992
@Override
8093
public Array getArray(String key)
8194
{

src/test/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/DataTypesTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import static org.junit.Assert.assertNull;
2525
import static org.junit.Assert.assertTrue;
2626

27+
import java.util.Date;
28+
29+
import javax.xml.bind.DatatypeConverter;
30+
2731
import org.junit.Before;
2832
import org.junit.Test;
2933

@@ -117,6 +121,24 @@ public void boolInArray()
117121
assertEquals(true, array.getBool(6));
118122
}
119123

124+
@Test
125+
public void dateInDict()
126+
{
127+
assertEquals(DatatypeConverter.parseDateTime("2012-05-31T14:38:28Z").getTime(), dict.getDate("date"));
128+
Date newDate = DatatypeConverter.parseDateTime("2015-05-31T14:38:28Z").getTime();
129+
dict.setDate("date", newDate);
130+
assertEquals(newDate, dict.getDate("date"));
131+
}
132+
133+
@Test
134+
public void dateInArray()
135+
{
136+
assertEquals(DatatypeConverter.parseDateTime("2012-05-31T14:38:28Z").getTime(), array.getDate(7));
137+
Date newDate = DatatypeConverter.parseDateTime("2015-05-31T14:38:28Z").getTime();
138+
array.setDate(7, newDate);
139+
assertEquals(newDate, array.getDate(7));
140+
}
141+
120142
@Test
121143
public void dictInDict()
122144
{
@@ -153,7 +175,7 @@ public void dictInArrayNonExistingIndex()
153175
public void getOrCreateAndSetArrayInDict()
154176
{
155177
Array array = dict.getOrCreateAndSetArray("arraytest");
156-
assertEquals(7, array.size());
178+
assertEquals(8, array.size());
157179
assertEquals("value", array.get(0));
158180
}
159181

0 commit comments

Comments
 (0)