-{
- private static StringLengthComparator instance;
-
- /**
- *
- */
- @Override
- public int compare(final String alpha, final String bravo)
- {
- int result;
-
- //
- Integer alphaValue;
- if (alpha == null)
- {
- //
- alphaValue = null;
-
- }
- else
- {
- //
- alphaValue = alpha.length();
- }
-
- //
- Integer bravoValue;
- if (bravo == null)
- {
- //
- bravoValue = null;
-
- }
- else
- {
- //
- bravoValue = bravo.length();
- }
-
- //
- result = compare(alphaValue, bravoValue);
-
- //
- return result;
- }
-
- /**
- * This method compares two nullable string values.
- *
- * The comparison manages the local language alphabet order.
- *
- *
- * compare(null, null) = 0
- * compare(null, bravo) < 0
- * compare(alpha, null) > 0
- * compare(alpha, bravo) = alpha.compareTo(bravo)
- *
- *
- * @param alpha
- * one of the value.
- *
- * @param bravo
- * the other value.
- *
- * @return zero or a positive value or a negative value.
- *
- */
- public static int compare(final Integer alpha, final Integer bravo)
- {
- int result;
-
- //
- if ((alpha == null) && (bravo == null))
- {
- //
- result = 0;
-
- }
- else if (alpha == null)
- {
- //
- result = -1;
-
- }
- else if (bravo == null)
- {
- //
- result = +1;
-
- }
- else
- {
- //
- result = alpha.compareTo(bravo);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public static StringLengthComparator instance()
- {
- StringLengthComparator result;
-
- if (instance == null)
- {
- instance = new StringLengthComparator();
- }
-
- result = instance;
-
- //
- return result;
- }
-
-}
diff --git a/src/fr/devinsy/util/strings/StringList.java b/src/fr/devinsy/util/strings/StringList.java
deleted file mode 100644
index 873f541..0000000
--- a/src/fr/devinsy/util/strings/StringList.java
+++ /dev/null
@@ -1,1584 +0,0 @@
-/**
- * Copyright (C) 2008-2010, 2013-2015 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.io.IOException;
-import java.text.Collator;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-
-import org.apache.commons.lang3.StringUtils;
-
-/**
- * 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 StringList extends ArrayList implements CharSequence
-{
- private static final long serialVersionUID = -1154185934830213732L;
-
- public static final String LINE_SEPARATOR = "\n";
-
- /**
- * Constructs an empty list with an initial capacity of ten (see ArrayList
- * constructor).
- */
- public StringList()
- {
- super();
- }
-
- /**
- * Constructs a list of string of the specified collection, in the order
- * they are returned by the collection's iterator.
- *
- * @param source
- */
- public StringList(final Collection source)
- {
- super();
-
- if (source != null)
- {
- //
- ensureCapacity(source.size());
-
- //
- for (String string : source)
- {
- this.add(string);
- }
- }
- }
-
- /**
- * Constructs an empty list with the specified initial capacity.
- *
- * @param initialCapacity
- */
- public StringList(final int initialCapacity)
- {
- super(initialCapacity);
- }
-
- /**
- * Constructs a list of string from a string array.
- *
- * @param source
- */
- public StringList(final String... source)
- {
- super();
-
- if (source != null)
- {
- //
- ensureCapacity(source.length);
-
- //
- for (String string : source)
- {
- this.add(string);
- }
- }
- }
-
- /**
- * Appends the string representation of the char argument to this string
- * list.
- *
- * @param character
- * @return
- */
- public StringList append(final char character)
- {
- StringList result;
-
- this.add(String.valueOf(character));
-
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Appends the string of the specified collection, in the order they are
- * returned by the collection's iterator.
- *
- * @param strings
- * @return
- */
- public StringList append(final Collection strings)
- {
- StringList result;
-
- if (strings != null)
- {
- for (String string : strings)
- {
- this.append(string);
- }
- }
-
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Appends the string representation of the double argument to this string
- * list.
- *
- * @param value
- * @return
- */
- public StringList append(final double value)
- {
- StringList result;
-
- result = this.append(String.valueOf(value));
-
- //
- return (result);
- }
-
- /**
- * Appends the string representation of the int argument to this string
- * list.
- *
- * @param value
- * @return
- */
- public StringList append(final int value)
- {
- StringList result;
-
- result = this.append(String.valueOf(value));
-
- //
- return (result);
- }
-
- /**
- * Appends the string representation of the long argument to this string
- * list.
- *
- * @param value
- * @return
- */
- public StringList append(final long value)
- {
- StringList result;
-
- result = this.append(String.valueOf(value));
-
- //
- return (result);
- }
-
- /**
- * Appends the string representation of the int argument to this string
- * list.
- *
- * @param value
- * @return
- */
- public StringList append(final Object value)
- {
- StringList result;
-
- if (value != null)
- {
- this.append(value.toString());
- }
-
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Appends the string representation of the long argument to this string
- * list.
- *
- * @param value
- * @return
- */
- public StringList append(final short value)
- {
- StringList result;
-
- result = this.append(String.valueOf(value));
-
- //
- return (result);
- }
-
- /**
- * Appends the string argument to this string list.
- *
- * Check null parameter before add.
- *
- * @param string
- * @return
- */
- public StringList append(final String string)
- {
- StringList result;
-
- if (string != null)
- {
- this.add(string);
- }
-
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Appends the string of the array argument to this string list.
- *
- * @param strings
- * @return
- */
- public StringList append(final String... strings)
- {
- StringList result;
-
- if (strings != null)
- {
- for (String string : strings)
- {
- this.add(string);
- }
- }
-
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Appends a break line to this string list.
- *
- * @return
- */
- public StringList appendln()
- {
- StringList result;
-
- this.add(LINE_SEPARATOR);
-
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Appends the string representation of the char argument to this string
- * list, then append a break line too.
- *
- * @param character
- * @return
- */
- public StringList appendln(final char character)
- {
- StringList result;
-
- result = this.append(character).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param string
- * @return
- */
- public StringList appendln(final Collection string)
- {
- StringList result;
-
- result = this.append(string).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param value
- * @return
- */
- public StringList appendln(final double value)
- {
- StringList result;
-
- result = this.append(value).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param value
- * @return
- */
- public StringList appendln(final int value)
- {
- StringList result;
-
- result = this.append(value).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param value
- * @return
- */
- public StringList appendln(final long value)
- {
- StringList result;
-
- result = this.append(value).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param value
- * @return
- */
- public StringList appendln(final Object value)
- {
- StringList result;
-
- result = this.append(value).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param value
- * @return
- */
- public StringList appendln(final short value)
- {
- StringList result;
-
- result = this.append(value).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param string
- * @return
- */
- public StringList appendln(final String string)
- {
- StringList result;
-
- result = this.append(string).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public StringList appendln(final String... strings)
- {
- StringList result;
-
- result = this.append(strings).appendln();
-
- //
- return (result);
- }
-
- /**
- *
- */
- @Override
- public char charAt(final int index)
- {
- char result;
-
- //
- StringListCharPosition position = indexOf(index);
-
- //
- result = get(position.getStringIndex()).charAt(position.getLocalCharIndex());
-
- //
- return result;
- }
-
- /**
- *
- * @param position
- * @return
- */
- public char charAt(final StringListCharPosition position)
- {
- char result;
-
- //
- result = get(position.getStringIndex()).charAt(position.getLocalCharIndex());
-
- //
- return result;
- }
-
- /**
- * Deep copy and shallow copy have no sense about a list of immutable
- * objects.
- *
- * @return
- */
- @Override
- public StringList clone()
- {
- StringList result;
-
- result = new StringList(size());
-
- for (String string : this)
- {
- result.add(string);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public boolean containsAny(final Collection target)
- {
- boolean result;
-
- if (target == null)
- {
- result = false;
- }
- else
- {
- boolean ended = false;
- Iterator iterator = target.iterator();
- result = false;
- while (!ended)
- {
- if (iterator.hasNext())
- {
- String current = iterator.next();
-
- if (this.contains(current))
- {
- ended = true;
- result = true;
- }
- }
- else
- {
- ended = true;
- result = false;
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public boolean containsAny(final String... target)
- {
- boolean result;
-
- if (target == null)
- {
- result = false;
- }
- else
- {
- boolean ended = false;
- int index = 0;
- result = false;
- while (!ended)
- {
- if (index < target.length)
- {
- String current = target[index];
-
- if (this.contains(current))
- {
- ended = true;
- result = true;
- }
- else
- {
- index += 1;
- }
- }
- else
- {
- ended = true;
- result = false;
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public boolean containsBlank()
- {
- boolean result;
-
- boolean ended = false;
- Iterator iterator = iterator();
- result = false;
- while (!ended)
- {
- if (iterator.hasNext())
- {
- String line = iterator.next();
-
- if (StringUtils.isBlank(line))
- {
- ended = true;
- result = true;
- }
- }
- else
- {
- ended = true;
- result = false;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public boolean containsEmpty()
- {
- boolean result;
-
- boolean ended = false;
- Iterator iterator = iterator();
- result = false;
- while (!ended)
- {
- if (iterator.hasNext())
- {
- String line = iterator.next();
-
- if (StringUtils.isEmpty(line))
- {
- ended = true;
- result = true;
- }
- }
- else
- {
- ended = true;
- result = false;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public boolean containsNull()
- {
- boolean result;
-
- boolean ended = false;
- Iterator iterator = iterator();
- result = false;
- while (!ended)
- {
- if (iterator.hasNext())
- {
- String line = iterator.next();
-
- if (line == null)
- {
- ended = true;
- result = true;
- }
- }
- else
- {
- ended = true;
- result = false;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param id
- * @return
- */
- public String getByIndex(final int id)
- {
- String result;
-
- result = this.get(id);
-
- //
- return (result);
- }
-
- /**
- *
- * @return
- */
- public String getFirst()
- {
- String result;
-
- if (this.size() == 0)
- {
- result = null;
- }
- else
- {
- result = get(0);
- }
-
- //
- return (result);
- }
-
- /**
- *
- * @return
- */
- public String getLast()
- {
- String result;
-
- if (this.size() == 0)
- {
- result = null;
- }
- else
- {
- result = get(this.size() - 1);
- }
-
- //
- return (result);
- }
-
- /**
- *
- * @return
- */
- public String getLongestBytesLine()
- {
- String result;
-
- if (isEmpty())
- {
- result = null;
- }
- else
- {
- int max = 0;
- result = "";
- for (String line : this)
- {
- if (line.getBytes().length > max)
- {
- max = line.length();
- result = line;
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public String getLongestLine()
- {
- String result;
-
- if (isEmpty())
- {
- result = null;
- }
- else
- {
- int max = 0;
- result = "";
- for (String line : this)
- {
- if (line.length() > max)
- {
- max = line.length();
- result = line;
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public StringList getNotBlank()
- {
- StringList result;
-
- result = new StringList();
-
- for (String line : this)
- {
- if (StringUtils.isNotBlank(line))
- {
- result.add(line);
- }
- }
-
- //
- return (result);
- }
-
- /**
- *
- * @return
- */
- public StringList getNotEmpty()
- {
- StringList result;
-
- result = new StringList();
-
- for (String line : this)
- {
- if (StringUtils.isNotEmpty(line))
- {
- result.add(line);
- }
- }
-
- //
- return (result);
- }
-
- /**
- *
- * @return
- */
- public StringList getNotNull()
- {
- StringList result;
-
- result = new StringList();
-
- for (String line : this)
- {
- if (line != null)
- {
- result.add(line);
- }
- }
-
- //
- return (result);
- }
-
- /**
- *
- * @return
- */
- public String getShortestBytesLine()
- {
- String result;
-
- if (isEmpty())
- {
- result = null;
- }
- else
- {
- int min = Integer.MAX_VALUE;
- result = null;
- for (String line : this)
- {
- if (line.getBytes().length < min)
- {
- min = line.length();
- result = line;
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public String getShortestLine()
- {
- String result;
-
- if (isEmpty())
- {
- result = null;
- }
- else
- {
- int min = Integer.MAX_VALUE;
- result = null;
- for (String line : this)
- {
- if (line.length() < min)
- {
- min = line.length();
- result = line;
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param index
- * @return
- */
- public StringListCharPosition indexOf(final int index)
- {
- StringListCharPosition result;
-
- if ((index < 0) || (index >= length()))
- {
- throw new StringIndexOutOfBoundsException(index);
- }
- else
- {
- boolean ended = false;
- int stringIndex = 0;
- int currentLength = 0;
- result = null;
- while (!ended)
- {
- if (index < currentLength + get(stringIndex).length())
- {
- ended = true;
- result = new StringListCharPosition(index, stringIndex, index - currentLength);
- }
- else
- {
- stringIndex += 1;
- currentLength += get(stringIndex).length();
- }
- }
-
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param startIndex
- * @return the index of the next line not null, -1 otherwise.
- */
- public int indexOfNextLineNotNull(final int startIndex)
- {
- int result;
-
- boolean ended = false;
- int currentIndex = startIndex;
- result = -1;
- while (!ended)
- {
- if (currentIndex >= this.size())
- {
- ended = true;
- result = -1;
- }
- else
- {
- if (this.get(currentIndex) == null)
- {
- ended = true;
- result = currentIndex;
- }
- else
- {
- currentIndex += 1;
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param position
- * @return
- */
- public boolean isOutOfBounds(final StringListCharPosition position)
- {
- boolean result;
-
- if (position == null)
- {
- result = true;
- }
- else
- {
- if (isOutOfList(position))
- {
- result = true;
- }
- else if (isOutOfLine(position))
- {
- result = true;
- }
- else
- {
- result = false;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param position
- * @return
- */
- public boolean isOutOfLine(final StringListCharPosition position)
- {
- boolean result;
-
- if (position == null)
- {
- result = true;
- }
- else
- {
- if (position.getLocalCharIndex() >= this.get(position.getStringIndex()).length())
- {
- result = true;
- }
- else
- {
- result = false;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param position
- * @return
- */
- public boolean isOutOfList(final StringListCharPosition position)
- {
- boolean result;
-
- if (position == null)
- {
- result = true;
- }
- else
- {
- if (position.getStringIndex() >= this.size())
- {
- result = true;
- }
- else
- {
- result = false;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- */
- public Iterator iteratorOfChar()
- {
- Iterator result;
-
- result = new StringListCharIterator(this);
-
- //
- return result;
- }
-
- /**
- * Returns the length of the string list concatenation. Null strings are
- * ignored.
- */
- @Override
- public int length()
- {
- int result = 0;
-
- for (String string : this)
- {
- if (string != null)
- {
- result += string.length();
- }
- }
-
- //
- return (result);
- }
-
- /**
- * Merge all strings of the list into in single string. At the end of
- * operation, the new string is the first of the list and the size list is
- * 1.
- *
- * @return
- */
- public StringList merge()
- {
- StringList result;
-
- String merge = this.toString();
-
- clear();
- add(merge);
-
- result = this;
-
- //
- return result;
- }
-
- /**
- * Removes the last element of the list.
- *
- * @return This list.
- */
- public StringList removeLast()
- {
- StringList result;
-
- if (this.size() > 0)
- {
- this.remove(this.size() - 1);
- }
-
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Extends the list copying the last element a number of time.
- *
- * @param count
- * The number of time to copy the last element.
- *
- * @return This list.
- */
- public StringList repeatLast(final int count)
- {
- StringList result;
-
- //
- if ((this.size() != 0) && (count > 0))
- {
- //
- this.ensureCapacity(this.size() + count);
-
- //
- String last = getLast();
-
- //
- for (int index = 0; index < count; index++)
- {
- this.append(last);
- }
- }
-
- //
- result = this;
-
- //
- return (result);
- }
-
- /**
- * Sorts this list.
- *
- * @return This List.
- */
- public StringList reverse()
- {
- StringList result;
-
- Collections.reverse(this);
-
- //
- result = this;
-
- //
- return result;
- }
-
- /**
- * Sorts this list.
- *
- * @return This List.
- */
- public StringList sort()
- {
- StringList result;
-
- Collections.sort(this, Collator.getInstance());
-
- //
- result = this;
-
- //
- return result;
- }
-
- /**
- * Sorts this list.
- *
- * @return This List.
- */
- public StringList sort(final Comparator comparator)
- {
- StringList result;
-
- Collections.sort(this, comparator);
-
- //
- result = this;
-
- //
- return result;
- }
-
- /**
- * Sorts this list.
- *
- * @return This List.
- */
- public StringList sortByLength()
- {
- StringList result;
-
- Collections.sort(this, StringLengthComparator.instance());
-
- //
- result = this;
-
- //
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public CharSequence subSequence(final int start, final int end)
- {
- StringList result;
-
- result = substring(start, end);
-
- //
- return result;
- }
-
- /**
- * Extracts a substring from this list.
- *
- * @param start
- * The first character of the substring.
- * @param end
- * The last character of the substring.
- *
- * @return The sublist targeted.
- */
- public StringList substring(final int beginIndex, final int endIndex)
- {
- StringList result;
-
- if (beginIndex < 0)
- {
- throw new StringIndexOutOfBoundsException(beginIndex);
- }
- else if (endIndex > length())
- {
- throw new StringIndexOutOfBoundsException(endIndex);
- }
- else if (beginIndex > endIndex)
- {
- throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
- }
- else if (beginIndex == endIndex)
- {
- result = new StringList();
- }
- else
- {
- //
- result = new StringList();
-
- //
- StringListCharPosition startPosition = indexOf(beginIndex);
- StringListCharPosition endPosition = indexOf(endIndex);
-
- //
- if (startPosition.getStringIndex() == endPosition.getStringIndex())
- {
- String source = get(startPosition.getStringIndex());
- String target = source.substring(startPosition.getLocalCharIndex(), endPosition.getLocalCharIndex());
- result.append(target);
- }
- else
- {
- //
- {
- String source = get(startPosition.getStringIndex());
- String target = source.substring(startPosition.getLocalCharIndex());
- result.append(target);
- }
-
- //
- for (int stringIndex = startPosition.getStringIndex() + 1; stringIndex < endPosition.getStringIndex(); stringIndex++)
- {
- String target = get(stringIndex);
- result.append(target);
- }
-
- //
- {
- String source = get(endPosition.getStringIndex());
- String target = source.substring(0, endPosition.getLocalCharIndex());
- result.append(target);
- }
- }
- }
-
- //
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
- {
- String result;
-
- if (size() == 1)
- {
- //
- result = get(0);
-
- }
- else
- {
- //
- StringBuffer buffer = new StringBuffer(length());
-
- for (String string : this)
- {
- buffer.append(string);
- }
-
- result = buffer.toString();
- }
-
- //
- return (result);
- }
-
- /**
- *
- * @param prefix
- * @param separator
- * @param postifx
- * @return
- */
- public String toString(final String prefix, final String separator, final String postfix)
- {
- String result;
-
- StringList buffer = new StringList(1 + size() * 2 + 1);
-
- buffer.append(prefix);
-
- for (String string : this)
- {
- buffer.append(string);
- buffer.append(separator);
- }
-
- if (separator != null)
- {
- buffer.removeLast();
- }
-
- buffer.append(postfix);
-
- result = buffer.toString();
-
- //
- return result;
- }
-
- /**
- * Returns an array containing all of the strings in this list in proper
- * sequence (from first to last element).
- *
- * @return
- */
- public String[] toStringArray()
- {
- String[] result;
-
- result = new String[this.size()];
-
- for (int index = 0; index < size(); index++)
- {
- result[index] = get(index);
- }
-
- //
- return result;
- }
-
- /**
- * Returns a string containing the concatenation of the strings of this
- * list. Between each string of this list, a separator argument string is
- * concatenated too.
- *
- * @param separator
- *
- * @return
- */
- public String toStringSeparatedBy(final String separator)
- {
- String result;
-
- StringList buffer = new StringList(this.size() * 2);
-
- for (String string : this)
- {
- buffer.append(string);
- buffer.append(separator);
- }
-
- if (separator != null)
- {
- buffer.removeLast();
- }
-
- result = buffer.toString();
-
- //
- return (result);
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public String toStringWithBracket()
- {
- String result;
-
- result = toString("[", ",", "]");
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public String toStringWithBrackets()
- {
- String result;
-
- StringList buffer = new StringList();
-
- for (String string : this)
- {
- buffer.append("[").append(string).append("]");
- }
-
- result = buffer.toString();
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public String toStringWithCommas()
- {
- String result;
-
- result = this.toStringSeparatedBy(",");
-
- //
- return (result);
- }
-
- /**
- *
- * @return
- */
- public String toStringWithFrenchCommas()
- {
- String result;
-
- result = this.toStringSeparatedBy(", ");
-
- //
- return (result);
- }
-
- /**
- * Writes the strings of this list into a {@code PrintWriter}.
- *
- * @param out
- * The {@code PrintWriter} where to write.
- *
- * @throws IOException
- */
- public void writeInto(final java.io.PrintWriter out) throws IOException
- {
- for (String string : this)
- {
- out.write(string);
- }
- }
-
- /**
- * Writes the strings of this list into a {@code Writer}.
- *
- * @param out
- * The {@code Writer} where to write.
- *
- * @throws IOException
- */
- public void writeInto(final java.io.Writer out) throws IOException
- {
- for (String string : this)
- {
- out.write(string);
- }
- }
-}
diff --git a/src/fr/devinsy/util/strings/StringListCharIterator.java b/src/fr/devinsy/util/strings/StringListCharIterator.java
deleted file mode 100644
index 4f84c1b..0000000
--- a/src/fr/devinsy/util/strings/StringListCharIterator.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * Copyright (C) 2014-2015 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.util.Iterator;
-
-/**
- *
- */
-public class StringListCharIterator implements Iterator
-{
- private StringList source;
- private StringListCharPosition currentPosition;
- private StringListCharPosition nextPosition;
-
- /**
- *
- */
- public StringListCharIterator(final StringList source)
- {
- super();
-
- this.source = source;
- this.nextPosition = new StringListCharPosition();
- }
-
- /**
- *
- */
- @Override
- public boolean hasNext()
- {
- boolean result;
-
- if (this.source == null)
- {
- result = false;
- }
- else
- {
- if (this.source.isOutOfBounds(this.nextPosition))
- {
- result = false;
- }
- else
- {
- result = true;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- */
- @Override
- public Character next()
- {
- Character result;
-
- if (this.source == null)
- {
- result = null;
- }
- else
- {
- if (hasNext())
- {
- result = this.source.charAt(this.nextPosition);
-
- this.nextPosition.next();
-
- if (this.source.isOutOfLine(this.nextPosition))
- {
- this.nextPosition.nextEndOfLine();
-
- while ((!this.source.isOutOfList(this.nextPosition)) && (this.source.get(this.nextPosition.getStringIndex()) == null))
- {
- this.nextPosition.nextEndOfLine();
- }
- }
- }
- else
- {
- result = null;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public StringListCharPosition nextPosition()
- {
- StringListCharPosition result;
-
- result = new StringListCharPosition(this.nextPosition);
-
- //
- return result;
- }
-
- /**
- * Do nothing.
- */
- @Override
- public void remove()
- {
- // TODO or not TODO?
- }
-}
diff --git a/src/fr/devinsy/util/strings/StringListCharPosition.java b/src/fr/devinsy/util/strings/StringListCharPosition.java
deleted file mode 100644
index 5940e53..0000000
--- a/src/fr/devinsy/util/strings/StringListCharPosition.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Copyright (C) 2013-2015 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-/**
- * This class manages a char position in a StringList object.
- *
- * @author Christian P. Momon
- */
-public class StringListCharPosition
-{
- private int charIndex;
- private int stringIndex;
- private int localCharIndex;
-
- /**
- *
- * @param index
- * @param stringIndex
- * @param localIndex
- */
- public StringListCharPosition()
- {
- this.charIndex = 0;
- this.stringIndex = 0;
- this.localCharIndex = 0;
- }
-
- /**
- *
- * @param index
- * @param stringIndex
- * @param localIndex
- */
- public StringListCharPosition(final int index, final int stringIndex, final int localIndex)
- {
- this.charIndex = index;
- this.stringIndex = stringIndex;
- this.localCharIndex = localIndex;
- }
-
- /**
- *
- * @param source
- */
- public StringListCharPosition(final StringListCharPosition source)
- {
- this.charIndex = source.getCharIndex();
- this.stringIndex = source.getStringIndex();
- this.localCharIndex = source.getLocalCharIndex();
- }
-
- public int getCharIndex()
- {
- return this.charIndex;
- }
-
- public int getLocalCharIndex()
- {
- return this.localCharIndex;
- }
-
- public int getStringIndex()
- {
- return this.stringIndex;
- }
-
- public void next()
- {
- this.charIndex += 1;
- this.localCharIndex += 1;
- }
-
- public void nextEndOfLine()
- {
- this.localCharIndex = 0;
- this.stringIndex += 1;
- }
-
- public void setCharIndex(final int charIndex)
- {
- this.charIndex = charIndex;
- }
-
- public void setLocalCharIndex(final int localCharIndex)
- {
- this.localCharIndex = localCharIndex;
- }
-
- public void setStringIndex(final int stringIndex)
- {
- this.stringIndex = stringIndex;
- }
-
-}
diff --git a/src/fr/devinsy/util/strings/StringListInputStream.java b/src/fr/devinsy/util/strings/StringListInputStream.java
deleted file mode 100644
index 95ab552..0000000
--- a/src/fr/devinsy/util/strings/StringListInputStream.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * Copyright (C) 2013-2015 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * TODO CREATION STEP.
- */
-public class StringListInputStream extends InputStream
-{
- private StringList in;
-
- /**
- *
- */
- public StringListInputStream()
- {
- this.in = new StringList();
- }
-
- /**
- *
- */
- public StringListInputStream(final int size)
- {
- this.in = new StringList(size);
- }
-
- /**
- *
- */
- public StringListInputStream(final StringList source)
- {
- if (source == null)
- {
- throw new NullPointerException("source is null.");
- }
- else
- {
- this.in = source;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int available() throws IOException
- {
- return 0;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void close() throws IOException
- {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public synchronized void mark(final int readlimit)
- {
- // TODO
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean markSupported()
- {
- boolean result;
-
- result = true;
-
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int read() throws IOException
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public synchronized void reset() throws IOException
- {
- // TODO
- throw new IOException("mark/reset not supported");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public long skip(final long n) throws IOException
- {
- // TODO
- return 0;
- }
-}
diff --git a/src/fr/devinsy/util/strings/StringListReader.java b/src/fr/devinsy/util/strings/StringListReader.java
deleted file mode 100644
index 465739a..0000000
--- a/src/fr/devinsy/util/strings/StringListReader.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Copyright (C) 2013-2017 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Reader;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class StringListReader extends Reader
-{
- private StringList in;
- private StringListCharIterator iterator;
-
- /**
- *
- * @param in
- */
- public StringListReader(final StringList in)
- {
- this.in = in;
- this.iterator = new StringListCharIterator(in);
- }
-
- /**
- *
- */
- @Override
- public void close()
- {
- }
-
- /**
- *
- */
- @Override
- public synchronized int read(final char[] cbuf, final int off, final int len) throws IOException
- {
- int result;
-
- BufferedReader a;
-
- if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0))
- {
- throw new IndexOutOfBoundsException();
- }
- else if (len == 0)
- {
- result = 0;
- }
- else if (this.iterator.hasNext())
- {
- //
- result = 0;
-
- // Read off characters.
- {
- boolean ended = false;
- int offCount = 0;
- while (!ended)
- {
- if ((offCount < off) && (this.iterator.hasNext()))
- {
- this.iterator.next();
- offCount += 1;
- result += 1;
- }
- else
- {
- ended = true;
- }
- }
- }
-
- // Read len characters.
- {
- boolean ended = false;
- int lenCount = 0;
- while (!ended)
- {
- if ((lenCount < len) && (this.iterator.hasNext()))
- {
- char letter = this.iterator.next();
- cbuf[lenCount] = letter;
- lenCount += 1;
- result += 1;
- }
- else
- {
- ended = true;
- }
- }
- }
- }
- else
- {
- result = -1;
- }
-
- //
- return result;
- }
-}
diff --git a/src/fr/devinsy/util/strings/StringListUtils.java b/src/fr/devinsy/util/strings/StringListUtils.java
deleted file mode 100644
index 9ad0a7a..0000000
--- a/src/fr/devinsy/util/strings/StringListUtils.java
+++ /dev/null
@@ -1,1038 +0,0 @@
-/**
- * Copyright (C) 2008-2010, 2013-2016 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.util.Collection;
-
-/**
- * The {@code StringUtils} class defines helper methods to string collection.
- *
- * Operations that are null safe.
- *
- */
-public class StringListUtils
-{
- public static final String DEFAULT_CHARSET_NAME = "UTF-8";
-
- /**
- *
- */
- private StringListUtils()
- {
- }
-
- /**
- * Builds a string concatenating many times a source string.
- *
- * @param source
- * The string to concatenate several time.
- *
- * @param multiplier
- * The number of concatenate to produce.
- * @return
- */
- public static String concatenate(final String source, final int multiplier)
- {
- String result;
-
- result = repeat(source, multiplier).toString();
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static boolean containsBlank(final Collection source)
- {
- boolean result;
-
- if (source == null)
- {
- result = false;
- }
- else if (source instanceof StringList)
- {
- result = ((StringList) source).containsBlank();
- }
- else
- {
- result = new StringList(source).containsBlank();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static boolean containsBlank(final String... source)
- {
- boolean result;
-
- if (source == null)
- {
- result = false;
- }
- else
- {
- result = new StringList(source).containsBlank();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static boolean containsEmpty(final Collection source)
- {
- boolean result;
-
- if (source == null)
- {
- result = false;
- }
- else if (source instanceof StringList)
- {
- result = ((StringList) source).containsEmpty();
- }
- else
- {
- result = new StringList(source).containsEmpty();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static boolean containsEmpty(final String... source)
- {
- boolean result;
-
- if (source == null)
- {
- result = false;
- }
- else
- {
- result = new StringList(source).containsEmpty();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static boolean containsNull(final Collection source)
- {
- boolean result;
-
- if (source == null)
- {
- result = false;
- }
- else if (source instanceof StringList)
- {
- result = ((StringList) source).containsNull();
- }
- else
- {
- result = new StringList(source).containsNull();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static boolean containsNull(final String... source)
- {
- boolean result;
-
- if (source == null)
- {
- result = false;
- }
- else
- {
- result = new StringList(source).containsNull();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param target
- * @return
- */
- public static StringSet getComplement(final Collection alpha, final Collection bravo)
- {
- StringSet result;
-
- result = getDifference(bravo, alpha);
-
- //
- return result;
- }
-
- /**
- *
- * @param target
- * @return
- */
- public static StringSet getDifference(final Collection alpha, final Collection bravo)
- {
- StringSet result;
-
- result = new StringSet(alpha);
- result.removeAll(bravo);
-
- //
- return result;
- }
-
- /**
- *
- * @param target
- * @return
- */
- public static StringSet getDisjunction(final Collection alpha, final Collection bravo)
- {
- StringSet result;
-
- result = new StringSet();
-
- for (String string : alpha)
- {
- if (!bravo.contains(string))
- {
- result.add(string);
- }
- }
-
- for (String string : bravo)
- {
- if (!alpha.contains(string))
- {
- result.add(string);
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param target
- * @return
- */
- public static StringSet getIntersectionOf(final Collection alpha, final Collection bravo)
- {
- StringSet result;
-
- result = new StringSet();
-
- for (String string : alpha)
- {
- if (bravo.contains(string))
- {
- result.add(string);
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param target
- * @return
- */
- public static StringSet getUnionOf(final Collection alpha, final Collection bravo)
- {
- StringSet result;
-
- result = new StringSet(alpha);
-
- for (String string : bravo)
- {
- result.add(string);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param file
- * @throws IOException
- */
- public static StringList load(final File source) throws IOException
- {
- StringList result;
-
- result = load(source, DEFAULT_CHARSET_NAME);
-
- //
- return result;
- }
-
- /**
- *
- * @param file
- * @throws IOException
- */
- public static StringList load(final File file, final String charsetName) throws IOException
- {
- StringList result;
-
- //
- result = new StringList();
-
- //
- read(result, new FileInputStream(file), charsetName);
-
- //
- return result;
- }
-
- /**
- *
- * @param file
- * @return
- * @throws IOException
- */
- public static StringList load(final URL source) throws IOException
- {
- StringList result;
-
- result = load(source, DEFAULT_CHARSET_NAME);
-
- //
- return result;
- }
-
- /**
- *
- * @param file
- * @throws IOException
- */
- public static StringList load(final URL source, final String charsetName) throws IOException
- {
- StringList result;
-
- //
- result = new StringList();
-
- //
- read(result, source.openStream(), charsetName);
-
- //
- return result;
- }
-
- /**
- *
- * @param file
- * @throws IOException
- */
- public static void read(final StringList out, final InputStream is, final String charsetName) throws IOException
- {
- BufferedReader in = null;
- try
- {
- in = new BufferedReader(new InputStreamReader(is, charsetName));
-
- boolean ended = false;
-
- while (!ended)
- {
- String line = in.readLine();
-
- if (line == null)
- {
- ended = true;
- }
- else
- {
- out.append(line);
- }
- }
- }
- finally
- {
- try
- {
- if (in != null)
- {
- in.close();
- }
- }
- catch (IOException exception)
- {
- exception.printStackTrace();
- }
- }
- }
-
- /**
- * Builds a string list concatenating many times a source string.
- *
- * @param source
- * The string to concatenate several time.
- *
- * @param multiplier
- * The number of concatenate to produce.
- * @return
- */
- public static StringList repeat(final String source, final int multiplier)
- {
- StringList result;
-
- result = new StringList(multiplier);
- for (int count = 0; count < multiplier; count++)
- {
- result.append(source);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param file
- * @throws FileNotFoundException
- * @throws UnsupportedEncodingException
- */
- public static void save(final File file, final StringList source) throws UnsupportedEncodingException, FileNotFoundException
- {
- PrintWriter out = null;
- try
- {
- out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), DEFAULT_CHARSET_NAME));
-
- if (source != null)
- {
- for (String string : source)
- {
- out.println(string);
- }
- }
- }
- finally
- {
- if (out != null)
- {
- out.close();
- }
- }
- }
-
- /**
- * Sorts the string list.
- *
- * @param source
- * The string list to sort.
- */
- public static void sort(final StringList source)
- {
- if (source != null)
- {
- source.sort();
- }
- }
-
- /**
- * Concatenates the string from an array to a string.
- *
- * @param source
- * The string array to convert.
- *
- * @return A string concatenation of the argument.
- */
- public static String toString(final String[] source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toString();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param prefix
- * @param separator
- * @param postfix
- * @return
- */
- public static String toString(final String[] source, final String prefix, final String separator, final String postfix)
- {
- String result;
-
- if (source == null)
- {
- result = new StringList().toString(prefix, null, postfix);
- }
- else
- {
- result = new StringList(source).toString(prefix, separator, postfix);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param prefix
- * @param separator
- * @param postfix
- * @return
- */
- public static String toString(final StringList source, final String prefix, final String separator, final String postfix)
- {
- String result;
-
- if (source == null)
- {
- result = new StringList().toString(prefix, null, postfix);
- }
- else
- {
- result = source.toString(prefix, separator, postfix);
- }
-
- //
- return result;
- }
-
- /**
- * Converts a {@code Collection} to an array of {@code String}.
- *
- * @param source
- * The string list to convert.
- *
- * @return The result of the conversion.
- */
- public static String[] toStringArray(final Collection source)
- {
- String[] result;
-
- if (source == null)
- {
- result = new String[0];
- }
- else
- {
- result = new StringList(source).toStringArray();
- }
-
- //
- return result;
- }
-
- /**
- * Converts a {@code StringList} to an array of {@code String}.
- *
- * @param source
- * The string list to convert.
- *
- * @return The result of the conversion.
- */
- public static String[] toStringArray(final StringList source)
- {
- String[] result;
-
- if (source == null)
- {
- result = new String[0];
- }
- else
- {
- result = source.toStringArray();
- }
-
- //
- return result;
- }
-
- /**
- * Concatenates the string from an array to a string.
- *
- * @param strings
- * The string array to convert.
- *
- * @return If argument is null then returns an empty string, otherwise
- * returns a string concatenation of the argument.
- */
- public static String toStringNotNull(final String[] source)
- {
- String result;
-
- result = toString(source);
-
- if (result == null)
- {
- result = "";
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringSeparatedBy(final Collection source, final String separator)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringSeparatedBy(separator);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringSeparatedBy(final String[] source, final String separator)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringSeparatedBy(separator);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringSeparatedBy(final StringList source, final String separator)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = source.toStringSeparatedBy(separator);
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringWithBracket(final Collection source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithBracket();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringWithBracket(final String[] source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithBracket();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringWithBracket(final StringList source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = source.toStringWithBracket();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringWithBracketNotNull(final Collection source)
- {
- String result;
-
- result = toStringWithBracket(source);
-
- if (result == null)
- {
- result = "";
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringWithBracketNotNull(final String[] source)
- {
- String result;
-
- result = toStringWithBracket(source);
-
- if (result == null)
- {
- result = "";
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param strings
- * @return
- */
- public static String toStringWithBracketNotNull(final StringList source)
- {
- String result;
-
- result = toStringWithBracket(source);
-
- if (result == null)
- {
- result = "";
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithBrackets(final Collection source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithBrackets();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithBrackets(final String[] source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithBrackets();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithBrackets(final StringList source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = source.toStringWithBrackets();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithCommas(final Collection source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithCommas();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithCommas(final String[] source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithCommas();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithCommas(final StringList source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = source.toStringWithCommas();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithFrenchCommas(final Collection source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithFrenchCommas();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithFrenchCommas(final String[] source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = new StringList(source).toStringWithFrenchCommas();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toStringWithFrenchCommas(final StringList source)
- {
- String result;
-
- if (source == null)
- {
- result = null;
- }
- else
- {
- result = source.toStringWithFrenchCommas();
- }
-
- //
- return result;
- }
-}
diff --git a/src/fr/devinsy/util/strings/StringListWriter.java b/src/fr/devinsy/util/strings/StringListWriter.java
deleted file mode 100644
index b52bf3c..0000000
--- a/src/fr/devinsy/util/strings/StringListWriter.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * Copyright (C) 2013-2017 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- *
- */
-public class StringListWriter extends Writer
-{
- private StringList out;
-
- /**
- *
- */
- public StringListWriter()
- {
- this.out = new StringList();
- }
-
- /**
- *
- */
- public StringListWriter(final int initialCapacity)
- {
- this.out = new StringList(initialCapacity);
- }
-
- /**
- *
- */
- public StringListWriter(final StringList target)
- {
- if (target == null)
- {
- throw new NullPointerException("target is null.");
- }
- else
- {
- this.out = target;
- }
- }
-
- /*
- *
- */
- @Override
- public void close() throws IOException
- {
-
- }
-
- /*
- *
- */
- @Override
- public void flush() throws IOException
- {
-
- }
-
- /*
- *
- */
- @Override
- public String toString()
- {
- String result;
-
- result = this.out.toString();
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public StringList toStringList()
- {
- StringList result;
-
- result = this.out;
-
- //
- return result;
- }
-
- /*
- *
- */
- 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
- {
- char[] target;
- if ((off == 0) && (cbuf.length == len))
- {
- target = cbuf;
- }
- else
- {
- target = new char[len];
- for (int index = off; index < len; index++)
- {
- target[index] = cbuf[index];
- }
- }
-
- //
- this.out.append(new String(target));
- }
-
- /*
- *
- */
- @Override
- public void write(final String string) throws IOException
- {
- this.out.append(string);
- }
-}
diff --git a/src/fr/devinsy/util/strings/StringSet.java b/src/fr/devinsy/util/strings/StringSet.java
deleted file mode 100644
index f69a951..0000000
--- a/src/fr/devinsy/util/strings/StringSet.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/**
- * Copyright (C) 2014-2016 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-/**
- * This class is a set of String objects with specific methods. It makes
- * possible to build a string without any copy. The goal is to make easier the
- * use of set of strings.
- */
-public class StringSet extends HashSet
-{
- private static final long serialVersionUID = 6674838743930005326L;
-
- /**
- *
- */
- public StringSet()
- {
- super();
- }
-
- /**
- * Constructs a list of string of the specified collection, in the order
- * they are returned by the collection's iterator.
- *
- * @param source
- */
- public StringSet(final Collection source)
- {
- super(source.size());
-
- if (source != null)
- {
- //
- for (String string : source)
- {
- this.add(string);
- }
- }
- }
-
- /**
- *
- */
- public StringSet(final int initialCapacity)
- {
- super(initialCapacity);
- }
-
- /**
- *
- */
- public StringSet(final String[] source)
- {
- super();
-
- if (source != null)
- {
- //
- for (String string : source)
- {
- this.add(string);
- }
- }
- }
-
- /**
- *
- */
- public StringSet(final StringSet source)
- {
- super();
-
- if (source != null)
- {
- //
- for (String string : source)
- {
- this.add(string);
- }
- }
- }
-
- /**
- * Check null parameter before add.
- */
- @Override
- public boolean add(final String string)
- {
- boolean result;
-
- if (string != null)
- {
- //
- result = super.add(string);
- }
- else
- {
- //
- result = false;
- }
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet add(final StringSet strings)
- {
- StringSet result;
-
- if (strings != null)
- {
- for (String string : strings)
- {
- this.add(string);
- }
- }
-
- result = this;
-
- //
- return result;
- }
-
- /**
- * Deep copy and shallow copy have no sense about a list of immutable
- * objects.
- *
- * @return
- */
- @Override
- public StringSet clone()
- {
- StringSet result;
-
- result = new StringSet(size());
-
- for (String string : this)
- {
- result.add(string);
- }
-
- //
- return result;
- }
-
- /**
- *
- */
- public int length()
- {
- int result = 0;
-
- for (String string : this)
- {
- result += string.length();
- }
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet merge()
- {
- StringSet result;
-
- StringBuffer buffer = new StringBuffer(length());
-
- for (String string : this)
- {
- buffer.append(string);
- }
-
- String merge = buffer.toString();
-
- clear();
- add(merge);
-
- //
- result = this;
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final char character)
- {
- StringSet result;
-
- this.add(String.valueOf(character));
-
- result = this;
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final double value)
- {
- StringSet result;
-
- result = this.put(String.valueOf(value));
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final int value)
- {
- StringSet result;
-
- result = this.put(String.valueOf(value));
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final long value)
- {
- StringSet result;
-
- result = this.put(String.valueOf(value));
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final Object value)
- {
- StringSet result;
-
- if (value != null)
- {
- this.put(value.toString());
- }
-
- result = this;
-
- //
- return result;
- }
-
- /**
- * Check null parameter before add.
- */
- public StringSet put(final String string)
- {
- StringSet result;
-
- if (string != null)
- {
- this.add(string);
- }
-
- result = this;
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final String... strings)
- {
- StringSet result;
-
- if (strings != null)
- {
- for (String string : strings)
- {
- this.put(string);
- }
- }
-
- result = this;
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final StringList strings)
- {
- StringSet result;
-
- if (strings != null)
- {
- for (String string : strings)
- {
- this.put(string);
- }
- }
-
- result = this;
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet put(final StringSet strings)
- {
- StringSet result;
-
- if (strings != null)
- {
- for (String string : strings)
- {
- this.put(string);
- }
- }
-
- result = this;
-
- //
- return result;
- }
-
- /**
- *
- */
- public StringSet putNullable(final Object value)
- {
- StringSet result;
-
- if (value == null)
- {
- super.add((String) null);
- }
- else
- {
- this.put(value.toString());
- }
-
- result = this;
-
- //
- return result;
- }
-
- /**
- *
- */
- @Override
- public String toString()
- {
- String result;
-
- result = toStringList().toStringWithCommas();
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public StringList toStringList()
- {
- StringList result;
-
- result = new StringList(this);
-
- //
- return result;
- }
-}
diff --git a/src/fr/devinsy/util/unix/CachedFile.java b/src/fr/devinsy/util/unix/CachedFile.java
deleted file mode 100644
index ce1881f..0000000
--- a/src/fr/devinsy/util/unix/CachedFile.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-import java.io.File;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class CachedFile
-{
- public enum Status
- {
- NOT_LOAD, EXPIRED, UPDATED
- }
-
- private static 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;
- }
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
diff --git a/src/fr/devinsy/util/unix/EtcGroupFile.java b/src/fr/devinsy/util/unix/EtcGroupFile.java
deleted file mode 100644
index ad1ccb5..0000000
--- a/src/fr/devinsy/util/unix/EtcGroupFile.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-import java.util.Vector;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class EtcGroupFile extends CachedFile
-{
- // static private final Logger logger =
- // LoggerFactory.getLogger(EtcGroupFile.class);
-
- private 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 getLoginGroups(final String login)
- {
- Vector result;
-
- Groups groups = updatedGroups();
-
- result = groups.getLoginGroups(login);
-
- //
- return (result);
- }
-
- /**
- *
- */
- public String getLoginGroupsString(final String login)
- {
- String result;
-
- this.groups = updatedGroups();
-
- result = this.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);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/EtcGroupFileReader.java b/src/fr/devinsy/util/unix/EtcGroupFileReader.java
deleted file mode 100644
index 35ab71f..0000000
--- a/src/fr/devinsy/util/unix/EtcGroupFileReader.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-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;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class EtcGroupFileReader
-{
- private static final Logger logger = LoggerFactory.getLogger(EtcGroupFileReader.class);
-
- /**
- *
- */
- public static 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);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/EtcPasswdFile.java b/src/fr/devinsy/util/unix/EtcPasswdFile.java
deleted file mode 100644
index 2816e37..0000000
--- a/src/fr/devinsy/util/unix/EtcPasswdFile.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class EtcPasswdFile extends CachedFile
-{
- private static final Logger logger = LoggerFactory.getLogger(EtcPasswdFile.class);
-
- private 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);
- }
-
- /**
- *
- */
- public static EtcPasswdFile instance()
- {
- EtcPasswdFile result;
-
- if (EtcPasswdFile.instance == null)
- {
- EtcPasswdFile.instance = new EtcPasswdFile();
- }
-
- result = EtcPasswdFile.instance;
-
- //
- return (result);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/EtcPasswdFileReader.java b/src/fr/devinsy/util/unix/EtcPasswdFileReader.java
deleted file mode 100644
index 1467391..0000000
--- a/src/fr/devinsy/util/unix/EtcPasswdFileReader.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-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;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class EtcPasswdFileReader
-{
- private static final Logger logger = LoggerFactory.getLogger(EtcPasswdFileReader.class);
-
- /**
- *
- */
- public static 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);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/Group.java b/src/fr/devinsy/util/unix/Group.java
deleted file mode 100644
index 04eb687..0000000
--- a/src/fr/devinsy/util/unix/Group.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-import java.util.Vector;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-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 members;
-
- /**
- *
- */
- public Group()
- {
- this.name = null;
- this.password = null;
- this.gid = -1;
- this.members = new Vector();
- }
-
- /**
- *
- */
- 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 getMembers()
- {
- Vector 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 members()
- {
- Vector 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);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/Groups.java b/src/fr/devinsy/util/unix/Groups.java
deleted file mode 100644
index 34e0e4d..0000000
--- a/src/fr/devinsy/util/unix/Groups.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class Groups extends Vector
-{
-
- 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 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 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 getLoginGroups(final String login)
- {
- Vector result;
-
- result = new Vector();
- Iterator 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 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 iterator = this.iterator();
-
- while (iterator.hasNext())
- {
- out.append(iterator.next().toString() + "\n");
- }
-
- result = out.toString();
-
- //
- return (result);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/Unix.java b/src/fr/devinsy/util/unix/Unix.java
deleted file mode 100644
index 5de7972..0000000
--- a/src/fr/devinsy/util/unix/Unix.java
+++ /dev/null
@@ -1,597 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2015 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-import java.io.File;
-import java.util.Vector;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import fr.devinsy.util.cmdexec.CmdExec;
-import fr.devinsy.util.strings.StringListUtils;
-import fr.devinsy.util.unix.acl.Acl;
-import fr.devinsy.util.unix.acl.AclManager;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class Unix
-{
- private static final Logger logger = LoggerFactory.getLogger(Unix.class);
- public static final String SUDO = "/usr/bin/sudo";
-
- /**
- *
- */
- public static void appendToFile(final String text, final String path) throws Exception
- {
- if ((text == null) || (text.length() == 0) || (path == null) || (path.length() == 0))
- {
- throw new Exception("Parameter undefined: [" + text + "][" + path + "].");
- }
- else
- {
- try
- {
- CmdExec.run(SUDO, "bash", "-c", "echo \"" + text + "\" >> " + path);
- }
- catch (Exception exception)
- {
- throw new Exception("Error detected appending text to file [" + path + "].", exception);
- }
- }
- }
-
- /**
- *
- */
- public static void chmod(final String changes, final String path) throws Exception
- {
- if ((changes == null) || (changes.length() == 0) || (path == null) || (path.length() == 0))
- {
- throw new Exception("Parameter undefined: [" + changes + "][" + path + "].");
- }
- else if (!new File(path).exists())
- {
- throw new Exception("Path not found: [" + path + "].");
- }
- else
- {
- try
- {
- CmdExec.run(SUDO, "chmod", changes, path);
- }
- catch (Exception exception)
- {
- throw new Exception("Error running chmod command for [" + changes + "][" + path + "].", exception);
- }
- }
- }
-
- /**
- *
- */
- public static void clearAcl(final String id, final String filePathName) throws Exception
- {
- AclManager.clearId(id, filePathName);
- }
-
- /**
- *
- */
- public static void clearAclGroup(final String group, final String filePathName) throws Exception
- {
- AclManager.clearGroup(group, filePathName);
- }
-
- /**
- *
- */
- public static void clearAclUser(final String login, final String filePathName) throws Exception
- {
- AclManager.clearUser(login, filePathName);
- }
-
- /**
- *
- */
- public static void createUserAccount(final String login) throws Exception
- {
- if ((login == null) || (login.length() == 0))
- {
- throw new Exception("Login parameter undefined.");
- }
- else
- {
- createUserAccount(login, login);
- }
- }
-
- /**
- *
- */
- public static void createUserAccount(final String login, final String name) throws Exception
- {
- if ((login == null) || (login.length() == 0))
- {
- throw new Exception("Login parameter undefined.");
- }
- else if ((name == null) || (name.length() == 0))
- {
- throw new Exception("Name parameter undefined.");
- }
- else
- {
- createUserAccount(login, name, "/home/" + login);
- }
- }
-
- /**
- *
- */
- public static void createUserAccount(final String login, final String name, final String home) throws Exception
- {
- if ((login == null) || (login.length() == 0))
- {
- throw new Exception("Login parameter undefined.");
- }
- else if ((name == null) || (name.length() == 0))
- {
- throw new Exception("Name parameter undefined.");
- }
- else if ((home == null) || (home.length() == 0))
- {
- throw new Exception("Home parameter undefined.");
- }
- else
- {
- try
- {
- logger.info("Creating user account for [" + login + "].");
- CmdExec.run(SUDO, "/usr/sbin/useradd", "-m", "-c", name, "-d", home, login);
- EtcPasswdFile.instance().update();
- logger.info("User account created for [" + login + "].");
- }
- catch (Exception exception)
- {
- throw new Exception("Error detected creating user account [" + login + "].", exception);
- }
- }
- }
-
- /**
- *
- */
- public static void createUserAccount(final String login, final String name, final String home, final String password) throws Exception
- {
- if ((password == null) || (password.length() == 0))
- {
- throw new Exception("Password parameter undefined.");
- }
- else if (Unix.isLogin(login))
- {
- throw new Exception("Login [" + login + "] already in use");
- }
- else
- {
- createUserAccount(login, name, home);
- setPassword(login, password);
- }
- }
-
- /**
- *
- */
- public static void deleteGroup(final String group) throws Exception
- {
- if ((group == null) || (group.length() == 0))
- {
- throw new Exception("Group parameter undefined.");
- }
- else
- {
- try
- {
- logger.info("Deleting group for [" + group + "].");
- CmdExec.run(SUDO + " groupdel " + group);
- logger.info("Group deleted for [" + group + "].");
- }
- catch (Exception exception)
- {
- throw new Exception("Error running groupdel command for group [" + group + "].", exception);
- }
- }
- }
-
- /**
- *
- */
- public static void deleteUserAccount(final String login) throws Exception
- {
- if ((login == null) || (login.length() == 0))
- {
- throw new Exception("Login parameter undefined.");
- }
- else
- {
- try
- {
- logger.info("Deleting user account for [" + login + "].");
- CmdExec.run(SUDO + " /usr/sbin/userdel " + login);
- logger.info("User account delted for [" + login + "].");
- }
- catch (Exception exception)
- {
- throw new Exception("Error running userdel command for login [" + login + "].", exception);
- }
- }
- }
-
- /**
- *
- */
- public static String getAclData(final String filePathName) throws Exception
- {
- String result;
-
- result = AclManager.getAclData(filePathName);
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static String[] getAclUsers(final String filePathName) throws Exception
- {
- String[] result;
-
- Acl acl = AclManager.getAcl(filePathName);
-
- result = acl.currentAcl().getUserIds();
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static boolean isGroup(final String groupName)
- {
- boolean result;
-
- result = EtcGroupFile.instance().contains(groupName);
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static boolean isLogin(final String login)
- {
- boolean result;
-
- result = EtcPasswdFile.instance().contains(login);
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static void link(final String sourcePath, final String targetPath) throws Exception
- {
- logger.info("[" + sourcePath + "][" + targetPath + "]");
- if ((sourcePath == null) || (sourcePath.length() == 0) || (targetPath == null) || (targetPath.length() == 0))
- {
- throw new Exception("Parameter undefined: [" + sourcePath + "][" + targetPath + "].");
- }
- else
- {
- File sourceFile = new File(sourcePath);
- File targetFile = new File(targetPath);
-
- if (!sourceFile.exists())
- {
- throw new Exception("Source does not exist: [" + sourcePath + "].");
- }
- else if ((targetFile.exists()) && (!targetFile.isDirectory()))
- {
- throw new Exception("Target already exists: [" + targetPath + "].");
- }
- else
- {
- try
- {
- CmdExec.run(SUDO, "ln", "-s", sourcePath, targetPath);
- }
- catch (Exception exception)
- {
- throw new Exception("Error detected linking [" + sourcePath + "][" + targetPath + "].", exception);
- }
- }
- }
- }
-
- /**
- *
- */
- public static void modifyLogin(final String sourceLogin, final String targetLogin, final String sourceHomeDirectory) throws Exception
- {
- logger.info("Starting login modifying: [" + sourceLogin + "] -> [" + targetLogin + "]");
- if ((sourceLogin == null) || (sourceLogin.length() == 0))
- {
- throw new Exception("Original login parameters undefined");
- }
- else if ((targetLogin == null) || (targetLogin.length() == 0))
- {
- throw new Exception("New login parameters undefined");
- }
- else if (!Unix.isLogin(sourceLogin))
- {
- throw new Exception("Original login unknow: [" + sourceLogin + "].");
- }
- else if (Unix.isLogin(targetLogin))
- {
- throw new Exception("New login unknow: [" + targetLogin + "].");
- }
- else if (sourceHomeDirectory == null)
- {
- throw new Exception("sourceHomeDirectory parameter undefined, thus no home directory move.");
- }
- else if (!new File(sourceHomeDirectory).exists())
- {
- throw new Exception("Source home directory does not exist: [" + sourceHomeDirectory + "].");
- }
- else
- {
- String targetHomeDirectory = new File(sourceHomeDirectory).getParent().toString() + "/" + targetLogin;
- if (new File(targetHomeDirectory).exists())
- {
- throw new Exception("Target home directory already exists: [" + targetHomeDirectory + "].");
- }
- else
- {
- try
- {
- logger.info("Login modifying: [" + sourceLogin + "] -> [" + targetLogin + "]");
- CmdExec.run(SUDO + " usermod -l " + targetLogin + " " + sourceLogin);
- logger.info("Login modified: [" + sourceLogin + "] -> [" + targetLogin + "]");
- }
- catch (Exception exception)
- {
- throw new Exception("Login modification failed for [" + sourceLogin + "].", exception);
- }
-
- try
- {
- logger.info("Renaming home directory: [" + sourceHomeDirectory + "] -> [" + targetLogin + "]");
- CmdExec.run(SUDO + " mv " + sourceHomeDirectory + " " + targetHomeDirectory);
- logger.info("Home directory renamed: [" + sourceHomeDirectory + "] -> [" + targetLogin + "]");
- }
- catch (Exception exception)
- {
- throw new Exception("Home directory rename failed for [" + sourceHomeDirectory + "].", exception);
- }
- }
- }
- logger.info("Login modifying done: [" + sourceLogin + "] -> [" + targetLogin + "]");
- }
-
- /**
- *
- */
- public static void recursiveChmod(final String changes, final String path) throws Exception
- {
- if ((changes == null) || (changes.length() == 0) || (path == null) || (path.length() == 0))
- {
- throw new Exception("Parameter undefined: [" + changes + "][" + path + "].");
- }
- else if (!new File(path).exists())
- {
- throw new Exception("Path not found: [" + path + "].");
- }
- else
- {
- try
- {
- CmdExec.run(SUDO, "chmod", "-R", changes, path);
- }
- catch (Exception exception)
- {
- throw new Exception("Error running recursive chmod command for [" + changes + "][" + path + "].", exception);
- }
- }
- }
-
- /**
- *
- */
- public static void renameGroup(final String sourceGroup, final String targetGroup) throws Exception
- {
- logger.info("Starting group renaming: [" + sourceGroup + "] -> [" + targetGroup + "]");
- if ((sourceGroup == null) || (sourceGroup.length() == 0))
- {
- throw new Exception("Original group name parameters undefined");
- }
- else if ((targetGroup == null) || (targetGroup.length() == 0))
- {
- throw new Exception("New group name parameters undefined");
- }
- else if (!Unix.isGroup(sourceGroup))
- {
- throw new Exception("Original group unknow: [" + sourceGroup + "].");
- }
- else if (Unix.isGroup(targetGroup))
- {
- throw new Exception("New group unknow: [" + targetGroup + "].");
- }
- else
- {
- try
- {
- logger.info("Login modifying: [" + sourceGroup + "] -> [" + targetGroup + "]");
- CmdExec.run(SUDO + " groupmod -n " + targetGroup + " " + sourceGroup);
- logger.info("Login modified: [" + sourceGroup + "] -> [" + targetGroup + "]");
- }
- catch (Exception exception)
- {
- throw new Exception("Group renaming failed for [" + sourceGroup + "].", exception);
- }
- }
- logger.info("Group renaming done: [" + sourceGroup + "] -> [" + targetGroup + "]");
- }
-
- /**
- *
- */
- public static Group searchGroup(final String groupName)
- {
- Group result;
-
- result = EtcGroupFile.instance().get(groupName);
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static User searchLogin(final String login)
- {
- User result;
-
- result = EtcPasswdFile.instance().get(login);
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static Vector searchLoginGroups(final String login)
- {
- Vector result;
-
- result = EtcGroupFile.instance().getLoginGroups(login);
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static void setfacl(final String... args) throws Exception
- {
- try
- {
- CmdExec.run(SUDO, "setfacl", args, 1, 6);
- }
- catch (Exception exception)
- {
- throw new Exception("Error running setfacl command for " + StringListUtils.toStringWithBrackets(args) + ":" + exception.getMessage() + ".", exception);
- }
- }
-
- /**
- * As 'passwd' command has not the option '--stdin' in all systems (eg.
- * Debian), this method uses the 'chpasswd' command.
- */
- public static void setPassword(final String login, final String newPassword) throws Exception
- {
- if ((login == null) || (login.length() == 0))
- {
- throw new Exception("Login parameter undefined.");
- }
- else if (newPassword == null)
- {
- throw new Exception("New password parameter undefined.");
- }
- else
- {
- try
- {
- logger.info("Password setting for [" + login + "].");
- CmdExec.run(SUDO, "bash", "-c", "echo \"" + login + ":" + newPassword + "\"| chpasswd ");
- logger.info("Password set for [" + login + "].");
- }
- catch (Exception exception)
- {
- throw new Exception("Error detected on setting of the new password for [" + login + "].", exception);
- }
- }
- }
-
- /**
- * chfn [ -f full-name ] [ username ]
- */
- public static void setRealName(final String login, final String newRealName) throws Exception
- {
- if ((login == null) || (login.length() == 0))
- {
- throw new Exception("Login parameter undefined.");
- }
- else if (newRealName == null)
- {
- throw new Exception("New real name parameter undefined.");
- }
- else
- {
- try
- {
- logger.info("Real name changing for user [" + login + "].");
- CmdExec.run(SUDO, "chfn", "-f", newRealName, login);
- EtcPasswdFile.instance().update();
- logger.info("Real name changed for user [" + login + "].");
- }
- catch (Exception exception)
- {
- throw new Exception("Error detected on setting of the new real name for [" + login + "].", exception);
- }
- }
- }
-
- /**
- *
- */
- public static void unlink(final String filePathName) throws Exception
- {
- logger.info("[" + filePathName + "]");
- if (filePathName == null)
- {
- throw new Exception("Parameter undefined: [" + filePathName + "].");
- }
- else
- {
- new File(filePathName).delete();
- }
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/User.java b/src/fr/devinsy/util/unix/User.java
deleted file mode 100644
index 8942577..0000000
--- a/src/fr/devinsy/util/unix/User.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class User
-{
- // private static 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);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/Users.java b/src/fr/devinsy/util/unix/Users.java
deleted file mode 100644
index f33160c..0000000
--- a/src/fr/devinsy/util/unix/Users.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/**
- * Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class Users extends Vector
-{
- private static final long serialVersionUID = -7178304512851592399L;
-
- // private static 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 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 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 iterator = this.iterator();
-
- while (iterator.hasNext())
- {
- out.append(iterator.next().toString() + "\n");
- }
-
- result = out.toString();
-
- //
- return (result);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/acl/Acl.java b/src/fr/devinsy/util/unix/acl/Acl.java
deleted file mode 100644
index 1f2f37c..0000000
--- a/src/fr/devinsy/util/unix/acl/Acl.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix.acl;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class Acl
-{
- // private static 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;
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/acl/AclEntries.java b/src/fr/devinsy/util/unix/acl/AclEntries.java
deleted file mode 100644
index 580ab6f..0000000
--- a/src/fr/devinsy/util/unix/acl/AclEntries.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix.acl;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class AclEntries extends Vector
-{
- private static final long serialVersionUID = 5802487312198869603L;
-
- // private static 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 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 ids = new Vector();
-
- 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 ids = new Vector();
-
- 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 ids = new Vector();
-
- 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 iterator = this.iterator();
-
- while (iterator.hasNext())
- {
- out.append(iterator.next().toString() + "\n");
- }
-
- result = out.toString();
-
- //
- return (result);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/acl/AclEntry.java b/src/fr/devinsy/util/unix/acl/AclEntry.java
deleted file mode 100644
index 09e1eb3..0000000
--- a/src/fr/devinsy/util/unix/acl/AclEntry.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.unix.acl;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class AclEntry
-{
- // private static 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 = this.permission;
-
- //
- return (result);
- }
-
- /**
- *
- */
- public Type type()
- {
- Type result;
-
- result = this.type;
-
- //
- return (result);
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/unix/acl/AclManager.java b/src/fr/devinsy/util/unix/acl/AclManager.java
deleted file mode 100644
index 7484141..0000000
--- a/src/fr/devinsy/util/unix/acl/AclManager.java
+++ /dev/null
@@ -1,424 +0,0 @@
-/**
- * Copyright (C) 2010, 2013-2015 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-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.cmdexec.CmdExec;
-import fr.devinsy.util.strings.StringListUtils;
-import fr.devinsy.util.unix.Unix;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class AclManager
-{
- private static final Logger logger = LoggerFactory.getLogger(AclManager.class);
- public static final String SUDO = "/usr/bin/sudo";
-
- final static public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$");
- final static public Pattern GROUP_PATTERN = Pattern.compile("^group:(.*):(.*)$");
- final static public Pattern MASK_PATTERN = Pattern.compile("^mask:(.*):(.*)$");
- final static public Pattern OTHER_PATTERN = Pattern.compile("^other:(.*):(.*)$");
- final static public Pattern DEFAULT_USER_PATTERN = Pattern.compile("^default:user:(.*):(.*)$");
- final static public Pattern DEFAULT_GROUP_PATTERN = Pattern.compile("^default:group:(.*):(.*)$");
- final static public Pattern DEFAULT_MASK_PATTERN = Pattern.compile("^default:mask:(.*):(.*)$");
- final static 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);
- }
- }
-
- /**
- *
- */
- public static 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);
- }
-
- /**
- *
- */
- public static 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);
- }
-
- /**
- *
- */
- public static 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);
- }
-
- /**
- *
- */
- public static 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 " + StringListUtils.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
- }
- }
-}
-
-// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/src/fr/devinsy/util/xml/XMLAttributes.java b/src/fr/devinsy/util/xml/XMLAttributes.java
deleted file mode 100644
index 640185f..0000000
--- a/src/fr/devinsy/util/xml/XMLAttributes.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.stream.events.Attribute;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLAttributes extends HashMap implements Iterable
-{
-
- private static final long serialVersionUID = 8456469741805779474L;
-
- /**
- *
- */
- public XMLAttributes()
- {
- super();
- }
-
- /**
- *
- */
- public XMLAttributes(final int capacity)
- {
- super(capacity);
- }
-
- /**
- *
- */
- public XMLAttributes(final Iterator source)
- {
- super();
- if (source != null)
- {
- while (source.hasNext())
- {
- Attribute attribute = source.next();
-
- add(attribute);
- }
- }
- }
-
- /**
- *
- */
- public XMLAttributes(final XMLAttributes source)
- {
- super();
- addAll(source);
- }
-
- /**
- *
- * @param attribute
- */
- public void add(final Attribute attribute)
- {
- if (attribute != null)
- {
- put(attribute.getName().getLocalPart(), attribute);
- }
- }
-
- /**
- *
- * @param source
- */
- public void addAll(final XMLAttributes source)
- {
- for (Attribute attribute : source)
- {
- this.add(attribute);
- }
- }
-
- /**
- *
- * @param label
- * @return
- */
- public Attribute getByLabel(final String label)
- {
- Attribute result;
-
- result = get(label);
-
- //
- return result;
- }
-
- /**
- *
- */
- @Override
- public Iterator iterator()
- {
- Iterator result;
-
- result = this.values().iterator();
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public Set labels()
- {
- Set result;
-
- result = this.keySet();
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public List toList()
- {
- List result;
-
- result = new ArrayList(values());
-
- //
- return result;
- }
-}
diff --git a/src/fr/devinsy/util/xml/XMLBadFormatException.java b/src/fr/devinsy/util/xml/XMLBadFormatException.java
deleted file mode 100644
index 268c1f0..0000000
--- a/src/fr/devinsy/util/xml/XMLBadFormatException.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import org.slf4j.helpers.MessageFormatter;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLBadFormatException extends Exception
-{
-
- private static final long serialVersionUID = 768256303984176512L;
-
- /**
- *
- * @param code
- * @param message
- */
- public XMLBadFormatException(final String message)
- {
- super(message);
- }
-
- /**
- *
- * @param code
- * @param message
- * @param exception
- */
- public XMLBadFormatException(final String message, final Exception exception)
- {
- super(message, exception);
- }
-
- /**
- *
- * @param format
- * @param arguments
- */
- public XMLBadFormatException(final String format, final Object... arguments)
- {
- this(MessageFormatter.arrayFormat(format, arguments).getMessage());
- }
-
- /**
- *
- * @param message
- * @param cause
- */
- public XMLBadFormatException(final String message, final Throwable cause)
- {
- super(message, cause);
- }
-
- /**
- *
- * @param cause
- */
- public XMLBadFormatException(final Throwable cause)
- {
- super(cause);
- }
-}
diff --git a/src/fr/devinsy/util/xml/XMLReader.java b/src/fr/devinsy/util/xml/XMLReader.java
deleted file mode 100644
index 57dd535..0000000
--- a/src/fr/devinsy/util/xml/XMLReader.java
+++ /dev/null
@@ -1,617 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- * Copyright (C) 2017 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.InputStream;
-import java.io.Reader;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.events.XMLEvent;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import fr.devinsy.util.strings.StringList;
-import fr.devinsy.util.xml.XMLTag.TagType;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLReader
-{
- private static final Logger logger = LoggerFactory.getLogger(XMLReader.class);
-
- protected XMLEventReader in;
- private XMLEvent nextEvent;
-
- /**
- *
- */
- protected XMLReader()
- {
- this.in = null;
- this.nextEvent = null;
- }
-
- /**
- *
- * @param file
- * @throws XMLStreamException
- * @throws FileNotFoundException
- */
- public XMLReader(final File file) throws FileNotFoundException, XMLStreamException
- {
- this.nextEvent = null;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- this.in = factory.createXMLEventReader(new FileInputStream(file), "UTF-8");
- }
-
- /**
- *
- * @param target
- * @throws XMLStreamException
- */
- public XMLReader(final InputStream source) throws XMLStreamException
- {
- this.nextEvent = null;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- this.in = factory.createXMLEventReader(source);
- }
-
- /**
- *
- * @param target
- * @throws XMLStreamException
- */
- public XMLReader(final Reader source) throws XMLStreamException
- {
- this.nextEvent = null;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- this.in = factory.createXMLEventReader(source);
- }
-
- /**
- * @throws XMLStreamException
- */
- public void close() throws XMLStreamException
- {
- if (this.in != null)
- {
- this.in.close();
- }
- }
-
- /**
- * This methods does a premonition act. Useful to detect end of a list.
- *
- * @param label
- * @return
- * @throws XMLStreamException
- */
- public boolean hasNextStartTag(final String label) throws XMLStreamException
- {
- boolean result;
-
- // Load next event.
- if (this.nextEvent == null)
- {
- if (this.in.hasNext())
- {
- this.nextEvent = this.in.nextEvent();
- }
- }
-
- // Analyze next event.
- if (this.nextEvent == null)
- {
- result = false;
- }
- else if ((this.nextEvent.isStartElement()) && (StringUtils.equals(this.nextEvent.asStartElement().getName().getLocalPart(), label)))
- {
- result = true;
- }
- else
- {
- result = false;
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param label
- * @return
- * @throws XMLBadFormatException
- * @throws XMLStreamException
- */
- public XMLTag readContentTag(final String label) throws XMLBadFormatException, XMLStreamException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, content tag [" + label + "] is expected.");
- }
- else if (result.getType() != TagType.CONTENT)
- {
- throw new XMLBadFormatException("Content tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(label, result.getLabel()))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- */
- public XMLTag readEndTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, end tag [" + label + "] is expected.");
- }
- else if (result.getType() != TagType.END)
- {
- throw new XMLBadFormatException("End tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(result.getLabel(), label))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readListTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
- }
- else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY))
- {
- throw new XMLBadFormatException("List tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(label, result.getLabel()))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readNullableContentTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
- }
- else if (!StringUtils.equals(label, result.getLabel()))
- {
- throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
- }
- else if ((result.getType() != TagType.EMPTY) && (result.getType() != TagType.CONTENT))
- {
- throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readNullableStartTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected.");
- }
- else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY))
- {
- throw new XMLBadFormatException("Start tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(result.getLabel(), label))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readStartTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected.");
- }
- else if (result.getType() != TagType.START)
- {
- throw new XMLBadFormatException("Start tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(result.getLabel(), label))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
-
- //
- return result;
- }
-
- /**
- * Transducer graph :
- *
- * - START_DOCUMENT => HEADER TAG
- *
- START_ELEMENT(X) + START_ELEMENT(Y) => => START TAG
- *
- START_ELEMENT(X) + CHARACTERS(C) + START_ELEMENT(Y) => SPACES=>
- * START TAG
- *
- START_ELEMENT(X) + CHARACTERS(C) + END_ELEMENT(X) => C =>
- * CONTENT TAG
- *
- START_ELEMENT(X) + END_ELEMENT(X) => => => EMPTY
- *
- END_ELEMENT(X) =>
=> END TAG
- * - END_DOCUMENT => FOOTER TAG
- *
- *
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- *
- */
- public XMLTag readTag() throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- int level = 1;
- boolean ended = false;
- result = null;
- XMLAttributes attributesBuffer = null;
- QName nameBuffer = null;
- StringList contentBuffer = null;
- while (!ended)
- {
- //
- XMLEvent event;
- if (this.nextEvent != null)
- {
- event = this.nextEvent;
- this.nextEvent = null;
- }
- else if (this.in.hasNext())
- {
- event = this.in.nextEvent();
- }
- else
- {
- event = null;
- }
-
- if (event == null)
- {
- ended = true;
- result = null;
- }
- else
- {
- logger.debug("eventType=" + XMLTools.toString(event));
- switch (level)
- {
- case 1:
- switch (event.getEventType())
- {
- case XMLEvent.START_DOCUMENT:
- // START_DOCUMENT => START DOCUMENT TAG
- ended = true;
- result = new XMLTag(null, TagType.HEADER, null);
- break;
- case XMLEvent.START_ELEMENT:
- // START_ELEMENT(X) => ...
- nameBuffer = event.asStartElement().getName();
- attributesBuffer = new XMLAttributes(event.asStartElement().getAttributes());
- level += 1;
- break;
- case XMLEvent.END_ELEMENT:
- // END_ELEMENT(X) => => END TAG
- ended = true;
- result = new XMLTag(event.asEndElement().getName(), TagType.END, null);
- break;
- case XMLEvent.END_DOCUMENT:
- // END_DOCUMENT => END DOCUMENT TAG
- ended = true;
- result = new XMLTag(null, TagType.FOOTER, null);
- break;
- }
- break;
- case 2:
- switch (event.getEventType())
- {
- case XMLEvent.START_ELEMENT:
- // START_ELEMENT(X) + START_ELEMENT(Y) =>
- // => START TAG
- ended = true;
- result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
- this.nextEvent = event;
- break;
- case XMLEvent.CHARACTERS:
- // START_ELEMENT(X) + CHARACTERS(C) => ...
- contentBuffer = new StringList(50);
- contentBuffer.append(event.asCharacters().getData());
- level += 1;
- break;
- case XMLEvent.END_ELEMENT:
- // START_ELEMENT(X) + END_ELEMENT(X) =>
- // => => EMPTY
- ended = true;
- result = new XMLTag(nameBuffer, TagType.EMPTY, attributesBuffer);
- break;
- default:
- throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
- }
- break;
- case 3:
- switch (event.getEventType())
- {
- case XMLEvent.START_ELEMENT:
- // START_ELEMENT(X) + CHARACTERS(C) +
- // START_ELEMENT(Y) =>
- // SPACES => START TAG
- ended = true;
- result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
- this.nextEvent = event;
- break;
- case XMLEvent.CHARACTERS:
- // START_ELEMENT(X) + CHARACTERS(C1) +
- // CHARACTERS(C2)=> ...
- contentBuffer.append(event.asCharacters().getData());
- break;
- case XMLEvent.END_ELEMENT:
- // START_ELEMENT(X) + CHARACTERS(C) +
- // END_ELEMENT(X) => C
- // => CONTENT TAG
- ended = true;
- result = new XMLTag(nameBuffer, TagType.CONTENT, attributesBuffer);
- result.setContent(contentBuffer.toString());
- break;
- default:
- throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
- }
- break;
- default:
- throw new XMLBadFormatException("Unexpected level [" + level + "].");
- }
- }
- }
-
- logger.debug("=> " + XMLTools.toString(result));
-
- //
- return result;
- }
-
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- */
- public XMLTag readXMLFooter() throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, end document event is expected.");
- }
- else if (result.getType() != TagType.FOOTER)
- {
- throw new XMLBadFormatException("End document tag is missing.");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- * @throws XMLException
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- */
- public XMLTag readXMLHeader() throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
-
- //
- result = readTag();
-
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, start document event is expected.");
- }
- else if (result.getType() != TagType.HEADER)
- {
- throw new XMLBadFormatException("XML header is missing.");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param args
- * @throws Exception
- */
- public static void main(final String args[]) throws Exception
- {
-
- XMLInputFactory factory = XMLInputFactory.newInstance();
- XMLEventReader in = factory.createXMLEventReader(new FileReader("/home/cpm/C/Puck/Dev/Puck/test/TT/t3.puc"));
-
- XMLEvent event;
- while (in.hasNext())
- {
- event = in.nextEvent();
-
- switch (event.getEventType())
- {
- case XMLEvent.ATTRIBUTE:
- System.out.println("ATTRIBUTE ");
- break;
- case XMLEvent.CDATA:
- System.out.println("CDATA");
- break;
- case XMLEvent.CHARACTERS:
- System.out.println("CHARACTERS [" + event.asCharacters().getData() + "]");
- break;
- case XMLEvent.COMMENT:
- System.out.println("COMMENT");
- break;
- case XMLEvent.DTD:
- System.out.println("DTD");
- break;
- case XMLEvent.END_DOCUMENT:
- System.out.println("END_DOCUMENT");
- break;
- case XMLEvent.END_ELEMENT:
- System.out.println("END_ELEMENT " + event.asEndElement().getName());
- break;
- case XMLEvent.ENTITY_DECLARATION:
- System.out.println("ENTITY_DECLARATION");
- break;
- case XMLEvent.ENTITY_REFERENCE:
- System.out.println("ENTITY_REFERENCE");
- break;
- case XMLEvent.NAMESPACE:
- System.out.println("NAMESPACE");
- break;
- case XMLEvent.NOTATION_DECLARATION:
- System.out.println("NOTATION_DECLARATION");
- break;
- case XMLEvent.PROCESSING_INSTRUCTION:
- System.out.println("PROCESSING_INSTRUCTION");
- break;
- case XMLEvent.SPACE:
- System.out.println("SPACE");
- break;
- case XMLEvent.START_DOCUMENT:
- System.out.println("START_DOCUMENT");
- break;
- case XMLEvent.START_ELEMENT:
- System.out.println("START_ELEMENT [name=" + event.asStartElement().getName() + "][namespaceURI=" + event.asStartElement().getName().getNamespaceURI() + "][prefix="
- + event.asStartElement().getName().getPrefix() + "][localPart=" + event.asStartElement().getName().getLocalPart() + "]");
- break;
- default:
- System.out.println("DEFAULT");
- }
- }
- }
-}
diff --git a/src/fr/devinsy/util/xml/XMLTag.java b/src/fr/devinsy/util/xml/XMLTag.java
deleted file mode 100644
index 806f754..0000000
--- a/src/fr/devinsy/util/xml/XMLTag.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import javax.xml.namespace.QName;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLTag
-{
-
- public enum TagType
- {
- HEADER, START, END, EMPTY, CONTENT, FOOTER
- }
-
- private QName name;
- private TagType type;
- private XMLAttributes attributes;
- private String content;
-
- /**
- *
- */
- public XMLTag(final QName name, final TagType type, final XMLAttributes attributes)
- {
- this.name = name;
- this.type = type;
- this.attributes = attributes;
- this.content = null;
- }
-
- public XMLAttributes attributes()
- {
- return this.attributes;
- }
-
- public String getContent()
- {
- return this.content;
- }
-
- /**
- *
- * @return
- */
- public String getLabel()
- {
- String result;
-
- if (this.name == null)
- {
- result = "";
- }
- else
- {
- result = this.name.getLocalPart();
- }
-
- //
- return result;
- }
-
- public QName getName()
- {
- return this.name;
- }
-
- /**
- *
- * @return
- */
- public String getNamespaceURI()
- {
- String result;
-
- if (this.name == null)
- {
- result = "";
- }
- else
- {
- result = this.name.getNamespaceURI();
- }
-
- //
- return result;
- }
-
- /**
- *
- * @return
- */
- public String getPrefix()
- {
- String result;
-
- if (this.name == null)
- {
- result = "";
- }
- else
- {
- result = this.name.getPrefix();
- }
-
- //
- return result;
- }
-
- public TagType getType()
- {
- return this.type;
- }
-
- public void setContent(final String content)
- {
- this.content = content;
- }
-
- public void setName(final QName name)
- {
- this.name = name;
- }
-
- public void setType(final TagType type)
- {
- this.type = type;
- }
-}
diff --git a/src/fr/devinsy/util/xml/XMLTools.java b/src/fr/devinsy/util/xml/XMLTools.java
deleted file mode 100644
index a7de117..0000000
--- a/src/fr/devinsy/util/xml/XMLTools.java
+++ /dev/null
@@ -1,389 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.zip.ZipInputStream;
-
-import javax.xml.stream.events.XMLEvent;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLTools
-{
- /**
- *
- * @param source
- * @return
- */
- public static String escapeXmlBlank(final String source)
- {
- String result;
-
- if (StringUtils.isBlank(source))
- {
- result = "";
- }
- else
- {
- result = StringEscapeUtils.escapeXml(source);
- }
-
- //
- return result;
- }
-
- /**
- *
- *
- * @param source
- * @throws SAXException
- * @throws IOException
- * @throws PuckException
- */
- public static boolean isValid(final File xmlFile, final File xsdFile) throws SAXException, IOException
- {
- boolean result;
-
- //
- InputStream xmlSource;
- if (isZipFile(xmlFile))
- {
- ZipInputStream zin = new ZipInputStream(new FileInputStream(xmlFile));
- zin.getNextEntry();
- xmlSource = zin;
- }
- else
- {
- xmlSource = new FileInputStream(xmlFile);
- }
-
- //
- result = isValid(xmlSource, new FileInputStream(xsdFile));
-
- //
- return result;
- }
-
- /**
- *
- *
- * @param source
- * @throws SAXException
- * @throws IOException
- * @throws PuckException
- */
- public static boolean isValid(final File xmlFile, final InputStream xsdSource) throws SAXException, IOException
- {
- boolean result;
-
- //
- InputStream xmlSource;
- if (isZipFile(xmlFile))
- {
- ZipInputStream zin = new ZipInputStream(new FileInputStream(xmlFile));
- zin.getNextEntry();
- xmlSource = zin;
- }
- else
- {
- xmlSource = new FileInputStream(xmlFile);
- }
-
- //
- result = isValid(xmlSource, xsdSource);
-
- //
- return result;
- }
-
- /**
- *
- *
- * @param source
- * @throws SAXException
- * @throws IOException
- * @throws PuckException
- */
- public static boolean isValid(final InputStream xmlSource, final InputStream xsdSource) throws SAXException, IOException
- {
- boolean result;
-
- if (xmlSource == null)
- {
- result = false;
- }
- else
- {
- try
- {
- //
- SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
- InputSource sourceentree = new InputSource(xsdSource);
- SAXSource sourceXSD = new SAXSource(sourceentree);
- Schema schema = factory.newSchema(sourceXSD);
- Validator validator = schema.newValidator();
-
- //
- validator.validate(new StreamSource(xmlSource));
- result = true;
-
- }
- catch (final IllegalArgumentException exception)
- {
- exception.printStackTrace();
- result = false;
- }
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param file
- * @return
- * @throws IOException
- */
- public static boolean isZipFile(final File file) throws IOException
- {
- boolean result;
-
- //
- byte[] buffer = new byte[4];
- FileInputStream is = null;
- try
- {
- is = new FileInputStream(file);
- is.read(buffer);
- }
- finally
- {
- if (is != null)
- {
- is.close();
- }
- }
-
- // 50 4B 3 4
- if ((buffer[0] == 0x50) && (buffer[1] == 0x4B) && (buffer[2] == 0x03) && (buffer[3] == 0x04))
- {
- result = true;
- }
- else
- {
- result = false;
- }
-
- //
- return result;
- }
-
- /**
- *
- */
- public static String readTag(final BufferedReader in) throws Exception
- {
- String result;
-
- Pattern TAG_PATTERN = Pattern.compile("^<([\\w-_\\.]+)>.*([\\w-_\\.]+)>$");
- Pattern SHORT_TAG_PATTERN = Pattern.compile("^<.+/>$");
-
- result = in.readLine();
- boolean ended = false;
- while (!ended)
- {
- /*
- * DEBUG Matcher tagMatcher2 = TAG_PATTERN.matcher(result); if
- * (tagMatcher2.find()) { logger.info("group count,0,1,2 = [" +
- * tagMatcher2.groupCount() + "][" + tagMatcher2.group(0) + "][" +
- * tagMatcher2.group(1) + "][" + tagMatcher2.group(2) + "]"); }
- */
-
- Matcher tagMatcher = TAG_PATTERN.matcher(result);
- Matcher shortTagMatcher = SHORT_TAG_PATTERN.matcher(result);
-
- if ((tagMatcher.find()) && (tagMatcher.groupCount() == 2) && (tagMatcher.group(1).equals(tagMatcher.group(2))))
- {
- ended = true;
- }
- else if (shortTagMatcher.matches())
- {
- ended = true;
- }
- else
- {
- result += in.readLine();
- }
- }
-
- //
- return (result);
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String toHTLM5(final String source)
- {
- String result;
-
- if (StringUtils.isBlank(source))
- {
- result = "";
- }
- else
- {
- result = source.replace(" ", " ");
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param value
- * @return
- */
- public static String toString(final XMLEvent source)
- {
- String result;
-
- switch (source.getEventType())
- {
- case XMLEvent.ATTRIBUTE:
- result = "ATTRIBUTE ";
- break;
- case XMLEvent.CDATA:
- result = "CDATA";
- break;
- case XMLEvent.CHARACTERS:
- result = "CHARACTERS [" + source.asCharacters().getData() + "]";
- break;
- case XMLEvent.COMMENT:
- result = "COMMENT";
- break;
- case XMLEvent.DTD:
- result = "DTD";
- break;
- case XMLEvent.END_DOCUMENT:
- result = "END_DOCUMENT";
- break;
- case XMLEvent.END_ELEMENT:
- result = "END_ELEMENT " + source.asEndElement().getName();
- break;
- case XMLEvent.ENTITY_DECLARATION:
- result = "ENTITY_DECLARATION";
- break;
- case XMLEvent.ENTITY_REFERENCE:
- result = "ENTITY_REFERENCE";
- break;
- case XMLEvent.NAMESPACE:
- result = "NAMESPACE";
- break;
- case XMLEvent.NOTATION_DECLARATION:
- result = "NOTATION_DECLARATION";
- break;
- case XMLEvent.PROCESSING_INSTRUCTION:
- result = "PROCESSING_INSTRUCTION";
- break;
- case XMLEvent.SPACE:
- result = "SPACE";
- break;
- case XMLEvent.START_DOCUMENT:
- result = "START_DOCUMENT";
- break;
- case XMLEvent.START_ELEMENT:
- result = "START_ELEMENT [name=" + source.asStartElement().getName() + "][namespaceURI=" + source.asStartElement().getName().getNamespaceURI() + "][prefix="
- + source.asStartElement().getName().getPrefix() + "][localPart=" + source.asStartElement().getName().getLocalPart() + "]";
- break;
- default:
- result = null;
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param event
- * @return
- */
- public static String toString(final XMLTag source)
- {
- String result;
-
- if (source == null)
- {
- result = "null";
- }
- else
- {
- result = "[label=" + source.getLabel() + "][type=" + source.getType().toString() + "][content=" + source.getContent() + "]";
- }
-
- //
- return result;
- }
-
- /**
- *
- * @param source
- * @return
- */
- public static String unescapeXmlBlank(final String source)
- {
- String result;
-
- if (StringUtils.isBlank(source))
- {
- result = null;
- }
- else
- {
- result = StringEscapeUtils.unescapeXml(source);
- }
-
- //
- return result;
- }
-}
diff --git a/src/fr/devinsy/util/xml/XMLWriter.java b/src/fr/devinsy/util/xml/XMLWriter.java
deleted file mode 100644
index d5b41ec..0000000
--- a/src/fr/devinsy/util/xml/XMLWriter.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-import org.apache.commons.lang3.ArrayUtils;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLWriter
-{
-
- protected PrintWriter out;
-
- /**
- * Default constructor (useful for extend this class).
- */
- protected XMLWriter()
- {
- this.out = null;
- }
-
- /**
- * Initialize a XML Writer to a file.
- *
- * @param file
- * Where write the XML data.
- *
- * @throws FileNotFoundException
- * @throws UnsupportedEncodingException
- */
- public XMLWriter(final File file) throws UnsupportedEncodingException, FileNotFoundException
- {
- this.out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
- }
-
- /**
- * Initialize a XML Writer to a OutputStream
.
- *
- * @param target
- * Where write the XML data.
- *
- * @throws UnsupportedEncodingException
- */
- public XMLWriter(final OutputStream target) throws UnsupportedEncodingException
- {
- this.out = new PrintWriter(new OutputStreamWriter(target, "UTF-8"));
- }
-
- /**
- * Initialize a XML Writer to a Writer
.
- *
- * @param target
- * Where write the XML data.
- *
- * @throws UnsupportedEncodingException
- */
- public XMLWriter(final Writer target) throws UnsupportedEncodingException
- {
- this.out = new PrintWriter(target);
- }
-
- /**
- * This method closes the target stream.
- */
- public void close() throws IOException
- {
- if (this.out != null)
- {
- this.out.flush();
- this.out.close();
- }
- }
-
- /**
- * This method flushes the target stream.
- */
- public void flush() throws IOException
- {
- if (this.out != null)
- {
- this.out.flush();
- }
- }
-
- /**
- * This method writes a XML comment.
- *
- * @param comment
- * The comment to write.
- */
- public void writeComment(final String comment)
- {
- this.out.print("");
- }
-
- /**
- * This method writes a XML tag with no content.
- */
- public void writeEmptyTag(final String label, final String... attributes)
- {
- this.out.print("<");
- this.out.print(label);
- writeTagAttributes(attributes);
- this.out.print("/>");
- }
-
- /**
- * This method writes a XML ender tag.
- */
- public void writeEndTag(final String label)
- {
- this.out.print("");
- this.out.print(label);
- this.out.print(">");
- }
-
- /**
- * This method writes a XML start tag.
- */
- public void writeStartTag(final String label, final String... attributes)
- {
- this.out.print("<");
- this.out.print(label);
- writeTagAttributes(attributes);
- this.out.print(">");
- }
-
- /**
- * This method write a XML tag with attributes and boolean content data.
- *
- * @param label
- * @param content
- * @param attributes
- */
- public void writeTag(final String label, final boolean content, final String... attributes)
- {
- writeStartTag(label, attributes);
- writeTagContent(String.valueOf(content));
- writeEndTag(label);
- }
-
- /**
- * This method write a XML tag with attributes and long content data.
- *
- * @param label
- * @param content
- * @param attributes
- */
- public void writeTag(final String label, final long content, final String... attributes)
- {
- writeStartTag(label, attributes);
- writeTagContent(String.valueOf(content));
- writeEndTag(label);
- }
-
- /**
- * This method write a XML tag with attributes and content data. Content
- * data are converted in XML format.
- *
- * @param label
- * @param content
- * @param attributes
- */
- public void writeTag(final String label, final String content, final String... attributes)
- {
- if (content == null)
- {
- writeEmptyTag(label, attributes);
- }
- else
- {
- writeStartTag(label, attributes);
- writeTagContent(content);
- writeEndTag(label);
- }
- }
-
- /**
- * This method writes attributes of a tag.
- *
- * @param attributes
- */
- private void writeTagAttributes(final String... attributes)
- {
- //
- if ((attributes != null) && (attributes.length > 0))
- {
- for (int count = 0; count < attributes.length; count += 2)
- {
- this.out.print(" ");
- this.out.print(attributes[count]);
- this.out.print("=\"");
- this.out.print(attributes[count + 1]);
- this.out.print("\"");
- }
- }
- }
-
- /**
- * This method writes content using XML escape.
- *
- * @param content
- * data to write in XML format.
- */
- private void writeTagContent(final String content)
- {
- //
- for (int count = 0; count < content.length(); count++)
- {
- //
- char car = content.charAt(count);
-
- switch (car)
- {
- case '<':
- this.out.print("<");
- break;
- case '>':
- this.out.print(">");
- break;
- case '&':
- this.out.print("&");
- break;
- case '"':
- this.out.print(""");
- break;
- case '\'':
- this.out.print("'");
- break;
- default:
- this.out.print(car);
- }
- }
- }
-
- /**
- * This method writes a XML header with attributes.
- *
- * @param attributes
- */
- public void writeXMLHeader(final String... attributes)
- {
-
- //
- this.out.print("");
- }
-}
diff --git a/src/fr/devinsy/util/xml/XMLZipReader.java b/src/fr/devinsy/util/xml/XMLZipReader.java
deleted file mode 100644
index a988c32..0000000
--- a/src/fr/devinsy/util/xml/XMLZipReader.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipInputStream;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLZipReader extends XMLReader
-{
-
- /**
- *
- * @param file
- * @throws IOException
- * @throws XMLStreamException
- */
- public XMLZipReader(final File file) throws IOException, XMLStreamException
- {
- super();
-
- XMLInputFactory factory = XMLInputFactory.newInstance();
- ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
- zis.getNextEntry();
- this.in = factory.createXMLEventReader(zis, "UTF-8");
- }
-
- /**
- *
- * @param target
- * @throws IOException
- * @throws XMLStreamException
- */
- public XMLZipReader(final InputStream source) throws IOException, XMLStreamException
- {
- super();
-
- XMLInputFactory factory = XMLInputFactory.newInstance();
- ZipInputStream zis = new ZipInputStream(source);
- zis.getNextEntry();
- this.in = factory.createXMLEventReader(zis, "UTF-8");
- }
-}
diff --git a/src/fr/devinsy/util/xml/XMLZipWriter.java b/src/fr/devinsy/util/xml/XMLZipWriter.java
deleted file mode 100644
index 515ccf2..0000000
--- a/src/fr/devinsy/util/xml/XMLZipWriter.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/**
- * Copyright (C) 2013-2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.zip.Deflater;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import fr.devinsy.util.FileTools;
-
-/**
- *
- * @author Christian Pierre MOMON (christian.momon@devinsy.fr)
- */
-public class XMLZipWriter extends XMLWriter
-{
- private ZipOutputStream zos;
-
- /**
- *
- * @param file
- * @throws IOException
- */
- public XMLZipWriter(final File file) throws IOException
- {
- super();
-
- this.zos = new ZipOutputStream(new FileOutputStream(file));
- this.zos.setLevel(Deflater.BEST_COMPRESSION);
- this.zos.setMethod(ZipOutputStream.DEFLATED);
- this.zos.setComment("Generated by XMLZipWriter");
- this.zos.putNextEntry(new ZipEntry(FileTools.setExtension(file, ".xml").getName()));
- this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
- }
-
- /**
- *
- * @param file
- * @throws IOException
- */
- public XMLZipWriter(final File file, final String generator) throws IOException
- {
- super();
-
- this.zos = new ZipOutputStream(new FileOutputStream(file));
- this.zos.setLevel(Deflater.BEST_COMPRESSION);
- this.zos.setMethod(ZipOutputStream.DEFLATED);
- this.zos.setComment(generator);
- this.zos.putNextEntry(new ZipEntry(FileTools.setExtension(file, ".xml").getName()));
- this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
- }
-
- /**
- *
- * @param target
- * @throws IOException
- */
- public XMLZipWriter(final OutputStream target, final String generator) throws IOException
- {
- super();
- this.zos = new ZipOutputStream(target);
- this.zos.setLevel(Deflater.BEST_COMPRESSION);
- this.zos.setMethod(ZipOutputStream.DEFLATED);
- if (generator != null)
- {
- this.zos.setComment(generator);
- }
- this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
- }
-
- /**
- *
- * @param target
- * @throws IOException
- */
- public XMLZipWriter(final OutputStream target, final String fileName, final String generator) throws IOException
- {
- super();
- this.zos = new ZipOutputStream(target);
- this.zos.setLevel(Deflater.BEST_COMPRESSION);
- this.zos.setMethod(ZipOutputStream.DEFLATED);
- if (generator != null)
- {
- this.zos.setComment(generator);
- }
- openEntry(fileName);
- this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
- }
-
- /**
- * @throws IOException
- *
- */
- @Override
- public void close() throws IOException
- {
- closeEntry();
- super.close();
- }
-
- /**
- * @throws IOException
- *
- */
- public void closeEntry() throws IOException
- {
- flush();
- this.zos.closeEntry();
- }
-
- /**
- *
- * @param fileName
- * @throws IOException
- */
- public void openEntry(final String fileName) throws IOException
- {
- if (fileName == null)
- {
- throw new NullPointerException("fileName is null.");
- }
- else
- {
- this.zos.putNextEntry(new ZipEntry(FileTools.setExtension(fileName, ".xml")));
- }
- }
-}
diff --git a/test/FileIteratorSandbox.java b/test/FileIteratorSandbox.java
index 08452c6..6e9a375 100644
--- a/test/FileIteratorSandbox.java
+++ b/test/FileIteratorSandbox.java
@@ -1,20 +1,20 @@
/**
* Copyright (C) 2013 Christian Pierre MOMON
*
- * This file is part of Devinsy-utils.
+ * This file is part of Devinsy-unix.
*
- * Devinsy-utils is free software: you can redistribute it and/or modify
+ * Devinsy-unix is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * Devinsy-utils is distributed in the hope that it will be useful,
+ * Devinsy-unix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
+ * along with Devinsy-unix. If not, see
*/
import java.io.File;
diff --git a/test/fr/devinsy/util/FileToolsTest.java b/test/fr/devinsy/util/FileToolsTest.java
index 2653b83..c965bad 100644
--- a/test/fr/devinsy/util/FileToolsTest.java
+++ b/test/fr/devinsy/util/FileToolsTest.java
@@ -1,20 +1,20 @@
/**
* Copyright (C) 2014 Christian Pierre MOMON
*
- * This file is part of Devinsy-utils.
+ * This file is part of Devinsy-unix.
*
- * Devinsy-utils is free software: you can redistribute it and/or modify
+ * Devinsy-unix is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * Devinsy-utils is distributed in the hope that it will be useful,
+ * Devinsy-unix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
+ * along with Devinsy-unix. If not, see
*/
package fr.devinsy.util;
diff --git a/test/fr/devinsy/util/cmdexec/CmdExecSandbox.java b/test/fr/devinsy/util/cmdexec/CmdExecSandbox.java
deleted file mode 100644
index d0c6418..0000000
--- a/test/fr/devinsy/util/cmdexec/CmdExecSandbox.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package fr.devinsy.util.cmdexec;
-
-/**
- * Copyright (C) 2013 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.PatternLayout;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- */
-class CmdExecSandbox
-{
- static private final Logger logger;
-
- static
- {
- // Initialize logger.
- org.apache.log4j.BasicConfigurator.configure();
- org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
-
- logger = LoggerFactory.getLogger(CmdExecSandbox.class);
- logger.info("Enter");
-
- //
- logger.info("Set the log file format…");
- org.apache.log4j.Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
- defaultLogger.removeAllAppenders();
- defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n")));
-
- logger.info("… done.");
-
- logger.debug("Exit");
- }
-
- /**
- *
- */
- public static String check(final String title, final StringBuffer source, final String model)
- {
- String result;
-
- if (source.indexOf(model) == -1)
- {
- result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
-
- }
- else
- {
- result = String.format("%-40s [ OK ] ", title);
- }
-
- //
- return (result);
- }
-
- /**
- *
- */
- public static void main(final String[] args)
- {
- System.out.println("Automatic test action for CmdExec!");
-
- test1();
-
- }
-
- /**
- *
- */
- public static void test1()
- {
- try
- {
- System.out.println("Launch…s");
-
- // String command = "/bin/sort -r /etc/passwd";
- String[] command = { "/usr/bin/sort", "-r", "/etc/passwd" };
-
- CmdExec cmd = new CmdExec(command, StreamGobbler.StreamWay.BUFFER, StreamGobbler.StreamWay.BUFFER);
- System.out.println("exitVal=[" + cmd.getExitValue() + "]");
- System.out.println("out=[" + cmd.getOutStream() + "]");
- System.out.println("err=[" + cmd.getErrStream() + "]");
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- logger.info("ERRRO=" + exception);
- }
- }
-}
diff --git a/test/fr/devinsy/util/strings/StringListTest.java b/test/fr/devinsy/util/strings/StringListTest.java
deleted file mode 100644
index 9afe379..0000000
--- a/test/fr/devinsy/util/strings/StringListTest.java
+++ /dev/null
@@ -1,402 +0,0 @@
-/**
- * Copyright (C) 2013,2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.util.Iterator;
-
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import fr.devinsy.util.strings.StringList;
-import fr.devinsy.util.strings.StringListCharIterator;
-import fr.devinsy.util.strings.StringListCharPosition;
-
-/**
- *
- * @author Christian P. Momon
- */
-public class StringListTest
-{
- static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(StringListTest.class);
-
- /**
- *
- */
- @Before
- public void before()
- {
- BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.ERROR);
- }
-
- /**
- *
- */
- @Test
- public void testCharAt01()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("abcdefghijklm");
-
- //
- char target = source.charAt(0);
- Assert.assertEquals(target, 'a');
-
- //
- target = source.charAt(4);
- Assert.assertEquals(target, 'e');
-
- //
- target = source.charAt(11);
- Assert.assertEquals(target, 'l');
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testCharAt02()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("abc");
- source.append("def");
- source.append("ghi");
- source.append("jkl");
- source.append("mno");
-
- //
- char target = source.charAt(0);
- Assert.assertEquals('a', target);
-
- //
- target = source.charAt(4);
- Assert.assertEquals('e', target);
-
- //
- target = source.charAt(11);
- Assert.assertEquals('l', target);
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test(expected = IndexOutOfBoundsException.class)
- public void testCharAtException01()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("abcdefghijklm");
-
- //
- char target = source.charAt(-2);
- Assert.assertEquals('a', target);
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test(expected = IndexOutOfBoundsException.class)
- public void testCharAtException02()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("abcdefghijklm");
-
- //
- char target = source.charAt(100);
- Assert.assertEquals('a', target);
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test(expected = IndexOutOfBoundsException.class)
- public void testCharAtException03()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("abcdefghijklm");
-
- //
- char target = source.charAt(source.length());
- Assert.assertEquals('a', target);
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testConstructor01()
- {
- //
- logger.debug("===== test starting...");
-
- String[] source = { "a", "b", "c" };
-
- //
- StringList target = new StringList(source);
-
- Assert.assertEquals(3, target.size());
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testConstructor02()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList target = new StringList("a", "b", "c");
-
- Assert.assertEquals(3, target.size());
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testIteratorOfChar01()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("abc");
- source.append("def");
- source.append("ghi");
- source.append("jkl");
- source.append("mno");
-
- //
- Iterator iterator = source.iteratorOfChar();
-
- for (int index = 0; index < source.length(); index++)
- {
- StringListCharPosition position = ((StringListCharIterator) iterator).nextPosition();
- System.out.println(index + ":" + source.charAt(index) + " " + position.getCharIndex() + " " + position.getStringIndex() + " " + position.getLocalCharIndex());
-
- Assert.assertTrue(iterator.hasNext());
-
- Character character = ((StringListCharIterator) iterator).next();
-
- Assert.assertEquals(character, new Character(source.charAt(index)));
- }
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testSubstring01()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("hamburger");
-
- //
- StringList target = source.substring(4, 8);
- Assert.assertEquals("urge", target.toString());
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testSubstring02()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("ham").append("bur").append("ger");
-
- //
- StringList target = source.substring(4, 8);
- Assert.assertEquals("urge", target.toString());
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- */
- @Test
- public void testSubstring03()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("smiles");
-
- //
- StringList target = source.substring(1, 5);
- Assert.assertEquals("mile", target.toString());
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- */
- @Test
- public void testSubstring04()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList source = new StringList();
- source.append("sm").append("il").append("es");
-
- //
- StringList target = source.substring(1, 5);
- Assert.assertEquals("mile", target.toString());
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testToString01()
- {
- //
- logger.debug("===== test starting...");
-
- //
- StringList buffer = new StringList();
-
- String target = buffer.toString();
-
- Assert.assertTrue(target.equals(""));
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testToString02()
- {
- //
- logger.debug("===== test starting...");
-
- //
- String source = "abcdefghijklm";
-
- StringList buffer = new StringList();
- buffer.append(source);
-
- String target = buffer.toString();
-
- Assert.assertEquals(source, target);
- Assert.assertTrue(target.equals(source));
-
- //
- logger.debug("===== test done.");
- }
-
- /**
- *
- */
- @Test
- public void testToString03()
- {
- //
- logger.debug("===== test starting...");
-
- //
- String source1 = "abcdefghijklm";
- String source2 = "other stuff";
-
- StringList buffer = new StringList();
- buffer.append(source1);
- buffer.append(source2);
-
- String target = buffer.toString();
-
- Assert.assertTrue(target.equals(source1 + source2));
-
- //
- logger.debug("===== test done.");
- }
-
-}
diff --git a/test/fr/devinsy/util/strings/StringListUtilsTest.java b/test/fr/devinsy/util/strings/StringListUtilsTest.java
deleted file mode 100644
index 097d37f..0000000
--- a/test/fr/devinsy/util/strings/StringListUtilsTest.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/**
- * Copyright (C) 2013,2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.strings;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- *
- * @author Christian P. Momon
- */
-public class StringListUtilsTest
-{
- private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(StringListUtilsTest.class);
-
- /**
- *
- */
- @Before
- public void before()
- {
- BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.ERROR);
- }
-
- /**
- *
- */
- @Test
- public void testContainsBlank01()
- {
- Assert.assertFalse(StringListUtils.containsBlank((Collection) null));
- Assert.assertFalse(StringListUtils.containsBlank(new StringList("aaa", "bbb", "ccc")));
- Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", null, "ccc")));
- Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", "", "ccc")));
- Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", " ", "ccc")));
- }
-
- /**
- *
- */
- @Test
- public void testContainsBlank02()
- {
- Assert.assertFalse(StringListUtils.containsBlank((String[]) null));
- Assert.assertFalse(StringListUtils.containsBlank("aaa", "bbb", "ccc"));
- Assert.assertTrue(StringListUtils.containsBlank("aaa", null, "ccc"));
- Assert.assertTrue(StringListUtils.containsBlank("aaa", "", "ccc"));
- Assert.assertTrue(StringListUtils.containsBlank("aaa", " ", "ccc"));
- }
-
- /**
- *
- */
- @Test
- public void testContainsBlank03()
- {
- Assert.assertFalse(StringListUtils.containsBlank((ArrayList) null));
- ArrayList source = new ArrayList();
- source.add("aaa");
- source.add("bbb");
- source.add("ccc");
- Assert.assertFalse(StringListUtils.containsBlank(source));
- source.set(1, null);
- Assert.assertTrue(StringListUtils.containsBlank(source));
- source.set(1, "");
- Assert.assertTrue(StringListUtils.containsBlank(source));
- source.set(1, " ");
- Assert.assertTrue(StringListUtils.containsBlank(source));
- }
-
- /**
- *
- */
- @Test
- public void testContainsEmpty01()
- {
- Assert.assertFalse(StringListUtils.containsEmpty((Collection) null));
- Assert.assertFalse(StringListUtils.containsEmpty(new StringList("aaa", "bbb", "ccc")));
- Assert.assertTrue(StringListUtils.containsEmpty(new StringList("aaa", null, "ccc")));
- Assert.assertTrue(StringListUtils.containsEmpty(new StringList("aaa", "", "ccc")));
- }
-
- /**
- *
- */
- @Test
- public void testContainsEmpty02()
- {
- Assert.assertFalse(StringListUtils.containsEmpty((String[]) null));
- Assert.assertFalse(StringListUtils.containsEmpty("aaa", "bbb", "ccc"));
- Assert.assertTrue(StringListUtils.containsEmpty("aaa", null, "ccc"));
- Assert.assertTrue(StringListUtils.containsEmpty("aaa", "", "ccc"));
- }
-
- /**
- *
- */
- @Test
- public void testContainsEmpty03()
- {
- Assert.assertFalse(StringListUtils.containsEmpty((ArrayList) null));
- ArrayList source = new ArrayList();
- source.add("aaa");
- source.add("bbb");
- source.add("ccc");
- Assert.assertFalse(StringListUtils.containsEmpty(source));
- source.set(1, null);
- Assert.assertTrue(StringListUtils.containsEmpty(source));
- source.set(1, "");
- Assert.assertTrue(StringListUtils.containsEmpty(source));
- }
-
- /**
- *
- */
- @Test
- public void testContainsNull01()
- {
- Assert.assertFalse(StringListUtils.containsNull((Collection) null));
- Assert.assertFalse(StringListUtils.containsNull(new StringList("aaa", "bbb", "ccc")));
- Assert.assertTrue(StringListUtils.containsNull(new StringList("aaa", null, "ccc")));
- }
-
- /**
- *
- */
- @Test
- public void testContainsNull02()
- {
- Assert.assertFalse(StringListUtils.containsNull((String[]) null));
- Assert.assertFalse(StringListUtils.containsNull("aaa", "bbb", "ccc"));
- Assert.assertTrue(StringListUtils.containsNull("aaa", null, "ccc"));
- }
-
- /**
- *
- */
- @Test
- public void testContainsNull03()
- {
- Assert.assertFalse(StringListUtils.containsNull((ArrayList) null));
- ArrayList source = new ArrayList();
- source.add("aaa");
- source.add("bbb");
- source.add("ccc");
- Assert.assertFalse(StringListUtils.containsNull(source));
- source.set(1, null);
- Assert.assertTrue(StringListUtils.containsNull(source));
- }
-}
diff --git a/test/fr/devinsy/util/util/rss/RSSCacheTest.java b/test/fr/devinsy/util/util/rss/RSSCacheTest.java
deleted file mode 100644
index dd3aa8a..0000000
--- a/test/fr/devinsy/util/util/rss/RSSCacheTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Copyright (C) 2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.util.rss;
-
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-
-import fr.devinsy.util.rss.RSSCache;
-
-/**
- *
- * @author Christian P. Momon
- */
-public class RSSCacheTest
-{
- static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(RSSCacheTest.class);
-
- /**
- *
- */
- @Before
- public void before()
- {
- BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.ERROR);
- }
-
- /**
- *
- */
- @Test
- public void test01()
- {
- //
- logger.debug("===== test starting...");
-
- RSSCache cache = RSSCache.instance();
-
- cache.put("ALPHA", "Mignonne, allons voir si la rose");
- cache.put("BRAVO", "Qui ce matin avoit desclose");
- cache.put("CHARLIE", "Sa robe de pourpre au Soleil,");
-
- cache.setOudated("CHARLIE");
-
- //
- logger.debug("===== test done.");
- }
-}
diff --git a/test/fr/devinsy/util/xml/XMLReaderTest.java b/test/fr/devinsy/util/xml/XMLReaderTest.java
deleted file mode 100644
index 02e4f1a..0000000
--- a/test/fr/devinsy/util/xml/XMLReaderTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/**
- * Copyright (C) 2014 Christian Pierre MOMON
- *
- * This file is part of Devinsy-utils.
- *
- * Devinsy-utils is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Devinsy-utils is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Devinsy-utils. If not, see
- */
-package fr.devinsy.util.xml;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-
-import javax.xml.stream.XMLStreamException;
-
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-
-import fr.devinsy.util.strings.StringList;
-
-/**
- *
- * @author Christian P. Momon
- */
-public class XMLReaderTest
-{
- static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(XMLReaderTest.class);
-
- /**
- *
- */
- @Before
- public void before()
- {
- BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.ERROR);
- }
-
- /**
- * @throws XMLStreamException
- * @throws FileNotFoundException
- * @throws XMLBadFormatException
- *
- */
- // @Test
- public void testFoo01() throws FileNotFoundException, XMLStreamException, XMLBadFormatException
- {
- //
- logger.debug("===== test starting...");
-
- // XMLReader in = new XMLReader(new
- // File("/home/cpm/C/Puck/TY/Ebrei 08.puc"));
- // XMLReader in = new XMLReader(new
- // File("/home/cpm/C/Puck/TY/T/kidarep.xml"));
- XMLReader in = new XMLReader(new File("/home/cpm/C/Puck/TY/T2/sikevadb-2014-06-08-17h55mn49s.xml"));
-
- boolean ended = false;
- while (!ended)
- {
- XMLTag tag = in.readTag();
-
- if (tag == null)
- {
- ended = true;
- }
- else
- {
- // System.out.println(String.format("tag %s", tag.getLabel()));
- }
-
- //
- logger.debug("===== test done.");
- }
- System.out.println("over");
- }
-
- /**
- * @throws XMLStreamException
- * @throws FileNotFoundException
- * @throws XMLBadFormatException
- *
- */
- // @Test
- public void testFoo02() throws FileNotFoundException, XMLStreamException, XMLBadFormatException
- {
- //
- logger.debug("===== test starting...");
-
- // XMLReader in = new XMLReader(new
- // File("/home/cpm/C/Puck/TY/Ebrei 08.puc"));
- XMLReader in = new XMLReader(new File("/home/cpm/C/Puck/TY/T/accounts.xml"));
- // XMLReader in = new XMLReader(new
- // File("/home/cpm/C/Puck/TY/T2/sikevadb-2014-06-08-17h55mn49s.xml"));
-
- boolean ended = false;
- StringList buffer = new StringList();
- while (!ended)
- {
- XMLTag tag = in.readTag();
-
- if (tag == null)
- {
- ended = true;
- }
- else
- {
- if (tag.getContent() != null)
- {
- System.out.println(buffer.append(tag.getContent()));
- }
- }
-
- //
- logger.debug("===== test done.");
- }
- System.out.println("over");
- }
-
-}