1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +00:00

VFSService and pom.xml updated

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-26 19:06:37 -03:00
parent 566c4e2037
commit a162b9d6d5
17 changed files with 450 additions and 105 deletions

View File

@@ -18,6 +18,8 @@ package com.l2jserver.util.transformer;
import java.io.File;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URL;
import com.l2jserver.util.transformer.impl.BooleanTransformer;
import com.l2jserver.util.transformer.impl.ByteTransformer;
@@ -29,6 +31,8 @@ import com.l2jserver.util.transformer.impl.InetSocketAddressTransformer;
import com.l2jserver.util.transformer.impl.IntegerTransformer;
import com.l2jserver.util.transformer.impl.LongTransformer;
import com.l2jserver.util.transformer.impl.ShortTransformer;
import com.l2jserver.util.transformer.impl.URITransformer;
import com.l2jserver.util.transformer.impl.URLTransformer;
/**
* The {@link TransformerFactory} return the transformer instance for any given
@@ -65,6 +69,10 @@ public class TransformerFactory {
return FileTransformer.SHARED_INSTANCE;
} else if (type == Class.class) {
return ClassTransformer.SHARED_INSTANCE;
} else if (type == URI.class) {
return URITransformer.SHARED_INSTANCE;
} else if (type == URL.class) {
return URLTransformer.SHARED_INSTANCE;
}
return null;
}

View File

@@ -0,0 +1,46 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.transformer.impl;
import java.net.URI;
import java.net.URISyntaxException;
import com.l2jserver.util.transformer.Transformer;
/**
* Transform an {@link URI} into an string.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class URITransformer implements Transformer<URI> {
public static final URITransformer SHARED_INSTANCE = new URITransformer();
@Override
public String transform(URI value) {
return value.toString();
}
@Override
public URI untransform(String value) {
try {
return new URI(value);
} catch (URISyntaxException e) {
return null;
}
}
}

View File

@@ -0,0 +1,47 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.transformer.impl;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import com.l2jserver.util.transformer.Transformer;
/**
* Transform an {@link URI} into an string.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class URLTransformer implements Transformer<URL> {
public static final URLTransformer SHARED_INSTANCE = new URLTransformer();
@Override
public String transform(URL value) {
return value.toString();
}
@Override
public URL untransform(String value) {
try {
return new URL(value);
} catch (MalformedURLException e) {
return null;
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.vfs;
import java.util.Arrays;
import org.apache.commons.vfs.FileSelectInfo;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileType;
/**
* This selector will select all <tt>FILES</tt> that has an given extension.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ExtensionFileSelector implements FileSelector {
private final String[] extensions;
private final boolean descendents;
public ExtensionFileSelector(String... extensions) {
this(true, extensions);
}
public ExtensionFileSelector(boolean descendents, String... extensions) {
this.descendents = descendents;
this.extensions = extensions;
Arrays.sort(extensions);
}
@Override
public boolean includeFile(FileSelectInfo file) throws Exception {
if (file.getFile().getType() != FileType.FILE)
return false;
return (Arrays.binarySearch(extensions, file.getFile().getName()
.getExtension()) >= 0);
}
@Override
public boolean traverseDescendents(FileSelectInfo file) throws Exception {
return descendents;
}
public static final ExtensionFileSelector ext(String... extensions) {
return new ExtensionFileSelector(extensions);
}
}