This commit is contained in:
Christian P. MOMON 2013-06-28 14:40:16 +02:00
parent fe1bb291cd
commit 16c24fa114
26 changed files with 5424 additions and 5424 deletions

View file

@ -1,3 +1,3 @@
Manifest-Version: 1.0
Class-Path:
Manifest-Version: 1.0
Class-Path:

View file

@ -1,242 +1,242 @@
/**
* @author Christian Momon, June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
/**
* This class defines a content file.
*
*/
public class DataFile
{
static public int NOID = 0;
static public int DEFAULT_SIZE = 0;
//
protected int id;
protected int contentId;
protected String name;
protected long size;
protected byte[] data;
protected String creationDate;
protected String creationUser;
/**
*
*/
public DataFile()
{
this.id = NOID;
this.contentId = NOID;
this.name = null;
this.size = DEFAULT_SIZE;
this.data = null;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public DataFile(final int contentId, final String name, final long size, final byte[] data)
{
this.id = NOID;
this.contentId = contentId;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public DataFile(final String name, final long size, final byte[] data)
{
this.id = NOID;
this.contentId = NOID;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public int contentId()
{
int result;
result = this.contentId;
//
return (result);
}
/**
*
*/
public String creationDate()
{
String result;
result = this.creationDate;
//
return (result);
}
/**
*
*/
public String creationUser()
{
String result;
result = this.creationUser;
//
return (result);
}
/**
*
*/
public byte[] data()
{
byte[] result;
result = this.data;
//
return (result);
}
/**
*
*/
public int id()
{
int result;
result = this.id;
//
return (result);
}
/**
*
*/
public String name()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public void setContentId(final int contentId)
{
this.contentId = contentId;
}
/**
*
*/
public void setCreationDate(final String creationDate)
{
if (creationDate == null)
{
this.creationDate = "";
}
else
{
this.creationDate = creationDate;
}
}
/**
*
*/
public void setCreationUser(final String creationUser)
{
if (creationUser == null)
{
this.creationUser = "";
}
else
{
this.creationUser = creationUser;
}
}
/**
*
*/
public void setData(final byte[] data)
{
this.data = data;
}
/**
*
*/
public void setId(final int id)
{
this.id = id;
}
/**
*
*/
public void setName(final String name)
{
if (name == null)
{
this.name = "";
}
else
{
this.name = name;
}
}
/**
*
*/
public void setSize(final long size)
{
if (size >= 0)
{
this.size = size;
}
else
{
this.size = 0;
}
}
/**
*
*/
public long size()
{
long result;
result = this.size;
//
return (result);
}
}
/**
* @author Christian Momon, June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
/**
* This class defines a content file.
*
*/
public class DataFile
{
static public int NOID = 0;
static public int DEFAULT_SIZE = 0;
//
protected int id;
protected int contentId;
protected String name;
protected long size;
protected byte[] data;
protected String creationDate;
protected String creationUser;
/**
*
*/
public DataFile()
{
this.id = NOID;
this.contentId = NOID;
this.name = null;
this.size = DEFAULT_SIZE;
this.data = null;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public DataFile(final int contentId, final String name, final long size, final byte[] data)
{
this.id = NOID;
this.contentId = contentId;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public DataFile(final String name, final long size, final byte[] data)
{
this.id = NOID;
this.contentId = NOID;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public int contentId()
{
int result;
result = this.contentId;
//
return (result);
}
/**
*
*/
public String creationDate()
{
String result;
result = this.creationDate;
//
return (result);
}
/**
*
*/
public String creationUser()
{
String result;
result = this.creationUser;
//
return (result);
}
/**
*
*/
public byte[] data()
{
byte[] result;
result = this.data;
//
return (result);
}
/**
*
*/
public int id()
{
int result;
result = this.id;
//
return (result);
}
/**
*
*/
public String name()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public void setContentId(final int contentId)
{
this.contentId = contentId;
}
/**
*
*/
public void setCreationDate(final String creationDate)
{
if (creationDate == null)
{
this.creationDate = "";
}
else
{
this.creationDate = creationDate;
}
}
/**
*
*/
public void setCreationUser(final String creationUser)
{
if (creationUser == null)
{
this.creationUser = "";
}
else
{
this.creationUser = creationUser;
}
}
/**
*
*/
public void setData(final byte[] data)
{
this.data = data;
}
/**
*
*/
public void setId(final int id)
{
this.id = id;
}
/**
*
*/
public void setName(final String name)
{
if (name == null)
{
this.name = "";
}
else
{
this.name = name;
}
}
/**
*
*/
public void setSize(final long size)
{
if (size >= 0)
{
this.size = size;
}
else
{
this.size = 0;
}
}
/**
*
*/
public long size()
{
long result;
result = this.size;
//
return (result);
}
}

View file

@ -1,167 +1,167 @@
/**
* @author Christian Momon, June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.ArrayList;
/**
* This class is a collection of DataFile objects whit some specific methods.
*
*/
public class DataFiles extends ArrayList<DataFile>
{
private static final long serialVersionUID = -4584622422555785456L;
/**
*
*
*/
public DataFiles()
{
super();
}
/**
*
* @param source
*/
public DataFiles(final DataFiles source)
{
super(source);
}
/**
*
*/
public DataFiles getByContentId(final int id)
{
DataFiles result = new DataFiles();
for (int nDataFile = 0; nDataFile < this.size(); nDataFile++)
{
DataFile contentFile = this.getByIndex(nDataFile);
if (contentFile.contentId() == id)
{
result.add(contentFile);
}
}
//
return (result);
}
/**
*
*/
public DataFile getById(final int id)
{
DataFile result = null;
boolean ended = false;
int nDataFile = 0;
while (!ended)
{
if (nDataFile >= this.size())
{
ended = true;
result = null;
}
else
{
DataFile contentFile = this.getByIndex(nDataFile);
if (id == contentFile.id())
{
ended = true;
result = contentFile;
}
else
{
nDataFile += 1;
}
}
}
//
return (result);
}
/**
*
*/
public DataFile getByIndex(final int index)
{
DataFile result;
result = super.get(index);
//
return (result);
}
/**
*
*/
public DataFile getByName(final String name)
{
DataFile result = null;
if ((name == null) || (name.equals("")))
{
result = null;
}
else
{
boolean ended = false;
int dataFileIndex = 0;
while (!ended)
{
if (dataFileIndex >= this.size())
{
ended = true;
result = null;
}
else
{
DataFile contentFile = this.getByIndex(dataFileIndex);
if (name.equals(contentFile.name()))
{
ended = true;
result = contentFile;
}
else
{
dataFileIndex += 1;
}
}
}
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
StringBuffer result = new StringBuffer();
for (int nDataFile = 0; nDataFile < this.size(); nDataFile++)
{
DataFile contentFile = this.getByIndex(nDataFile);
result.append("== " + contentFile.name() + "\n");
result.append("contentFile " + nDataFile + " - " + contentFile.name() + "\n");
}
//
return (result.toString());
}
}
/**
* @author Christian Momon, June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.ArrayList;
/**
* This class is a collection of DataFile objects whit some specific methods.
*
*/
public class DataFiles extends ArrayList<DataFile>
{
private static final long serialVersionUID = -4584622422555785456L;
/**
*
*
*/
public DataFiles()
{
super();
}
/**
*
* @param source
*/
public DataFiles(final DataFiles source)
{
super(source);
}
/**
*
*/
public DataFiles getByContentId(final int id)
{
DataFiles result = new DataFiles();
for (int nDataFile = 0; nDataFile < this.size(); nDataFile++)
{
DataFile contentFile = this.getByIndex(nDataFile);
if (contentFile.contentId() == id)
{
result.add(contentFile);
}
}
//
return (result);
}
/**
*
*/
public DataFile getById(final int id)
{
DataFile result = null;
boolean ended = false;
int nDataFile = 0;
while (!ended)
{
if (nDataFile >= this.size())
{
ended = true;
result = null;
}
else
{
DataFile contentFile = this.getByIndex(nDataFile);
if (id == contentFile.id())
{
ended = true;
result = contentFile;
}
else
{
nDataFile += 1;
}
}
}
//
return (result);
}
/**
*
*/
public DataFile getByIndex(final int index)
{
DataFile result;
result = super.get(index);
//
return (result);
}
/**
*
*/
public DataFile getByName(final String name)
{
DataFile result = null;
if ((name == null) || (name.equals("")))
{
result = null;
}
else
{
boolean ended = false;
int dataFileIndex = 0;
while (!ended)
{
if (dataFileIndex >= this.size())
{
ended = true;
result = null;
}
else
{
DataFile contentFile = this.getByIndex(dataFileIndex);
if (name.equals(contentFile.name()))
{
ended = true;
result = contentFile;
}
else
{
dataFileIndex += 1;
}
}
}
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
StringBuffer result = new StringBuffer();
for (int nDataFile = 0; nDataFile < this.size(); nDataFile++)
{
DataFile contentFile = this.getByIndex(nDataFile);
result.append("== " + contentFile.name() + "\n");
result.append("contentFile " + nDataFile + " - " + contentFile.name() + "\n");
}
//
return (result.toString());
}
}

View file

@ -1,357 +1,357 @@
/**
* @author Christian Momon, June 2010.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class groups function to help in Calendar manipulation.
*
* SimpleDateFormat is not used cause does not thread safe?
*/
public class DateHelper
{
// static private final Logger logger =
// LoggerFactory.getLogger(DateHelper.class);
static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d";
static final String SHORT_EUROPEAN_DATE_FORMAT = "%02d/%02d";
static final String RAW_DATE_FORMAT = "%04d%02d%02d";
static final String ISO_DATE_FORMAT = "%04d-%02d-%02d";
static final String AMERICAN_DATE_FORMAT = "%02d/%02d/%04d";
static final String EUROPEAN_DATE_PATTERN = "^([0123]{0,1}\\d)/([01]{0,1}\\d)/(\\d\\d\\d\\d)$";
static final String RAW_DATE_PATTERN = "^(\\d\\d\\d\\d)([01]\\d)([0123]\\d)$";
static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$";
static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
/**
*
*/
static public String americanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public String europeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR));
}
//
return (result);
}
/**
*
*/
static public boolean isAmericanFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(AMERICAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isEuropeanFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(EUROPEAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isISOFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(ISO_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public String ISOFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public boolean isRawFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(RAW_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isValidDate(final String date)
{
boolean result;
if ((isEuropeanFormat(date)) || (isRawFormat(date)) || (isISOFormat(date)) || (isAmericanFormat(date)))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
static public Calendar parseAmericanDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(AMERICAN_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(1)) - 1, Integer.parseInt(matcher.group(2)));
}
else
{
result = null;
}
//
return (result);
}
/**
* Note: European parsing test made before the American parsing one.
*/
static public Calendar parseDate(final String date)
{
Calendar result;
if (isEuropeanFormat(date))
{
result = parseEuropeanDate(date);
}
else if (isRawFormat(date))
{
result = parseRawDate(date);
}
else if (isISOFormat(date))
{
result = parseISODate(date);
}
else if (isAmericanFormat(date))
{
result = parseAmericanDate(date);
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseEuropeanDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(EUROPEAN_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(1)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseISODate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(ISO_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseRawDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(RAW_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public String rawFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(RAW_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH) + 1);
}
//
return (result);
}
/**
*
*/
static public String shortEuropeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(SHORT_EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1);
}
//
return (result);
}
}
/**
* @author Christian Momon, June 2010.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class groups function to help in Calendar manipulation.
*
* SimpleDateFormat is not used cause does not thread safe?
*/
public class DateHelper
{
// static private final Logger logger =
// LoggerFactory.getLogger(DateHelper.class);
static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d";
static final String SHORT_EUROPEAN_DATE_FORMAT = "%02d/%02d";
static final String RAW_DATE_FORMAT = "%04d%02d%02d";
static final String ISO_DATE_FORMAT = "%04d-%02d-%02d";
static final String AMERICAN_DATE_FORMAT = "%02d/%02d/%04d";
static final String EUROPEAN_DATE_PATTERN = "^([0123]{0,1}\\d)/([01]{0,1}\\d)/(\\d\\d\\d\\d)$";
static final String RAW_DATE_PATTERN = "^(\\d\\d\\d\\d)([01]\\d)([0123]\\d)$";
static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$";
static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
/**
*
*/
static public String americanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public String europeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR));
}
//
return (result);
}
/**
*
*/
static public boolean isAmericanFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(AMERICAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isEuropeanFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(EUROPEAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isISOFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(ISO_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public String ISOFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public boolean isRawFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(RAW_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isValidDate(final String date)
{
boolean result;
if ((isEuropeanFormat(date)) || (isRawFormat(date)) || (isISOFormat(date)) || (isAmericanFormat(date)))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
static public Calendar parseAmericanDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(AMERICAN_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(1)) - 1, Integer.parseInt(matcher.group(2)));
}
else
{
result = null;
}
//
return (result);
}
/**
* Note: European parsing test made before the American parsing one.
*/
static public Calendar parseDate(final String date)
{
Calendar result;
if (isEuropeanFormat(date))
{
result = parseEuropeanDate(date);
}
else if (isRawFormat(date))
{
result = parseRawDate(date);
}
else if (isISOFormat(date))
{
result = parseISODate(date);
}
else if (isAmericanFormat(date))
{
result = parseAmericanDate(date);
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseEuropeanDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(EUROPEAN_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(1)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseISODate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(ISO_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseRawDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(RAW_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public String rawFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(RAW_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH) + 1);
}
//
return (result);
}
/**
*
*/
static public String shortEuropeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(SHORT_EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1);
}
//
return (result);
}
}

View file

@ -1,111 +1,111 @@
/**
* @author Christian Momon, June 2010.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.Calendar;
/**
* This class groups function to help in Calendar manipulation.
*/
public class DateTimeHelper
{
// static private final Logger logger =
// LoggerFactory.getLogger(DateTimeHelper.class);
static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d %02d:%02d:%02d";
static final String RAW_DATE_FORMAT = "%04d%02d%02d %02d:%02d:%02d";
static final String ISO_DATE_FORMAT = "%04d-%02d-%02d %02d:%02d:%02d";
static final String AMERICAN_DATE_FORMAT = "%02d/%02d/%04d %02d:%02d:%02d";
static final String EUROPEAN_DATE_PATTERN = "^([0123]{0,1}\\d)/([01]{0,1}\\d)/(\\d\\d\\d\\d)$";
static final String RAW_DATE_PATTERN = "^(\\d\\d\\d\\d)([01]\\d)([0123]\\d)$";
static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$";
static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
/**
*
*/
static public String americanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.YEAR), time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE), time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String europeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR), time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE), time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String ISOFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE),
time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String rawFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(RAW_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE),
time.get(Calendar.SECOND));
}
//
return (result);
}
}
/**
* @author Christian Momon, June 2010.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.Calendar;
/**
* This class groups function to help in Calendar manipulation.
*/
public class DateTimeHelper
{
// static private final Logger logger =
// LoggerFactory.getLogger(DateTimeHelper.class);
static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d %02d:%02d:%02d";
static final String RAW_DATE_FORMAT = "%04d%02d%02d %02d:%02d:%02d";
static final String ISO_DATE_FORMAT = "%04d-%02d-%02d %02d:%02d:%02d";
static final String AMERICAN_DATE_FORMAT = "%02d/%02d/%04d %02d:%02d:%02d";
static final String EUROPEAN_DATE_PATTERN = "^([0123]{0,1}\\d)/([01]{0,1}\\d)/(\\d\\d\\d\\d)$";
static final String RAW_DATE_PATTERN = "^(\\d\\d\\d\\d)([01]\\d)([0123]\\d)$";
static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$";
static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
/**
*
*/
static public String americanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.YEAR), time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE), time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String europeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR), time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE), time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String ISOFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE),
time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String rawFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(RAW_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE),
time.get(Calendar.SECOND));
}
//
return (result);
}
}

