18 package org.turro.wd.files;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.OutputStreamWriter;
24 import java.text.ParseException;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.jdom.Document;
28 import org.jdom.Element;
29 import org.jdom.JDOMException;
30 import org.jdom.input.SAXBuilder;
31 import org.jdom.output.Format;
32 import org.jdom.output.XMLOutputter;
40 public static final String
42 WD_CONF_ROOT =
"/.BBWDConf",
43 WD_CACHE =
"/.BBWorkDir.cache";
45 private String bbUser, bbHost, bbPort, bbContext;
46 private File wdHome, wdInternal, wdCache;
48 public WorkingDirectory(String bbUser, String bbHost, String bbPort, String bbContext) {
52 this.bbContext = bbContext;
56 return bbContext ==
null ?
"" : bbContext;
71 public void initialize(String bbCreateDir, String bbCreatePath)
throws ParseException {
72 wdHome =
new File(System.getProperty(
"user.home") +
WD_ROOT +
"/" + bbHost);
73 if(!wdHome.exists()) {
76 wdInternal =
new File(wdHome.getAbsolutePath() + WD_CONF_ROOT);
77 if(!wdInternal.exists()) {
80 wdCache =
new File(wdInternal.getAbsolutePath() + WD_CACHE);
84 if(bbCreateDir !=
null) {
97 public void reload() throws ParseException {
110 return wdHome.getAbsolutePath();
113 private void initializeCache() throws ParseException {
114 SAXBuilder builder =
new SAXBuilder();
117 if(wdCache.exists()) {
118 doc = builder.build(wdCache);
121 }
catch (IOException ex) {
122 Logger.getLogger(
WorkingDirectory.class.getName()).log(Level.SEVERE,
null, ex);
123 }
catch (JDOMException ex) {
124 Logger.getLogger(
WorkingDirectory.class.getName()).log(Level.SEVERE,
null, ex);
129 Document doc =
new Document(
new Element(
"bb-working-directory"));
132 OutputStreamWriter fw =
new OutputStreamWriter(
new FileOutputStream(wdCache),
"UTF-8");
133 Format fm = Format.getPrettyFormat();
134 fm.setEncoding(
"UTF-8");
135 XMLOutputter xo =
new XMLOutputter(fm);
138 }
catch (IOException ex) {
Directory getDir(String dir)
void writeXML(Element root)
Directory addDirectory(String name)
void readXML(Element root)
void setServerPath(String serverPath)
static final String WD_ROOT
void initialize(String bbCreateDir, String bbCreatePath)
WorkingDirectory(String bbUser, String bbHost, String bbPort, String bbContext)