19 package org.turro.erp.time;
22 import java.io.IOException;
23 import java.io.OutputStreamWriter;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.TreeSet;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import org.turro.string.ObjectString;
30 import org.turro.string.Strings;
31 import org.jdom.Document;
32 import org.jdom.Element;
33 import org.jdom.JDOMException;
34 import org.jdom.input.SAXBuilder;
35 import org.jdom.output.Format;
36 import org.jdom.output.XMLOutputter;
37 import org.turro.elephant.context.ElephantContext;
38 import org.turro.elephant.context.IConstructor;
39 import org.turro.elephant.impl.util.FileUtil;
52 this.constructor = constructor;
57 Document doc =
new Document(
new Element(
"time-controls"));
58 writeXML(doc.getRootElement());
62 Format fm = Format.getPrettyFormat();
64 XMLOutputter xo =
new XMLOutputter(fm);
67 }
catch (IOException ex) {
77 org.amic.util.file.FileUtil.copyFile(confFile, copseg.getAbsolutePath());
78 }
catch (IOException ex) {
83 private void loadCollection() {
84 SAXBuilder builder =
new SAXBuilder();
88 if(confFile.exists()) {
89 doc = builder.build(confFile);
90 readXML(doc.getRootElement());
92 }
catch (IOException ex) {
93 Logger.getLogger(XMLHumanResourceSet.class.getName()).log(Level.SEVERE,
null, ex);
94 }
catch (JDOMException ex) {
95 Logger.getLogger(XMLHumanResourceSet.class.getName()).log(Level.SEVERE,
null, ex);
99 private void writeXML(Element rootElement) {
100 for(XMLTimeControl tc :
this) {
101 Element el =
new Element(
"time-control");
102 el.setAttribute(
"human-resource-id", tc.getHumanResourceId() +
"");
103 if(tc.getStartTime() !=
null) {
104 el.setAttribute(
"start-time",
105 ObjectString.formatObject(tc.getStartTime(), ObjectString.COMPRESSED_DATE_PATTERN,
false));
106 if(tc.getEndTime() !=
null) {
107 el.setAttribute(
"end-time",
108 ObjectString.formatObject(tc.getEndTime(), ObjectString.COMPRESSED_DATE_PATTERN,
false));
110 rootElement.addContent(el);
115 private void readXML(Element rootElement) {
117 for(Element el : (List<Element>) rootElement.getChildren(
"time-control")) {
118 XMLTimeControl tc =
new XMLTimeControl();
119 tc.setHumanResourceId((Long) ObjectString.parseString(el.getAttributeValue(
"human-resource-id"), Long.class,
false));
120 if(!Strings.isBlank(el.getAttributeValue(
"start-time"))) {
121 tc.setStartTime((Date) ObjectString.parseString(el.getAttributeValue(
"start-time"),
122 ObjectString.COMPRESSED_DATE_PATTERN, Date.class,
false));
124 if(!Strings.isBlank(el.getAttributeValue(
"end-time"))) {
125 tc.setEndTime((Date) ObjectString.parseString(el.getAttributeValue(
"end-time"),
126 ObjectString.COMPRESSED_DATE_PATTERN, Date.class,
false));
128 if(tc.getStartTime() !=
null) {
static String getRealPath(String path)
static String getEncoding()
static OutputStreamWriter getFileWriter(String folder, String file)
static File getFolderFile(File file)
String getName(XMLTimeControl tc)
XMLTimeControlSet(IConstructor constructor)
static final String XML_TIMECONTROL