View file

@ -1,228 +1,228 @@
/**
* @author Christian Momon, September 2009.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
/**
*
*/
public class InternetProxyConfiguration
{
//
protected String host;
protected int port;
protected String login;
protected String password;
/**
*
*/
public InternetProxyConfiguration()
{
this.host = "";
this.port = 0;
this.login = "";
this.password = "";
}
/**
*
*/
public InternetProxyConfiguration(final String host, final int port, final String login, final String password)
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
this.port = port;
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/**
*
*/
public InternetProxyConfiguration(final String host, final String port, final String login, final String password) throws Exception
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
if ((port == null) || (port.trim().length() == 0))
{
this.port = 0;
}
else
{
try
{
this.port = Integer.parseInt(port);
}
catch (Exception exception)
{
String errorMessage = "Incorrect PROXY port value.";
throw new Exception(errorMessage, exception);
}
}
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/**
*
*/
public String host()
{
String result;
result = this.host;
//
return (result);
}
/**
*
*/
public boolean isInitialized()
{
boolean result;
if ((this.host.length() > 0) && (this.port > 0))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
public String login()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String password()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public int port()
{
int result;
result = this.port;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
String login;
if (this.login.length() == 0)
{
login = "";
}
else
{
login = "********";
}
String password;
if (this.password.length() == 0)
{
password = "";
}
else
{
password = "********";
}
result = "(" + this.host + "," + this.port + "," + login + "," + password + ")";
//
return (result);
}
}
/**
* @author Christian Momon, September 2009.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
/**
*
*/
public class InternetProxyConfiguration
{
//
protected String host;
protected int port;
protected String login;
protected String password;
/**
*
*/
public InternetProxyConfiguration()
{
this.host = "";
this.port = 0;
this.login = "";
this.password = "";
}
/**
*
*/
public InternetProxyConfiguration(final String host, final int port, final String login, final String password)
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
this.port = port;
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/**
*
*/
public InternetProxyConfiguration(final String host, final String port, final String login, final String password) throws Exception
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
if ((port == null) || (port.trim().length() == 0))
{
this.port = 0;
}
else
{
try
{
this.port = Integer.parseInt(port);
}
catch (Exception exception)
{
String errorMessage = "Incorrect PROXY port value.";
throw new Exception(errorMessage, exception);
}
}
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/**
*
*/
public String host()
{
String result;
result = this.host;
//
return (result);
}
/**
*
*/
public boolean isInitialized()
{
boolean result;
if ((this.host.length() > 0) && (this.port > 0))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
public String login()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String password()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public int port()
{
int result;
result = this.port;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
String login;
if (this.login.length() == 0)
{
login = "";
}
else
{
login = "********";
}
String password;
if (this.password.length() == 0)
{
password = "";
}
else
{
password = "********";
}
result = "(" + this.host + "," + this.port + "," + login + "," + password + ")";
//
return (result);
}
}

View file

@ -1,120 +1,120 @@
/**
* @author Christian Momon, September 2009.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
/**
* This class defines a simple average manager. For example, it is useful for
* millisecond. The maximum value available in input is one day in millisecond.
*/
public class SimpleAveragemeter
{
//
protected long sum;
protected long cardinal;
protected long MAX_ADD = 1 * 24 * 60 * 60 * 1000; // One day in millisecond.
/**
*
*/
public SimpleAveragemeter()
{
this.reset();
}
/**
*
*/
synchronized public void add(final long value)
{
// Manage the sum limit.
if ((this.sum > Long.MAX_VALUE / 2) && (cardinal % 2 == 0))
{
this.sum = this.sum / 2;
this.cardinal = this.cardinal / 2;
}
// Add the new value.
if (this.sum > MAX_ADD)
{
this.sum += MAX_ADD;
this.cardinal += 1;
}
else
{
this.sum += value;
this.cardinal += 1;
}
}
/**
*
*/
synchronized public long average()
{
long result;
if (cardinal == 0)
{
result = 0;
}
else
{
result = sum / cardinal;
}
//
return (result);
}
/**
*
*/
public long cardinal()
{
long result;
result = this.cardinal;
//
return (result);
}
/**
*
*/
synchronized public void reset()
{
this.sum = 0;
this.cardinal = 0;
}
/**
*
*/
@Override
public String toString()
{
String result;
result = Long.toString(this.average());
//
return (result);
}
/**
*
*/
public long value()
{
long result;
result = this.average();
//
return (result);
}
}
/**
* @author Christian Momon, September 2009.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
/**
* This class defines a simple average manager. For example, it is useful for
* millisecond. The maximum value available in input is one day in millisecond.
*/
public class SimpleAveragemeter
{
//
protected long sum;
protected long cardinal;
protected long MAX_ADD = 1 * 24 * 60 * 60 * 1000; // One day in millisecond.
/**
*
*/
public SimpleAveragemeter()
{
this.reset();
}
/**
*
*/
synchronized public void add(final long value)
{
// Manage the sum limit.
if ((this.sum > Long.MAX_VALUE / 2) && (cardinal % 2 == 0))
{
this.sum = this.sum / 2;
this.cardinal = this.cardinal / 2;
}
// Add the new value.
if (this.sum > MAX_ADD)
{
this.sum += MAX_ADD;
this.cardinal += 1;
}
else
{
this.sum += value;
this.cardinal += 1;
}
}
/**
*
*/
synchronized public long average()
{
long result;
if (cardinal == 0)
{
result = 0;
}
else
{
result = sum / cardinal;
}
//
return (result);
}
/**
*
*/
public long cardinal()
{
long result;
result = this.cardinal;
//
return (result);
}
/**
*
*/
synchronized public void reset()
{
this.sum = 0;
this.cardinal = 0;
}
/**
*
*/
@Override
public String toString()
{
String result;
result = Long.toString(this.average());
//
return (result);
}
/**
*
*/
public long value()
{
long result;
result = this.average();
//
return (result);
}
}

View file

@ -1,151 +1,151 @@
/**
* @author Christian Momon, in June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.Date;
/**
*
*/
public class SimpleChronometer
{
//
protected long firstTime;
/**
*
*/
public SimpleChronometer()
{
this.reset();
}
/**
*
*/
public long interval()
{
long result;
result = new Date().getTime() - this.firstTime;
//
return (result);
}
/**
*
*/
public void reset()
{
this.firstTime = new Date().getTime();
}
/**
* TO BE COMPLETED.
*/
static public String humanString(final long interval)
{
String result;
if (interval < 1000)
{
result = interval + "ms";
}
else if (interval < 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 24 * 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 7 * 24 * 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else
// if (interval < 7*24*60*60*1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
//
return (result);
}
/**
*
*/
static public String shortHumanString(final long interval)
{
String result;
if (interval < 1000)
{
result = interval + " ms";
}
else if (interval < 2 * 1000)
{
result = interval / 1000 + " seconde";
}
else if (interval < 60 * 1000)
{
result = interval / 1000 + " secondes";
}
else if (interval < 2 * 60 * 1000L)
{
result = interval / (60 * 1000L) + " minute";
}
else if (interval < 60 * 60 * 1000L)
{
result = interval / (60 * 1000L) + " minutes";
}
else if (interval < 2 * 60 * 60 * 1000L)
{
result = interval / (60 * 60 * 1000L) + " heure";
}
else if (interval < 24 * 60 * 60 * 1000L)
{
result = interval / (60 * 60 * 1000L) + " heures";
}
else if (interval < 2 * 24 * 60 * 60 * 1000L)
{
result = interval / (24 * 60 * 60 * 1000L) + " jour";
}
else if (interval < 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (24 * 60 * 60 * 1000L) + " jours";
}
else if (interval < 2 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (7 * 24 * 60 * 60 * 1000L) + " semaine";
}
else if (interval < 30 * 24 * 60 * 60 * 1000L)
{
result = interval / (7 * 24 * 60 * 60 * 1000L) + " semaines";
}
else if (interval < 52 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (30 * 24 * 60 * 60 * 1000L) + " mois";
}
else if (interval < 2 * 52 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " année";
}
else
{
result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " années";
}
//
return (result);
}
}
/**
* @author Christian Momon, in June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.util.Date;
/**
*
*/
public class SimpleChronometer
{
//
protected long firstTime;
/**
*
*/
public SimpleChronometer()
{
this.reset();
}
/**
*
*/
public long interval()
{
long result;
result = new Date().getTime() - this.firstTime;
//
return (result);
}
/**
*
*/
public void reset()
{
this.firstTime = new Date().getTime();
}
/**
* TO BE COMPLETED.
*/
static public String humanString(final long interval)
{
String result;
if (interval < 1000)
{
result = interval + "ms";
}
else if (interval < 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 24 * 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 7 * 24 * 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else
// if (interval < 7*24*60*60*1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
//
return (result);
}
/**
*
*/
static public String shortHumanString(final long interval)
{
String result;
if (interval < 1000)
{
result = interval + " ms";
}
else if (interval < 2 * 1000)
{
result = interval / 1000 + " seconde";
}
else if (interval < 60 * 1000)
{
result = interval / 1000 + " secondes";
}
else if (interval < 2 * 60 * 1000L)
{
result = interval / (60 * 1000L) + " minute";
}
else if (interval < 60 * 60 * 1000L)
{
result = interval / (60 * 1000L) + " minutes";
}
else if (interval < 2 * 60 * 60 * 1000L)
{
result = interval / (60 * 60 * 1000L) + " heure";
}
else if (interval < 24 * 60 * 60 * 1000L)
{
result = interval / (60 * 60 * 1000L) + " heures";
}
else if (interval < 2 * 24 * 60 * 60 * 1000L)
{
result = interval / (24 * 60 * 60 * 1000L) + " jour";
}
else if (interval < 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (24 * 60 * 60 * 1000L) + " jours";
}
else if (interval < 2 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (7 * 24 * 60 * 60 * 1000L) + " semaine";
}
else if (interval < 30 * 24 * 60 * 60 * 1000L)
{
result = interval / (7 * 24 * 60 * 60 * 1000L) + " semaines";
}
else if (interval < 52 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (30 * 24 * 60 * 60 * 1000L) + " mois";
}
else if (interval < 2 * 52 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " année";
}
else
{
result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " années";
}
//
return (result);
}
}

View file

@ -1,383 +1,383 @@
/**
* @author Christian Momon, June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.io.IOException;
import java.util.ArrayList;
/**
* This class is a collection of String objects with specific methods. It makes
* possible to build a string without any copy. The goal is to optimize the
* building of strings where they are lot of concatenation action.
*/
public class StringConcatenator extends ArrayList<String>
{
private static final long serialVersionUID = -1154185934830213732L;
public String LINE_SEPARATOR = "\n";
/**
*
*/
public StringConcatenator()
{
super();
}
/**
*
*/
public StringConcatenator append(final char character)
{
StringConcatenator result;
this.add(String.valueOf(character));
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator append(final String string)
{
StringConcatenator result;
if (string != null)
{
this.add(string);
}
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator append(final StringConcatenator string)
{
StringConcatenator result;
if (string != null)
{
for (int nString = 0; nString < string.size(); nString++)
{
this.add(string.getByIndex(nString));
}
}
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator appendln()
{
StringConcatenator result;
this.add(LINE_SEPARATOR);
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final char character)
{
StringConcatenator result;
result = this.append(character).appendln();
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final String string)
{
StringConcatenator result;
result = this.append(string).appendln();
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final StringConcatenator string)
{
StringConcatenator result;
result = this.append(string).appendln();
//
return (result);
}
/**
*
*/
public String getByIndex(final int id)
{
String result;
result = this.get(id);
//
return (result);
}
/**
*
*/
public int lenght()
{
int result = 0;
for (int nString = 0; nString < this.size(); nString++)
{
result += this.getByIndex(nString).length();
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer preResult = new StringBuffer(this.lenght());
for (int nString = 0; nString < this.size(); nString++)
{
preResult.append(this.getByIndex(nString));
}
result = new String(preResult);
//
return (result);
}
/**
*
*/
public void writeInto(final java.io.Writer out) throws IOException
{
for (int nString = 0; nString < this.size(); nString++)
{
out.write(this.getByIndex(nString));
}
}
/**
*
*/
static public String toString(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator string = new StringConcatenator();
for (int nString = 0; nString < strings.length; nString++)
{
string.append(strings[nString]);
if (nString < strings.length - 1)
{
string.append(' ');
}
}
result = string.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringNotNull(final String[] strings)
{
String result;
result = toString(strings);
if (result == null)
{
result = "";
}
//
return (result);
}
/**
*
*/
static public String toStringWithBracket(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
merge.append("[");
merge.append(toStringWithCommas(strings));
merge.append("]");
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithBracketNotNull(final String[] strings)
{
String result;
result = toStringWithBrackets(strings);
if (result == null)
{
result = "";
}
//
return (result);
}
/**
*
*/
static public String toStringWithBrackets(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
merge.append("[").append(string).append("]");
}
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithFrenchCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
}
//
return (result);
}
}
/**
* @author Christian Momon, June 2008.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.io.IOException;
import java.util.ArrayList;
/**
* This class is a collection of String objects with specific methods. It makes
* possible to build a string without any copy. The goal is to optimize the
* building of strings where they are lot of concatenation action.
*/
public class StringConcatenator extends ArrayList<String>
{
private static final long serialVersionUID = -1154185934830213732L;
public String LINE_SEPARATOR = "\n";
/**
*
*/
public StringConcatenator()
{
super();
}
/**
*
*/
public StringConcatenator append(final char character)
{
StringConcatenator result;
this.add(String.valueOf(character));
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator append(final String string)
{
StringConcatenator result;
if (string != null)
{
this.add(string);
}
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator append(final StringConcatenator string)
{
StringConcatenator result;
if (string != null)
{
for (int nString = 0; nString < string.size(); nString++)
{
this.add(string.getByIndex(nString));
}
}
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator appendln()
{
StringConcatenator result;
this.add(LINE_SEPARATOR);
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final char character)
{
StringConcatenator result;
result = this.append(character).appendln();
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final String string)
{
StringConcatenator result;
result = this.append(string).appendln();
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final StringConcatenator string)
{
StringConcatenator result;
result = this.append(string).appendln();
//
return (result);
}
/**
*
*/
public String getByIndex(final int id)
{
String result;
result = this.get(id);
//
return (result);
}
/**
*
*/
public int lenght()
{
int result = 0;
for (int nString = 0; nString < this.size(); nString++)
{
result += this.getByIndex(nString).length();
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer preResult = new StringBuffer(this.lenght());
for (int nString = 0; nString < this.size(); nString++)
{
preResult.append(this.getByIndex(nString));
}
result = new String(preResult);
//
return (result);
}
/**
*
*/
public void writeInto(final java.io.Writer out) throws IOException
{
for (int nString = 0; nString < this.size(); nString++)
{
out.write(this.getByIndex(nString));
}
}
/**
*
*/
static public String toString(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator string = new StringConcatenator();
for (int nString = 0; nString < strings.length; nString++)
{
string.append(strings[nString]);
if (nString < strings.length - 1)
{
string.append(' ');
}
}
result = string.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringNotNull(final String[] strings)
{
String result;
result = toString(strings);
if (result == null)
{
result = "";
}
//
return (result);
}
/**
*
*/
static public String toStringWithBracket(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
merge.append("[");
merge.append(toStringWithCommas(strings));
merge.append("]");
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithBracketNotNull(final String[] strings)
{
String result;
result = toStringWithBrackets(strings);
if (result == null)
{
result = "";
}
//
return (result);
}
/**
*
*/
static public String toStringWithBrackets(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
merge.append("[").append(string).append("]");
}
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithFrenchCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
}
//
return (result);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,77 +1,77 @@
/**
* @author Christian Momon, March 2010.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.io.IOException;
import java.io.Writer;
/**
*
*/
public class StringListWriter extends Writer
{
protected StringList out;
/**
*
*/
StringListWriter()
{
this.out = new StringList();
}
/**
*
*/
StringListWriter(final int size)
{
this.out = new StringList(size);
}
/*
*
*/
@Override
public void close() throws IOException
{
}
/*
*
*/
@Override
public void flush() throws IOException
{
}
/*
*
*/
public void write(final char c) throws IOException
{
this.out.append(c);
}
/*
*
*/
@Override
public void write(final char[] cbuf, final int off, final int len) throws IOException
{
this.out.append(cbuf.toString().substring(off, len));
}
/*
*
*/
@Override
public void write(final String string) throws IOException
{
this.out.append(string);
}
}
/**
* @author Christian Momon, March 2010.
* This file is free software under the terms of the GNU Library General Public License
* as published by the Free Software Foundation version 2 or any later version.
*/
package fr.devinsy.util;
import java.io.IOException;
import java.io.Writer;
/**
*
*/
public class StringListWriter extends Writer
{
protected StringList out;
/**
*
*/
StringListWriter()
{
this.out = new StringList();
}
/**
*
*/
StringListWriter(final int size)
{
this.out = new StringList(size);
}
/*
*
*/
@Override
public void close() throws IOException
{
}
/*
*
*/
@Override
public void flush() throws IOException
{
}
/*
*
*/
public void write(final char c) throws IOException
{
this.out.append(c);
}
/*
*
*/
@Override
public void write(final char[] cbuf, final int off, final int len) throws IOException
{
this.out.append(cbuf.toString().substring(off, len));
}
/*
*
*/
@Override
public void write(final String string) throws IOException
{
this.out.append(string);
}
}

View file

@ -1,67 +1,67 @@
package fr.devinsy.util.cmdexec;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class Wrapper
{
static private final Wrapper instance = new Wrapper();
static private final Logger logger = LoggerFactory.getLogger(Wrapper.class);
/**
* return instance of the controller
*/
public static Wrapper instance()
{
return (instance);
}
/**
*
*/
static public StringBuffer wrap(final String ressource) throws IOException
{
logger.info("Enter");
StringBuffer result;
result = new StringBuffer();
BufferedReader buf = new BufferedReader(new FileReader(ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
result.append(ligne + "\n");
}
//
logger.info("Exit");
return (result);
}
/**
*
*/
static public void wrap(final String ressource, final PrintWriter output) throws IOException
{
logger.info("Enter");
BufferedReader buf = new BufferedReader(new FileReader(ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
output.print(ligne);
}
logger.info("Exit");
}
}
package fr.devinsy.util.cmdexec;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class Wrapper
{
static private final Wrapper instance = new Wrapper();
static private final Logger logger = LoggerFactory.getLogger(Wrapper.class);
/**
* return instance of the controller
*/
public static Wrapper instance()
{
return (instance);
}
/**
*
*/
static public StringBuffer wrap(final String ressource) throws IOException
{
logger.info("Enter");
StringBuffer result;
result = new StringBuffer();
BufferedReader buf = new BufferedReader(new FileReader(ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
result.append(ligne + "\n");
}
//
logger.info("Exit");
return (result);
}
/**
*
*/
static public void wrap(final String ressource, final PrintWriter output) throws IOException
{
logger.info("Enter");
BufferedReader buf = new BufferedReader(new FileReader(ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
output.print(ligne);
}
logger.info("Exit");
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,115 +1,115 @@
package fr.devinsy.util.unix;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class CachedFile
{
public enum Status
{
NOT_LOAD, EXPIRED, UPDATED
}
static private final Logger logger = LoggerFactory.getLogger(CachedFile.class);
protected String sourceName;
protected long sourceTime;
protected Status status;
/**
*
*/
public CachedFile(final String fileName)
{
this.sourceName = fileName;
this.sourceTime = 0;
this.status = Status.NOT_LOAD;
}
/**
*
*/
protected File getSourceFile()
{
File result;
if (this.sourceName == null)
{
result = null;
}
else
{
File source = new File(this.sourceName);
if (!source.exists())
{
logger.error("source file defined but not found");
result = null;
}
else
{
result = source;
}
}
//
return (result);
}
/**
*
*/
protected Status getStatus()
{
Status result;
File source = getSourceFile();
if (source == null)
{
this.status = Status.NOT_LOAD;
}
else if (this.sourceTime != source.lastModified())
{
this.status = Status.EXPIRED;
}
result = this.status;
//
return (result);
}
/**
*
*/
public void setNotLoad()
{
this.status = Status.NOT_LOAD;
}
/**
*
*/
public void setUpdated()
{
File source = getSourceFile();
if (source == null)
{
this.status = Status.NOT_LOAD;
}
else
{
this.sourceTime = source.lastModified();
this.status = Status.UPDATED;
}
}
}
package fr.devinsy.util.unix;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class CachedFile
{
public enum Status
{
NOT_LOAD, EXPIRED, UPDATED
}
static private final Logger logger = LoggerFactory.getLogger(CachedFile.class);
protected String sourceName;
protected long sourceTime;
protected Status status;
/**
*
*/
public CachedFile(final String fileName)
{
this.sourceName = fileName;
this.sourceTime = 0;
this.status = Status.NOT_LOAD;
}
/**
*
*/
protected File getSourceFile()
{
File result;
if (this.sourceName == null)
{
result = null;
}
else
{
File source = new File(this.sourceName);
if (!source.exists())
{
logger.error("source file defined but not found");
result = null;
}
else
{
result = source;
}
}
//
return (result);
}
/**
*
*/
protected Status getStatus()
{
Status result;
File source = getSourceFile();
if (source == null)
{
this.status = Status.NOT_LOAD;
}
else if (this.sourceTime != source.lastModified())
{
this.status = Status.EXPIRED;
}
result = this.status;
//
return (result);
}
/**
*
*/
public void setNotLoad()
{
this.status = Status.NOT_LOAD;
}
/**
*
*/
public void setUpdated()
{
File source = getSourceFile();
if (source == null)
{
this.status = Status.NOT_LOAD;
}
else
{
this.sourceTime = source.lastModified();
this.status = Status.UPDATED;
}
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,181 +1,181 @@
package fr.devinsy.util.unix;
import java.util.Vector;
/**
*
*/
public class EtcGroupFile extends CachedFile
{
// static private final Logger logger =
// LoggerFactory.getLogger(EtcGroupFile.class);
static EtcGroupFile instance = null;
protected Groups groups;
/**
*
*/
protected EtcGroupFile()
{
super("/etc/group");
this.groups = null;
}
/*
*
*/
public boolean contains(final String name)
{
boolean result;
Groups groups = updatedGroups();
if (groups == null)
{
result = false;
}
else
{
result = groups.contains(name);
}
//
return (result);
}
/**
*
*/
public Group get(final int gid)
{
Group result;
Groups groups = updatedGroups();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByGid(gid);
}
//
return (result);
}
/**
*
*/
public Group get(final String name)
{
Group result;
Groups groups = updatedGroups();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByName(name);
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
Groups groups = updatedGroups();
result = groups.getLoginGroups(login);
//
return (result);
}
/**
*
*/
public String getLoginGroupsString(final String login)
{
String result;
groups = updatedGroups();
result = groups.getLoginGroupsString(login);
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.groups.toString();
//
return (result);
}
/**
*
*/
protected Groups updatedGroups()
{
Groups result;
if (getStatus() != Status.UPDATED)
{
this.groups = EtcGroupFileReader.load();
if (this.groups == null)
{
setNotLoad();
}
else
{
setUpdated();
}
}
result = this.groups;
//
return (result);
}
/**
*
*/
static public EtcGroupFile instance()
{
EtcGroupFile result;
if (EtcGroupFile.instance == null)
{
EtcGroupFile.instance = new EtcGroupFile();
}
result = EtcGroupFile.instance;
//
return (result);
}
}
package fr.devinsy.util.unix;
import java.util.Vector;
/**
*
*/
public class EtcGroupFile extends CachedFile
{
// static private final Logger logger =
// LoggerFactory.getLogger(EtcGroupFile.class);
static EtcGroupFile instance = null;
protected Groups groups;
/**
*
*/
protected EtcGroupFile()
{
super("/etc/group");
this.groups = null;
}
/*
*
*/
public boolean contains(final String name)
{
boolean result;
Groups groups = updatedGroups();
if (groups == null)
{
result = false;
}
else
{
result = groups.contains(name);
}
//
return (result);
}
/**
*
*/
public Group get(final int gid)
{
Group result;
Groups groups = updatedGroups();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByGid(gid);
}
//
return (result);
}
/**
*
*/
public Group get(final String name)
{
Group result;
Groups groups = updatedGroups();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByName(name);
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
Groups groups = updatedGroups();
result = groups.getLoginGroups(login);
//
return (result);
}
/**
*
*/
public String getLoginGroupsString(final String login)
{
String result;
groups = updatedGroups();
result = groups.getLoginGroupsString(login);
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.groups.toString();
//
return (result);
}
/**
*
*/
protected Groups updatedGroups()
{
Groups result;
if (getStatus() != Status.UPDATED)
{
this.groups = EtcGroupFileReader.load();
if (this.groups == null)
{
setNotLoad();
}
else
{
setUpdated();
}
}
result = this.groups;
//
return (result);
}
/**
*
*/
static public EtcGroupFile instance()
{
EtcGroupFile result;
if (EtcGroupFile.instance == null)
{
EtcGroupFile.instance = new EtcGroupFile();
}
result = EtcGroupFile.instance;
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,83 +1,83 @@
package fr.devinsy.util.unix;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class EtcGroupFileReader
{
static private final Logger logger = LoggerFactory.getLogger(EtcGroupFileReader.class);
/**
*
*/
static public Groups load()
{
Groups result;
BufferedReader file;
try
{
file = new BufferedReader(new FileReader("/etc/group"));
}
catch (FileNotFoundException exception)
{
logger.error("File not found");
file = null;
}
if (file == null)
{
result = null;
}
else
{
result = new Groups();
try
{
String line;
while ((line = file.readLine()) != null)
{
String[] tokens = line.split(":");
Group group = new Group();
group.setName(tokens[0]);
group.setPassword(tokens[1]);
group.setGid((new Integer(tokens[2])).intValue());
// Manage the case of empty shell.
if (tokens.length == 4)
{
String[] tokensBis = tokens[3].split(",");
for (int tokenCounter = 0; tokenCounter < tokensBis.length; tokenCounter++)
{
group.addMember(tokensBis[tokenCounter]);
}
}
result.add(group);
}
file.close();
}
catch (java.io.IOException exception)
{
logger.error("Exception here.");
result = null;
}
}
//
return (result);
}
}
package fr.devinsy.util.unix;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class EtcGroupFileReader
{
static private final Logger logger = LoggerFactory.getLogger(EtcGroupFileReader.class);
/**
*
*/
static public Groups load()
{
Groups result;
BufferedReader file;
try
{
file = new BufferedReader(new FileReader("/etc/group"));
}
catch (FileNotFoundException exception)
{
logger.error("File not found");
file = null;
}
if (file == null)
{
result = null;
}
else
{
result = new Groups();
try
{
String line;
while ((line = file.readLine()) != null)
{
String[] tokens = line.split(":");
Group group = new Group();
group.setName(tokens[0]);
group.setPassword(tokens[1]);
group.setGid((new Integer(tokens[2])).intValue());
// Manage the case of empty shell.
if (tokens.length == 4)
{
String[] tokensBis = tokens[3].split(",");
for (int tokenCounter = 0; tokenCounter < tokensBis.length; tokenCounter++)
{
group.addMember(tokensBis[tokenCounter]);
}
}
result.add(group);
}
file.close();
}
catch (java.io.IOException exception)
{
logger.error("Exception here.");
result = null;
}
}
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,167 +1,167 @@
package fr.devinsy.util.unix;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class EtcPasswdFile extends CachedFile
{
static private final Logger logger = LoggerFactory.getLogger(EtcPasswdFile.class);
static EtcPasswdFile instance = null;
protected Users users;
/**
*
*/
protected EtcPasswdFile()
{
super("/etc/passwd");
this.users = null;
}
/*
*
*/
public boolean contains(final String login)
{
boolean result;
Users users = updatedUsers();
if (users == null)
{
result = false;
}
else
{
result = users.contains(login);
}
//
return (result);
}
/**
*
*/
public User get(final int uid)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByUid(uid);
}
//
return (result);
}
/**
*
*/
public User get(final String login)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByLogin(login);
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.users.toString();
//
return (result);
}
/**
*
*/
protected Users update()
{
Users result;
logger.debug("updating");
this.users = EtcPasswdFileReader.load();
if (this.users == null)
{
setNotLoad();
}
else
{
setUpdated();
}
result = this.users;
//
return (result);
}
/**
*
*/
protected Users updatedUsers()
{
Users result;
if (getStatus() != Status.UPDATED)
{
update();
}
result = this.users;
//
return (result);
}
/**
*
*/
static public EtcPasswdFile instance()
{
EtcPasswdFile result;
if (EtcPasswdFile.instance == null)
{
EtcPasswdFile.instance = new EtcPasswdFile();
}
result = EtcPasswdFile.instance;
//
return (result);
}
}
package fr.devinsy.util.unix;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class EtcPasswdFile extends CachedFile
{
static private final Logger logger = LoggerFactory.getLogger(EtcPasswdFile.class);
static EtcPasswdFile instance = null;
protected Users users;
/**
*
*/
protected EtcPasswdFile()
{
super("/etc/passwd");
this.users = null;
}
/*
*
*/
public boolean contains(final String login)
{
boolean result;
Users users = updatedUsers();
if (users == null)
{
result = false;
}
else
{
result = users.contains(login);
}
//
return (result);
}
/**
*
*/
public User get(final int uid)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByUid(uid);
}
//
return (result);
}
/**
*
*/
public User get(final String login)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByLogin(login);
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.users.toString();
//
return (result);
}
/**
*
*/
protected Users update()
{
Users result;
logger.debug("updating");
this.users = EtcPasswdFileReader.load();
if (this.users == null)
{
setNotLoad();
}
else
{
setUpdated();
}
result = this.users;
//
return (result);
}
/**
*
*/
protected Users updatedUsers()
{
Users result;
if (getStatus() != Status.UPDATED)
{
update();
}
result = this.users;
//
return (result);
}
/**
*
*/
static public EtcPasswdFile instance()
{
EtcPasswdFile result;
if (EtcPasswdFile.instance == null)
{
EtcPasswdFile.instance = new EtcPasswdFile();
}
result = EtcPasswdFile.instance;
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,86 +1,86 @@
package fr.devinsy.util.unix;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class EtcPasswdFileReader
{
static private final Logger logger = LoggerFactory.getLogger(EtcPasswdFileReader.class);
/**
*
*/
static public Users load()
{
Users result;
BufferedReader file;
try
{
file = new BufferedReader(new FileReader("/etc/passwd"));
}
catch (FileNotFoundException exception)
{
logger.error("File not found");
file = null;
}
if (file == null)
{
result = null;
}
else
{
result = new Users();
try
{
String line;
while ((line = file.readLine()) != null)
{
String[] tokens = line.split(":");
User user = new User();
user.setLogin(tokens[0]);
user.setPassword(tokens[1]);
user.setUid((new Integer(tokens[2])).intValue());
user.setGid((new Integer(tokens[3])).intValue());
user.setRealName(tokens[4]);
user.setHomeDirectory(tokens[5]);
// Manage the case of empty shell.
if (tokens.length == 7)
{
user.setShell(tokens[6]);
}
else
{
user.setShell("");
}
result.add(user);
}
file.close();
}
catch (java.io.IOException exception)
{
logger.error("Exception here.");
result = null;
}
}
//
return (result);
}
}
package fr.devinsy.util.unix;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class EtcPasswdFileReader
{
static private final Logger logger = LoggerFactory.getLogger(EtcPasswdFileReader.class);
/**
*
*/
static public Users load()
{
Users result;
BufferedReader file;
try
{
file = new BufferedReader(new FileReader("/etc/passwd"));
}
catch (FileNotFoundException exception)
{
logger.error("File not found");
file = null;
}
if (file == null)
{
result = null;
}
else
{
result = new Users();
try
{
String line;
while ((line = file.readLine()) != null)
{
String[] tokens = line.split(":");
User user = new User();
user.setLogin(tokens[0]);
user.setPassword(tokens[1]);
user.setUid((new Integer(tokens[2])).intValue());
user.setGid((new Integer(tokens[3])).intValue());
user.setRealName(tokens[4]);
user.setHomeDirectory(tokens[5]);
// Manage the case of empty shell.
if (tokens.length == 7)
{
user.setShell(tokens[6]);
}
else
{
user.setShell("");
}
result.add(user);
}
file.close();
}
catch (java.io.IOException exception)
{
logger.error("Exception here.");
result = null;
}
}
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,204 +1,204 @@
package fr.devinsy.util.unix;
import java.util.Vector;
/**
*
*/
public class Group
{
// static private final Logger logger =
// LoggerFactory.getLogger(Group.class);
/*
* /usr/include/grp.h
*
* The group structure.
* struct group
* {
* char *gr_name; Group name.
* char *gr_passwd; Password.
* __gid_t gr_gid; Group ID.
* char **gr_mem; Member list.
* };
*/
protected String name;
protected String password;
protected int gid;
protected Vector<String> members;
/**
*
*/
public Group()
{
this.name = null;
this.password = null;
this.gid = -1;
this.members = new Vector<String>();
}
/**
*
*/
public void addMember(final String login)
{
if ((login != null) && (login.length() != 0))
{
this.members.add(login);
}
}
/**
*
*/
public int getGid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public Vector<String> getMembers()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/**
*
*/
public String getName()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public String getPassword()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public int gid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public Vector<String> members()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/**
*
*/
public String name()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public String passwd()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public void setGid(final int gid)
{
this.gid = gid;
}
/**
*
*/
public void setName(final String name)
{
this.name = name;
}
/**
*
*/
public void setPasswd(final String password)
{
this.password = password;
}
/**
*
*/
public void setPassword(final String password)
{
this.password = password;
}
/**
*
*/
@Override
public String toString()
{
String result;
result = "|" + this.name + "|" + this.password + "|" + this.gid + "|" + this.members + "|";
//
return (result);
}
}
package fr.devinsy.util.unix;
import java.util.Vector;
/**
*
*/
public class Group
{
// static private final Logger logger =
// LoggerFactory.getLogger(Group.class);
/*
* /usr/include/grp.h
*
* The group structure.
* struct group
* {
* char *gr_name; Group name.
* char *gr_passwd; Password.
* __gid_t gr_gid; Group ID.
* char **gr_mem; Member list.
* };
*/
protected String name;
protected String password;
protected int gid;
protected Vector<String> members;
/**
*
*/
public Group()
{
this.name = null;
this.password = null;
this.gid = -1;
this.members = new Vector<String>();
}
/**
*
*/
public void addMember(final String login)
{
if ((login != null) && (login.length() != 0))
{
this.members.add(login);
}
}
/**
*
*/
public int getGid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public Vector<String> getMembers()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/**
*
*/
public String getName()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public String getPassword()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public int gid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public Vector<String> members()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/**
*
*/
public String name()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public String passwd()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public void setGid(final int gid)
{
this.gid = gid;
}
/**
*
*/
public void setName(final String name)
{
this.name = name;
}
/**
*
*/
public void setPasswd(final String password)
{
this.password = password;
}
/**
*
*/
public void setPassword(final String password)
{
this.password = password;
}
/**
*
*/
@Override
public String toString()
{
String result;
result = "|" + this.name + "|" + this.password + "|" + this.gid + "|" + this.members + "|";
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,214 +1,214 @@
package fr.devinsy.util.unix;
import java.util.Iterator;
import java.util.Vector;
/**
*
*/
public class Groups extends Vector<Group>
{
private static final long serialVersionUID = 5802487312198869603L;
// static private final Logger logger =
// LoggerFactory.getLogger(Groups.class);
/**
*
*/
public Groups()
{
super();
}
/*
*
*/
public boolean contains(final int gid)
{
boolean result;
if (getByGid(gid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains(final String name)
{
boolean result;
if (getByName(name) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public Group getByGid(final int gid)
{
Group result;
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
Group group = iterator.next();
if (group.getGid() == gid)
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/**
*
*/
public Group getByName(final String name)
{
Group result;
if (name == null)
{
result = null;
}
else
{
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
Group group = iterator.next();
if (group.getName().equals(name))
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
result = new Vector<String>();
Iterator<Group> iterator = this.iterator();
while (iterator.hasNext())
{
Group group = iterator.next();
if (group.members().contains(login))
{
result.add(group.getName());
}
}
//
return (result);
}
/**
*
*/
public String getLoginGroupsString(final String login)
{
String result;
Vector<String> groups = getLoginGroups(login);
StringBuffer string = new StringBuffer();
for (String group : groups)
{
if (string.length() == 0)
{
string.append(group);
}
else
{
string.append(",");
string.append(group);
}
}
result = string.toString();
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer out = new StringBuffer();
Iterator<Group> iterator = this.iterator();
while (iterator.hasNext())
{
out.append(iterator.next().toString() + "\n");
}
result = out.toString();
//
return (result);
}
}
package fr.devinsy.util.unix;
import java.util.Iterator;
import java.util.Vector;
/**
*
*/
public class Groups extends Vector<Group>
{
private static final long serialVersionUID = 5802487312198869603L;
// static private final Logger logger =
// LoggerFactory.getLogger(Groups.class);
/**
*
*/
public Groups()
{
super();
}
/*
*
*/
public boolean contains(final int gid)
{
boolean result;
if (getByGid(gid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains(final String name)
{
boolean result;
if (getByName(name) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public Group getByGid(final int gid)
{
Group result;
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
Group group = iterator.next();
if (group.getGid() == gid)
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/**
*
*/
public Group getByName(final String name)
{
Group result;
if (name == null)
{
result = null;
}
else
{
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
Group group = iterator.next();
if (group.getName().equals(name))
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
result = new Vector<String>();
Iterator<Group> iterator = this.iterator();
while (iterator.hasNext())
{
Group group = iterator.next();
if (group.members().contains(login))
{
result.add(group.getName());
}
}
//
return (result);
}
/**
*
*/
public String getLoginGroupsString(final String login)
{
String result;
Vector<String> groups = getLoginGroups(login);
StringBuffer string = new StringBuffer();
for (String group : groups)
{
if (string.length() == 0)
{
string.append(group);
}
else
{
string.append(",");
string.append(group);
}
}
result = string.toString();
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer out = new StringBuffer();
Iterator<Group> iterator = this.iterator();
while (iterator.hasNext())
{
out.append(iterator.next().toString() + "\n");
}
result = out.toString();
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load diff

View file

@ -1,337 +1,337 @@
package fr.devinsy.util.unix;
/**
*
*/
public class User
{
// static private final Logger logger = LoggerFactory.getLogger(User.class);
/*
* /usr/include/pwd.h
*
* The passwd structure.
* struct passwd
* {
* char *pw_name;D Username.
* char *pw_passwd; Password.
* __uid_t pw_uid; User ID.
* __gid_t pw_gid; Group ID.
* char *pw_gecos; Real name.
* char *pw_dir; Home directory.
* char *pw_shell; Shell program.
* };
*/
protected String login;
protected String password;
protected int uid;
protected int gid;
protected String realName;
protected String homeDirectory;
protected String shell;
/**
*
*/
public User()
{
this.login = null;
this.password = null;
this.uid = -1;
this.gid = -1;
this.realName = null;
this.homeDirectory = null;
this.shell = null;
}
/**
*
*/
public User(final User user)
{
this.login = user.login();
this.password = user.passwd();
this.uid = user.uid();
this.gid = user.gid();
this.realName = user.realName();
this.homeDirectory = user.homeDirectory();
this.shell = user.shell();
}
/**
*
*/
public int getGid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public String getHomeDirectory()
{
String result;
result = this.homeDirectory;
//
return (result);
}
/**
*
*/
public String getLogin()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String getPasswd()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String getPassword()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String getRealName()
{
String result;
result = this.realName;
//
return (result);
}
/**
*
*/
public String getShell()
{
String result;
result = this.shell;
//
return (result);
}
/**
*
*/
public int getUid()
{
int result;
result = this.uid;
//
return (result);
}
/**
*
*/
public int gid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public String homeDirectory()
{
String result;
result = this.homeDirectory;
//
return (result);
}
/**
*
*/
public String login()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String passwd()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String realName()
{
String result;
result = this.realName;
//
return (result);
}
/**
*
*/
public void setGid(final int gid)
{
this.gid = gid;
}
/**
*
*/
public void setHomeDirectory(final String homeDirectory)
{
this.homeDirectory = homeDirectory;
}
/**
*
*/
public void setLogin(final String login)
{
this.login = login;
}
/**
*
*/
public void setPasswd(final String password)
{
this.password = password;
}
/**
*
*/
public void setPassword(final String password)
{
this.password = password;
}
/**
*
*/
public void setRealName(final String realName)
{
this.realName = realName;
}
/**
*
*/
public void setShell(final String shell)
{
this.shell = shell;
}
/**
*
*/
public void setUid(final int uid)
{
this.uid = uid;
}
/**
*
*/
public String shell()
{
String result;
result = this.shell;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = "|" + this.login + "|" + this.password + "|" + this.uid + "|" + this.gid + "|" + this.realName + "|" + this.homeDirectory + "|" + this.shell + "|";
//
return (result);
}
/**
*
*/
public int uid()
{
int result;
result = this.uid;
//
return (result);
}
}
package fr.devinsy.util.unix;
/**
*
*/
public class User
{
// static private final Logger logger = LoggerFactory.getLogger(User.class);
/*
* /usr/include/pwd.h
*
* The passwd structure.
* struct passwd
* {
* char *pw_name;D Username.
* char *pw_passwd; Password.
* __uid_t pw_uid; User ID.
* __gid_t pw_gid; Group ID.
* char *pw_gecos; Real name.
* char *pw_dir; Home directory.
* char *pw_shell; Shell program.
* };
*/
protected String login;
protected String password;
protected int uid;
protected int gid;
protected String realName;
protected String homeDirectory;
protected String shell;
/**
*
*/
public User()
{
this.login = null;
this.password = null;
this.uid = -1;
this.gid = -1;
this.realName = null;
this.homeDirectory = null;
this.shell = null;
}
/**
*
*/
public User(final User user)
{
this.login = user.login();
this.password = user.passwd();
this.uid = user.uid();
this.gid = user.gid();
this.realName = user.realName();
this.homeDirectory = user.homeDirectory();
this.shell = user.shell();
}
/**
*
*/
public int getGid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public String getHomeDirectory()
{
String result;
result = this.homeDirectory;
//
return (result);
}
/**
*
*/
public String getLogin()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String getPasswd()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String getPassword()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String getRealName()
{
String result;
result = this.realName;
//
return (result);
}
/**
*
*/
public String getShell()
{
String result;
result = this.shell;
//
return (result);
}
/**
*
*/
public int getUid()
{
int result;
result = this.uid;
//
return (result);
}
/**
*
*/
public int gid()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public String homeDirectory()
{
String result;
result = this.homeDirectory;
//
return (result);
}
/**
*
*/
public String login()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String passwd()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String realName()
{
String result;
result = this.realName;
//
return (result);
}
/**
*
*/
public void setGid(final int gid)
{
this.gid = gid;
}
/**
*
*/
public void setHomeDirectory(final String homeDirectory)
{
this.homeDirectory = homeDirectory;
}
/**
*
*/
public void setLogin(final String login)
{
this.login = login;
}
/**
*
*/
public void setPasswd(final String password)
{
this.password = password;
}
/**
*
*/
public void setPassword(final String password)
{
this.password = password;
}
/**
*
*/
public void setRealName(final String realName)
{
this.realName = realName;
}
/**
*
*/
public void setShell(final String shell)
{
this.shell = shell;
}
/**
*
*/
public void setUid(final int uid)
{
this.uid = uid;
}
/**
*
*/
public String shell()
{
String result;
result = this.shell;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = "|" + this.login + "|" + this.password + "|" + this.uid + "|" + this.gid + "|" + this.realName + "|" + this.homeDirectory + "|" + this.shell + "|";
//
return (result);
}
/**
*
*/
public int uid()
{
int result;
result = this.uid;
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,160 +1,160 @@
package fr.devinsy.util.unix;
import java.util.Iterator;
import java.util.Vector;
/**
*
*/
public class Users extends Vector<User>
{
private static final long serialVersionUID = -7178304512851592399L;
// static private final Logger logger =
// LoggerFactory.getLogger(Users.class);
/**
*
*/
public Users()
{
super();
}
/*
*
*/
public boolean contains(final int uid)
{
boolean result;
if (getByUid(uid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains(final String login)
{
boolean result;
if (getByLogin(login) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public User getByLogin(final String login)
{
User result;
if (login == null)
{
result = null;
}
else
{
result = null;
boolean ended = false;
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
User user = iterator.next();
if (user.getLogin().equals(login))
{
ended = true;
result = user;
}
}
else
{
ended = true;
result = null;
}
}
}
//
return (result);
}
/**
*
*/
public User getByUid(final int uid)
{
User result;
result = null;
boolean ended = false;
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
User user = iterator.next();
if (user.getUid() == uid)
{
ended = true;
result = user;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer out;
out = new StringBuffer();
Iterator<User> iterator = this.iterator();
while (iterator.hasNext())
{
out.append(iterator.next().toString() + "\n");
}
result = out.toString();
//
return (result);
}
}
package fr.devinsy.util.unix;
import java.util.Iterator;
import java.util.Vector;
/**
*
*/
public class Users extends Vector<User>
{
private static final long serialVersionUID = -7178304512851592399L;
// static private final Logger logger =
// LoggerFactory.getLogger(Users.class);
/**
*
*/
public Users()
{
super();
}
/*
*
*/
public boolean contains(final int uid)
{
boolean result;
if (getByUid(uid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains(final String login)
{
boolean result;
if (getByLogin(login) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public User getByLogin(final String login)
{
User result;
if (login == null)
{
result = null;
}
else
{
result = null;
boolean ended = false;
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
User user = iterator.next();
if (user.getLogin().equals(login))
{
ended = true;
result = user;
}
}
else
{
ended = true;
result = null;
}
}
}
//
return (result);
}
/**
*
*/
public User getByUid(final int uid)
{
User result;
result = null;
boolean ended = false;
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
User user = iterator.next();
if (user.getUid() == uid)
{
ended = true;
result = user;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer out;
out = new StringBuffer();
Iterator<User> iterator = this.iterator();
while (iterator.hasNext())
{
out.append(iterator.next().toString() + "\n");
}
result = out.toString();
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,197 +1,197 @@
package fr.devinsy.util.unix.acl;
/**
*
*/
public class Acl
{
// static private final Logger logger = LoggerFactory.getLogger(Acl.class);
/*
# file: goo39
# owner: goo39
# group: goo39
user::rwx
user:cpm:rwx #effective:rwx
user:goo39:rwx #effective:rwx
group::--- #effective:---
group:goo40:rwx #effective:rwx
mask::rwx
other::---
default:user::rwx
default:user:cpm:rwx #effective:rwx
default:group::--- #effective:---
default:group:cpm:rwx #effective:rwx
default:group:goo40:rwx #effective:rwx
default:mask::rwx
default:other::---
*/
protected String filePathname;
protected String owner;
protected String group;
protected AclEntries currentAcl;
protected AclEntries defaultAcl;
/**
*
*/
public Acl(final String filePathname)
{
this.filePathname = filePathname;
this.owner = "";
this.group = "";
this.currentAcl = new AclEntries();
this.defaultAcl = new AclEntries();
}
/**
*
*/
public boolean contains(final AclEntry.Type type, final String id)
{
boolean result;
if ((this.currentAcl().contains(type, id)) || (this.defaultAcl().contains(type, id)))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
public boolean containsGroup(final String group)
{
boolean result;
result = contains(AclEntry.Type.GROUP, group);
//
return (result);
}
/**
*
*/
public boolean containsId(final String id)
{
boolean result;
if ((containsUser(id) || containsGroup(id)))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
public boolean containsUser(final String login)
{
boolean result;
result = contains(AclEntry.Type.USER, login);
//
return (result);
}
/**
*
*/
public AclEntries currentAcl()
{
AclEntries result;
result = this.currentAcl;
//
return (result);
}
/**
*
*/
public AclEntries defaultAcl()
{
AclEntries result;
result = this.defaultAcl;
//
return (result);
}
/**
*
*/
public String filePathname()
{
String result;
result = this.filePathname;
//
return (result);
}
/**
*
*/
public String group()
{
String result;
result = this.group;
//
return (result);
}
/**
*
*/
public String owner()
{
String result;
result = this.owner;
//
return (result);
}
/**
*
*/
public void setGroup(final String group)
{
this.group = group;
}
/**
*
*/
public void setOwner(final String owner)
{
this.owner = owner;
}
}
package fr.devinsy.util.unix.acl;
/**
*
*/
public class Acl
{
// static private final Logger logger = LoggerFactory.getLogger(Acl.class);
/*
# file: goo39
# owner: goo39
# group: goo39
user::rwx
user:cpm:rwx #effective:rwx
user:goo39:rwx #effective:rwx
group::--- #effective:---
group:goo40:rwx #effective:rwx
mask::rwx
other::---
default:user::rwx
default:user:cpm:rwx #effective:rwx
default:group::--- #effective:---
default:group:cpm:rwx #effective:rwx
default:group:goo40:rwx #effective:rwx
default:mask::rwx
default:other::---
*/
protected String filePathname;
protected String owner;
protected String group;
protected AclEntries currentAcl;
protected AclEntries defaultAcl;
/**
*
*/
public Acl(final String filePathname)
{
this.filePathname = filePathname;
this.owner = "";
this.group = "";
this.currentAcl = new AclEntries();
this.defaultAcl = new AclEntries();
}
/**
*
*/
public boolean contains(final AclEntry.Type type, final String id)
{
boolean result;
if ((this.currentAcl().contains(type, id)) || (this.defaultAcl().contains(type, id)))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
public boolean containsGroup(final String group)
{
boolean result;
result = contains(AclEntry.Type.GROUP, group);
//
return (result);
}
/**
*
*/
public boolean containsId(final String id)
{
boolean result;
if ((containsUser(id) || containsGroup(id)))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
public boolean containsUser(final String login)
{
boolean result;
result = contains(AclEntry.Type.USER, login);
//
return (result);
}
/**
*
*/
public AclEntries currentAcl()
{
AclEntries result;
result = this.currentAcl;
//
return (result);
}
/**
*
*/
public AclEntries defaultAcl()
{
AclEntries result;
result = this.defaultAcl;
//
return (result);
}
/**
*
*/
public String filePathname()
{
String result;
result = this.filePathname;
//
return (result);
}
/**
*
*/
public String group()
{
String result;
result = this.group;
//
return (result);
}
/**
*
*/
public String owner()
{
String result;
result = this.owner;
//
return (result);
}
/**
*
*/
public void setGroup(final String group)
{
this.group = group;
}
/**
*
*/
public void setOwner(final String owner)
{
this.owner = owner;
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,197 +1,197 @@
package fr.devinsy.util.unix.acl;
import java.util.Iterator;
import java.util.Vector;
/**
*
*/
public class AclEntries extends Vector<AclEntry>
{
private static final long serialVersionUID = 5802487312198869603L;
// static private final Logger logger =
// LoggerFactory.getLogger(AclEntries.class);
/**
*
*/
public AclEntries()
{
super();
}
/*
*
*/
public boolean contains(final AclEntry.Type type, final String id)
{
boolean result;
if (this.get(type, id) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public boolean containsId(final String id)
{
boolean result;
if ((this.get(AclEntry.Type.USER, id) == null) && (this.get(AclEntry.Type.GROUP, id) == null))
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public AclEntry get(final AclEntry.Type type, final String id)
{
AclEntry result;
result = null;
boolean ended = false;
Iterator<AclEntry> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
AclEntry entry = iterator.next();
if ((type == entry.type()) && (entry.id().equals(id)))
{
ended = true;
result = entry;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/**
*
*/
public String[] getGroupIds()
{
String[] result;
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if ((entry.type == AclEntry.Type.GROUP) && (!ids.contains(entry.id())))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public String[] getIds()
{
String[] result;
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if (!ids.contains(entry.id()))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public String[] getUserIds()
{
String[] result;
//
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if ((entry.type == AclEntry.Type.USER) && (!ids.contains(entry.id())))
{
ids.add(entry.id());
}
}
//
result = new String[ids.size()];
for (int nId = 0; nId < ids.size(); nId++)
{
result[nId] = ids.get(nId);
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer out;
out = new StringBuffer();
Iterator<AclEntry> iterator = this.iterator();
while (iterator.hasNext())
{
out.append(iterator.next().toString() + "\n");
}
result = out.toString();
//
return (result);
}
}
package fr.devinsy.util.unix.acl;
import java.util.Iterator;
import java.util.Vector;
/**
*
*/
public class AclEntries extends Vector<AclEntry>
{
private static final long serialVersionUID = 5802487312198869603L;
// static private final Logger logger =
// LoggerFactory.getLogger(AclEntries.class);
/**
*
*/
public AclEntries()
{
super();
}
/*
*
*/
public boolean contains(final AclEntry.Type type, final String id)
{
boolean result;
if (this.get(type, id) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public boolean containsId(final String id)
{
boolean result;
if ((this.get(AclEntry.Type.USER, id) == null) && (this.get(AclEntry.Type.GROUP, id) == null))
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public AclEntry get(final AclEntry.Type type, final String id)
{
AclEntry result;
result = null;
boolean ended = false;
Iterator<AclEntry> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
AclEntry entry = iterator.next();
if ((type == entry.type()) && (entry.id().equals(id)))
{
ended = true;
result = entry;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/**
*
*/
public String[] getGroupIds()
{
String[] result;
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if ((entry.type == AclEntry.Type.GROUP) && (!ids.contains(entry.id())))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public String[] getIds()
{
String[] result;
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if (!ids.contains(entry.id()))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public String[] getUserIds()
{
String[] result;
//
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if ((entry.type == AclEntry.Type.USER) && (!ids.contains(entry.id())))
{
ids.add(entry.id());
}
}
//
result = new String[ids.size()];
for (int nId = 0; nId < ids.size(); nId++)
{
result[nId] = ids.get(nId);
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer out;
out = new StringBuffer();
Iterator<AclEntry> iterator = this.iterator();
while (iterator.hasNext())
{
out.append(iterator.next().toString() + "\n");
}
result = out.toString();
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,95 +1,95 @@
package fr.devinsy.util.unix.acl;
/**
*
*/
public class AclEntry
{
// static private final Logger logger =
// LoggerFactory.getLogger(AclEntry.class);
/*
user::rwx
user:cpm:rwx #effective:rwx
user:goo39:rwx #effective:rwx
group::--- #effective:---
group:goo40:rwx #effective:rwx
mask::rwx
other::---
*/
public enum Type
{
NONE, USER, GROUP, MASK, OTHER
};
protected Type type;
protected String id;
protected String permission;
/**
*
*/
public AclEntry(final Type type, final String id, final String permission)
{
this.type = type;
this.id = id;
this.permission = permission;
}
/**
*
*/
public String id()
{
String result;
result = this.id;
//
return (result);
}
/**
*
*/
public String permission()
{
String result;
result = this.type.toString() + ":" + this.id + ":" + this.permission;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = permission;
//
return (result);
}
/**
*
*/
public Type type()
{
Type result;
result = this.type;
//
return (result);
}
}
package fr.devinsy.util.unix.acl;
/**
*
*/
public class AclEntry
{
// static private final Logger logger =
// LoggerFactory.getLogger(AclEntry.class);
/*
user::rwx
user:cpm:rwx #effective:rwx
user:goo39:rwx #effective:rwx
group::--- #effective:---
group:goo40:rwx #effective:rwx
mask::rwx
other::---
*/
public enum Type
{
NONE, USER, GROUP, MASK, OTHER
};
protected Type type;
protected String id;
protected String permission;
/**
*
*/
public AclEntry(final Type type, final String id, final String permission)
{
this.type = type;
this.id = id;
this.permission = permission;
}
/**
*
*/
public String id()
{
String result;
result = this.id;
//
return (result);
}
/**
*
*/
public String permission()
{
String result;
result = this.type.toString() + ":" + this.id + ":" + this.permission;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = permission;
//
return (result);
}
/**
*
*/
public Type type()
{
Type result;
result = this.type;
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,405 +1,405 @@
package fr.devinsy.util.unix.acl;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.StringConcatenator;
import fr.devinsy.util.cmdexec.CmdExec;
import fr.devinsy.util.unix.Unix;
/**
*
*/
public class AclManager
{
static private final Logger logger = LoggerFactory.getLogger(AclManager.class);
static public final String SUDO = "/usr/bin/sudo";
static final public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$");
static final public Pattern GROUP_PATTERN = Pattern.compile("^group:(.*):(.*)$");
static final public Pattern MASK_PATTERN = Pattern.compile("^mask:(.*):(.*)$");
static final public Pattern OTHER_PATTERN = Pattern.compile("^other:(.*):(.*)$");
static final public Pattern DEFAULT_USER_PATTERN = Pattern.compile("^default:user:(.*):(.*)$");
static final public Pattern DEFAULT_GROUP_PATTERN = Pattern.compile("^default:group:(.*):(.*)$");
static final public Pattern DEFAULT_MASK_PATTERN = Pattern.compile("^default:mask:(.*):(.*)$");
static final public Pattern DEFAULT_OTHER_PATTERN = Pattern.compile("^default:other:(.*):(.*)$");
/**
*
*/
public static void clearGroup(final String group, final String filePathName) throws Exception
{
if ((group == null) || (group.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
{
throw new Exception("Bad parameters [" + group + "][" + filePathName + "].");
}
else
{
Unix.setfacl("-R", "-L", "-x", "group:" + group, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "group:" + group, filePathName);
}
}
/**
*
*/
public static void clearId(final String id, final String filePathName) throws Exception
{
clearUser(id, filePathName);
clearGroup(id, filePathName);
}
/**
*
*/
public static void clearUser(final String login, final String filePathName) throws Exception
{
if ((login == null) || (login.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
{
throw new Exception("Bad parameters [" + login + "][" + filePathName + "].");
}
else
{
Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "user:" + login, filePathName);
}
}
/**
*
*/
static public Acl getAcl(final String filePathName) throws Exception
{
Acl result;
result = new Acl(filePathName);
String[] entries = getAclEntryLines(filePathName);
// Login pattern: "^[a-z_][a-z0-9_-]*$".
logger.debug("Line=[" + entries[1] + "]");
Matcher matcher = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[1]);
if (matcher.matches())
{
logger.debug("group=[" + matcher.group(1) + "]");
result.setOwner(matcher.group(1));
}
// Group pattern: "^[a-z_][a-z0-9_-]*$".
logger.debug("Line=[" + entries[2] + "]");
matcher = Pattern.compile("^#\\sgroup:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[2]);
if (matcher.matches())
{
logger.debug("group=[" + matcher.group(1) + "]");
result.setOwner(matcher.group(1));
}
for (int nEntry = 3; nEntry < entries.length; nEntry++)
{
String entryLine = entries[nEntry];
logger.debug("Line=[" + entryLine + "]");
//
Matcher userMatcher = USER_PATTERN.matcher(entryLine);
Matcher groupMatcher = GROUP_PATTERN.matcher(entryLine);
Matcher maskMatcher = MASK_PATTERN.matcher(entryLine);
Matcher otherMatcher = OTHER_PATTERN.matcher(entryLine);
Matcher defaultUserMatcher = DEFAULT_USER_PATTERN.matcher(entryLine);
Matcher defaultGroupMatcher = DEFAULT_GROUP_PATTERN.matcher(entryLine);
Matcher defaultMaskMatcher = DEFAULT_MASK_PATTERN.matcher(entryLine);
Matcher defaultOtherMatcher = DEFAULT_OTHER_PATTERN.matcher(entryLine);
AclEntry entry;
if (userMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.USER, userMatcher.group(1), userMatcher.group(2));
result.currentAcl().add(entry);
}
else if (groupMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.GROUP, groupMatcher.group(1), groupMatcher.group(2));
result.currentAcl().add(entry);
}
else if (maskMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.MASK, maskMatcher.group(1), maskMatcher.group(2));
result.currentAcl().add(entry);
}
else if (otherMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.OTHER, otherMatcher.group(1), otherMatcher.group(2));
result.currentAcl().add(entry);
}
else if (defaultUserMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.USER, defaultUserMatcher.group(1), defaultUserMatcher.group(2));
result.defaultAcl().add(entry);
}
else if (defaultGroupMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.GROUP, defaultGroupMatcher.group(1), defaultGroupMatcher.group(2));
result.defaultAcl().add(entry);
}
else if (defaultMaskMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.MASK, defaultMaskMatcher.group(1), defaultMaskMatcher.group(2));
result.defaultAcl().add(entry);
}
else if (defaultOtherMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.OTHER, defaultOtherMatcher.group(1), defaultOtherMatcher.group(2));
result.defaultAcl().add(entry);
}
else
{
throw new Exception("Unknow ACL entry line pattern for [" + entryLine + "].");
}
logger.debug("Acl entry decoded: [" + entry.toString() + "]");
}
//
return (result);
}
/**
*
*/
static public String getAclData(final String filePathName) throws Exception
{
String result;
try
{
logger.info("Getting Acl data for [" + filePathName + "].");
result = CmdExec.run(SUDO, "/usr/bin/getfacl", "--no-effective", filePathName);
logger.info("Acl data got for [" + filePathName + "].");
}
catch (Exception exception)
{
throw new Exception("Error getting ACL for [" + filePathName + "].", exception);
}
//
return (result);
}
/**
*
*/
static public String[] getAclEntryLines(final String filePathName)
{
String[] result;
try
{
result = getAclData(filePathName).split("\n");
}
catch (Exception exception)
{
result = new String[0];
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName) throws Exception
{
boolean result;
result = isUsed(type, id, filePathName, 0);
//
return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName, final int depth) throws Exception
{
boolean result;
if ((type == null) || (id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
{
throw new Exception("Bad parameter: [" + type + "][" + id + "][" + filePathName + "][" + depth + "].");
}
else
{
File file = new File(filePathName);
if (!file.exists())
{
throw new Exception("File does not exist [" + filePathName + "].");
}
else
{
Acl acl = getAcl(filePathName);
if (acl.contains(type, id))
{
result = true;
}
else if ((file.isDirectory()) && (depth > 0))
{
result = isUsed(type, id, filePathName, file.list(), depth - 1);
}
else
{
result = false;
}
}
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePath, final String[] filePathNames, final int depth) throws Exception
{
boolean result;
result = false;
boolean ended = false;
int nLine = 0;
while (!ended)
{
if (nLine < filePathNames.length)
{
String filePathName = filePathNames[nLine];
if (isUsed(type, id, filePath + "/" + filePathName, depth))
{
ended = true;
result = true;
}
else
{
nLine += 1;
}
}
else
{
ended = true;
result = false;
}
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String filePathName) throws Exception
{
boolean result;
result = isUsed(id, filePathName, 0);
//
return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String filePathName, final int depth) throws Exception
{
boolean result;
if ((id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
{
throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "].");
}
else
{
File file = new File(filePathName);
if (!file.exists())
{
throw new Exception("File does not exist [" + filePathName + "].");
}
else
{
Acl acl = getAcl(filePathName);
if (acl.containsId(id))
{
result = true;
}
else if ((file.isDirectory()) && (depth > 0))
{
result = isUsed(id, file.list(), depth - 1);
}
else
{
result = false;
}
}
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String[] filePathNames, final int depth) throws Exception
{
boolean result;
result = false;
boolean ended = false;
int nLine = 0;
while (!ended)
{
if (nLine < filePathNames.length)
{
String filePathName = filePathNames[nLine];
if (isUsed(id, filePathName, depth))
{
ended = true;
result = true;
}
else
{
nLine += 1;
}
}
else
{
ended = true;
result = false;
}
}
//
return (result);
}
/**
*
*/
static public void setfacl(final String... args) throws Exception
{
try
{
CmdExec.run(SUDO, "setfacl", args, 1, 5);
}
catch (Exception exception)
{
throw new Exception("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
}
}
}
package fr.devinsy.util.unix.acl;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.StringConcatenator;
import fr.devinsy.util.cmdexec.CmdExec;
import fr.devinsy.util.unix.Unix;
/**
*
*/
public class AclManager
{
static private final Logger logger = LoggerFactory.getLogger(AclManager.class);
static public final String SUDO = "/usr/bin/sudo";
static final public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$");
static final public Pattern GROUP_PATTERN = Pattern.compile("^group:(.*):(.*)$");
static final public Pattern MASK_PATTERN = Pattern.compile("^mask:(.*):(.*)$");
static final public Pattern OTHER_PATTERN = Pattern.compile("^other:(.*):(.*)$");
static final public Pattern DEFAULT_USER_PATTERN = Pattern.compile("^default:user:(.*):(.*)$");
static final public Pattern DEFAULT_GROUP_PATTERN = Pattern.compile("^default:group:(.*):(.*)$");
static final public Pattern DEFAULT_MASK_PATTERN = Pattern.compile("^default:mask:(.*):(.*)$");
static final public Pattern DEFAULT_OTHER_PATTERN = Pattern.compile("^default:other:(.*):(.*)$");
/**
*
*/
public static void clearGroup(final String group, final String filePathName) throws Exception
{
if ((group == null) || (group.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
{
throw new Exception("Bad parameters [" + group + "][" + filePathName + "].");
}
else
{
Unix.setfacl("-R", "-L", "-x", "group:" + group, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "group:" + group, filePathName);
}
}
/**
*
*/
public static void clearId(final String id, final String filePathName) throws Exception
{
clearUser(id, filePathName);
clearGroup(id, filePathName);
}
/**
*
*/
public static void clearUser(final String login, final String filePathName) throws Exception
{
if ((login == null) || (login.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
{
throw new Exception("Bad parameters [" + login + "][" + filePathName + "].");
}
else
{
Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "user:" + login, filePathName);
}
}
/**
*
*/
static public Acl getAcl(final String filePathName) throws Exception
{
Acl result;
result = new Acl(filePathName);
String[] entries = getAclEntryLines(filePathName);
// Login pattern: "^[a-z_][a-z0-9_-]*$".
logger.debug("Line=[" + entries[1] + "]");
Matcher matcher = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[1]);
if (matcher.matches())
{
logger.debug("group=[" + matcher.group(1) + "]");
result.setOwner(matcher.group(1));
}
// Group pattern: "^[a-z_][a-z0-9_-]*$".
logger.debug("Line=[" + entries[2] + "]");
matcher = Pattern.compile("^#\\sgroup:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[2]);
if (matcher.matches())
{
logger.debug("group=[" + matcher.group(1) + "]");
result.setOwner(matcher.group(1));
}
for (int nEntry = 3; nEntry < entries.length; nEntry++)
{
String entryLine = entries[nEntry];
logger.debug("Line=[" + entryLine + "]");
//
Matcher userMatcher = USER_PATTERN.matcher(entryLine);
Matcher groupMatcher = GROUP_PATTERN.matcher(entryLine);
Matcher maskMatcher = MASK_PATTERN.matcher(entryLine);
Matcher otherMatcher = OTHER_PATTERN.matcher(entryLine);
Matcher defaultUserMatcher = DEFAULT_USER_PATTERN.matcher(entryLine);
Matcher defaultGroupMatcher = DEFAULT_GROUP_PATTERN.matcher(entryLine);
Matcher defaultMaskMatcher = DEFAULT_MASK_PATTERN.matcher(entryLine);
Matcher defaultOtherMatcher = DEFAULT_OTHER_PATTERN.matcher(entryLine);
AclEntry entry;
if (userMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.USER, userMatcher.group(1), userMatcher.group(2));
result.currentAcl().add(entry);
}
else if (groupMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.GROUP, groupMatcher.group(1), groupMatcher.group(2));
result.currentAcl().add(entry);
}
else if (maskMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.MASK, maskMatcher.group(1), maskMatcher.group(2));
result.currentAcl().add(entry);
}
else if (otherMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.OTHER, otherMatcher.group(1), otherMatcher.group(2));
result.currentAcl().add(entry);
}
else if (defaultUserMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.USER, defaultUserMatcher.group(1), defaultUserMatcher.group(2));
result.defaultAcl().add(entry);
}
else if (defaultGroupMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.GROUP, defaultGroupMatcher.group(1), defaultGroupMatcher.group(2));
result.defaultAcl().add(entry);
}
else if (defaultMaskMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.MASK, defaultMaskMatcher.group(1), defaultMaskMatcher.group(2));
result.defaultAcl().add(entry);
}
else if (defaultOtherMatcher.matches())
{
entry = new AclEntry(AclEntry.Type.OTHER, defaultOtherMatcher.group(1), defaultOtherMatcher.group(2));
result.defaultAcl().add(entry);
}
else
{
throw new Exception("Unknow ACL entry line pattern for [" + entryLine + "].");
}
logger.debug("Acl entry decoded: [" + entry.toString() + "]");
}
//
return (result);
}
/**
*
*/
static public String getAclData(final String filePathName) throws Exception
{
String result;
try
{
logger.info("Getting Acl data for [" + filePathName + "].");
result = CmdExec.run(SUDO, "/usr/bin/getfacl", "--no-effective", filePathName);
logger.info("Acl data got for [" + filePathName + "].");
}
catch (Exception exception)
{
throw new Exception("Error getting ACL for [" + filePathName + "].", exception);
}
//
return (result);
}
/**
*
*/
static public String[] getAclEntryLines(final String filePathName)
{
String[] result;
try
{
result = getAclData(filePathName).split("\n");
}
catch (Exception exception)
{
result = new String[0];
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName) throws Exception
{
boolean result;
result = isUsed(type, id, filePathName, 0);
//
return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName, final int depth) throws Exception
{
boolean result;
if ((type == null) || (id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
{
throw new Exception("Bad parameter: [" + type + "][" + id + "][" + filePathName + "][" + depth + "].");
}
else
{
File file = new File(filePathName);
if (!file.exists())
{
throw new Exception("File does not exist [" + filePathName + "].");
}
else
{
Acl acl = getAcl(filePathName);
if (acl.contains(type, id))
{
result = true;
}
else if ((file.isDirectory()) && (depth > 0))
{
result = isUsed(type, id, filePathName, file.list(), depth - 1);
}
else
{
result = false;
}
}
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePath, final String[] filePathNames, final int depth) throws Exception
{
boolean result;
result = false;
boolean ended = false;
int nLine = 0;
while (!ended)
{
if (nLine < filePathNames.length)
{
String filePathName = filePathNames[nLine];
if (isUsed(type, id, filePath + "/" + filePathName, depth))
{
ended = true;
result = true;
}
else
{
nLine += 1;
}
}
else
{
ended = true;
result = false;
}
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String filePathName) throws Exception
{
boolean result;
result = isUsed(id, filePathName, 0);
//
return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String filePathName, final int depth) throws Exception
{
boolean result;
if ((id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
{
throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "].");
}
else
{
File file = new File(filePathName);
if (!file.exists())
{
throw new Exception("File does not exist [" + filePathName + "].");
}
else
{
Acl acl = getAcl(filePathName);
if (acl.containsId(id))
{
result = true;
}
else if ((file.isDirectory()) && (depth > 0))
{
result = isUsed(id, file.list(), depth - 1);
}
else
{
result = false;
}
}
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String[] filePathNames, final int depth) throws Exception
{
boolean result;
result = false;
boolean ended = false;
int nLine = 0;
while (!ended)
{
if (nLine < filePathNames.length)
{
String filePathName = filePathNames[nLine];
if (isUsed(id, filePathName, depth))
{
ended = true;
result = true;
}
else
{
nLine += 1;
}
}
else
{
ended = true;
result = false;
}
}
//
return (result);
}
/**
*
*/
static public void setfacl(final String... args) throws Exception
{
try
{
CmdExec.run(SUDO, "setfacl", args, 1, 5);
}
catch (Exception exception)
{
throw new Exception("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
}
}
}
// ////////////////////////////////////////////////////////////////////////