-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.java
More file actions
88 lines (68 loc) · 2.52 KB
/
Copy path17.java
File metadata and controls
88 lines (68 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package it.uniroma1.dis.wsngroup.gexf4j.core.impl.writer;
import static com.google.common.base.Preconditions.checkArgument;
import it.uniroma1.dis.wsngroup.gexf4j.core.dynamic.TimeFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public abstract class AbstractEntityWriter<T extends Object> {
protected static String writerTimeType = TimeFormat.DOUBLE;
protected static String toDouble(Object number) {
String returnValue = null;
if (number instanceof Double) {
Double n = (Double) number;
returnValue = String.valueOf(n);
}
return returnValue;
}
protected static String toInteger(Object number) {
String returnValue = null;
if (number instanceof Integer) {
Integer n = (Integer) number;
returnValue = String.valueOf(n);
}
return returnValue;
}
protected String toDateString(Object date) {
String returnValue = null;
if (date instanceof Date) {
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
Date d = (Date) date;
returnValue = sdfDate.format(d);
}
return returnValue;
}
protected String toDateTimeString(Object date) {
String returnValue = null;
if (date instanceof Date) {
SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date d = (Date) date;
returnValue = sdfDateTime.format(d);
}
return returnValue;
}
protected XMLStreamWriter writer = null;
protected T entity = null;
protected abstract String getElementName();
protected abstract void writeAttributes() throws XMLStreamException;
protected abstract void writeElements() throws XMLStreamException;
public AbstractEntityWriter(XMLStreamWriter writer, T entity) {
checkArgument(writer != null, "XML Writer cannot be null.");
checkArgument(entity != null, "Entity cannot be null.");
this.writer = writer;
this.entity = entity;
}
protected void write() {
try {
writeStartElement();
writeAttributes();
writeElements();
writer.writeEndElement();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
protected void writeStartElement() throws XMLStreamException {
writer.writeStartElement(getElementName());
}
}