.
+ *
+ * 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 .
+ */
+package com.l2jserver.service.core.vfs;
+
+import java.net.URI;
+import java.nio.file.Path;
+
+import com.l2jserver.service.configuration.Configuration;
+import com.l2jserver.service.configuration.Configuration.ConfigurationName;
+
+/**
+ * VFS service configuration
+ *
+ * @author Rogiel
+ * @see Configuration
+ */
+@ConfigurationName("vfs")
+public interface VFSConfiguration extends Configuration {
+ /**
+ * @return the VFS root {@link URI}
+ */
+ @ConfigurationPropertyGetter(name = "vfs.root", defaultValue = "")
+ Path getRoot();
+
+ /**
+ * @param root
+ * the new VFS root {@link URI}
+ */
+ @ConfigurationPropertySetter(name = "vfs.root")
+ void setRoot(Path root);
+}
diff --git a/src/main/java/com/l2jserver/service/core/vfs/VFSService.java b/src/main/java/com/l2jserver/service/core/vfs/VFSService.java
index 5cd28558e..86ba08379 100644
--- a/src/main/java/com/l2jserver/service/core/vfs/VFSService.java
+++ b/src/main/java/com/l2jserver/service/core/vfs/VFSService.java
@@ -16,9 +16,7 @@
*/
package com.l2jserver.service.core.vfs;
-import java.net.URI;
-
-import org.apache.commons.vfs.FileObject;
+import java.nio.file.Path;
import com.l2jserver.service.Service;
@@ -29,18 +27,6 @@ import com.l2jserver.service.Service;
* @author Rogiel
*/
public interface VFSService extends Service {
- /**
- * Resolves an file. If the file cannot be resolved, null will be returned.
- *
- * Please note that event if the file DOES NOT exists a valid object will be
- * returned.
- *
- * @param uri
- * the file uri
- * @return the resolved file. Will return null if could not resolve.
- */
- FileObject resolve(URI uri);
-
/**
* Resolves an file. If the file cannot be resolved, null will be returned.
*
@@ -51,5 +37,5 @@ public interface VFSService extends Service {
* the file uri as an string
* @return the resolved file. Will return null if could not resolve.
*/
- FileObject resolve(String uri);
+ Path resolve(String name);
}
diff --git a/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java b/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java
index 55974e83d..b634fd13a 100644
--- a/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java
+++ b/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java
@@ -18,6 +18,11 @@ package com.l2jserver.service.game.template;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
import javax.xml.bind.JAXBContext;
@@ -29,7 +34,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.vfs.FileObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,7 +60,6 @@ import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
import com.l2jserver.util.jaxb.NPCTemplateIDAdapter;
import com.l2jserver.util.jaxb.SkillTemplateIDAdapter;
import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
-import com.l2jserver.util.vfs.ExtensionFileSelector;
@Depends({ LoggingService.class, VFSService.class, CacheService.class,
ConfigurationService.class })
@@ -121,21 +124,35 @@ public class XMLTemplateService extends AbstractService implements
unmarshaller.setAdapter(TeleportationTemplateIDAdapter.class,
teleportationIdTemplateAdapter);
- final FileObject root = vfsService.resolve(config
- .getTemplateDirectory());
+ final Path templatePath = vfsService.resolve(config
+ .getTemplateDirectory().toString());
- log.info("Scanning {} for XML templates", root);
+ log.info("Scanning {} for XML templates", templatePath);
- FileObject[] files = root.findFiles(ExtensionFileSelector
- .ext("xml"));
+ Files.walkFileTree(templatePath, new SimpleFileVisitor() {
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir,
+ BasicFileAttributes attrs) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
- log.info("Located {} XML template files", files.length);
- for (final FileObject file : files) {
- loadTemplate(file);
- }
- final FileObject teleportsXml = root.getParent().resolveFile(
+ @Override
+ public FileVisitResult visitFile(Path file,
+ BasicFileAttributes attrs) throws IOException {
+ if (!file.toString().endsWith(".xml"))
+ return FileVisitResult.CONTINUE;
+ try {
+ loadTemplate(file);
+ return FileVisitResult.CONTINUE;
+ } catch (JAXBException e) {
+ throw new IOException(e);
+ }
+ }
+ });
+
+ final Path teleportsXmlPath = templatePath.getParent().resolve(
"teleports.xml");
- final InputStream in = teleportsXml.getContent().getInputStream();
+ final InputStream in = Files.newInputStream(teleportsXmlPath);
try {
TeleportationTemplateContainer container = (TeleportationTemplateContainer) unmarshaller
.unmarshal(in);
@@ -159,10 +176,10 @@ public class XMLTemplateService extends AbstractService implements
return (T) templates.get(id);
}
- public void loadTemplate(FileObject file) throws JAXBException, IOException {
- Preconditions.checkNotNull(file, "file");
- log.debug("Loading template {}", file);
- final InputStream in = file.getContent().getInputStream();
+ public void loadTemplate(Path path) throws JAXBException, IOException {
+ Preconditions.checkNotNull(path, "path");
+ log.debug("Loading template {}", path);
+ final InputStream in = Files.newInputStream(path);
try {
final Template> template = (Template>) unmarshaller
.unmarshal(in);
diff --git a/src/main/java/com/l2jserver/util/transformer/TransformerFactory.java b/src/main/java/com/l2jserver/util/transformer/TransformerFactory.java
index b0a143c4f..620d17738 100644
--- a/src/main/java/com/l2jserver/util/transformer/TransformerFactory.java
+++ b/src/main/java/com/l2jserver/util/transformer/TransformerFactory.java
@@ -20,6 +20,7 @@ import java.io.File;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URL;
+import java.nio.file.Path;
import com.l2jserver.util.transformer.impl.BooleanTransformer;
import com.l2jserver.util.transformer.impl.ByteTransformer;
@@ -30,6 +31,7 @@ import com.l2jserver.util.transformer.impl.FloatTransformer;
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.PathTransformer;
import com.l2jserver.util.transformer.impl.ShortTransformer;
import com.l2jserver.util.transformer.impl.URITransformer;
import com.l2jserver.util.transformer.impl.URLTransformer;
@@ -73,6 +75,8 @@ public class TransformerFactory {
return URITransformer.SHARED_INSTANCE;
} else if (type == URL.class) {
return URLTransformer.SHARED_INSTANCE;
+ } else if (type == Path.class) {
+ return PathTransformer.SHARED_INSTANCE;
}
return null;
}
diff --git a/src/main/java/com/l2jserver/util/transformer/impl/PathTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/PathTransformer.java
new file mode 100644
index 000000000..d6a4603ea
--- /dev/null
+++ b/src/main/java/com/l2jserver/util/transformer/impl/PathTransformer.java
@@ -0,0 +1,43 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.util.transformer.impl;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import com.l2jserver.util.transformer.Transformer;
+
+/**
+ * Transform an {@link Path} into an string.
+ *
+ * @author Rogiel
+ */
+public class PathTransformer implements Transformer {
+ public static final PathTransformer SHARED_INSTANCE = new PathTransformer();
+
+ @Override
+ public String transform(Path value) {
+ if(value == null)
+ return "";
+ return value.toString();
+ }
+
+ @Override
+ public Path untransform(String value) {
+ return Paths.get(value);
+ }
+}
diff --git a/src/main/java/com/l2jserver/util/transformer/impl/URITransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/URITransformer.java
index 166c83f34..41cb79d15 100644
--- a/src/main/java/com/l2jserver/util/transformer/impl/URITransformer.java
+++ b/src/main/java/com/l2jserver/util/transformer/impl/URITransformer.java
@@ -17,7 +17,6 @@
package com.l2jserver.util.transformer.impl;
import java.net.URI;
-import java.net.URISyntaxException;
import com.l2jserver.util.transformer.Transformer;
@@ -36,11 +35,6 @@ public class URITransformer implements Transformer {
@Override
public URI untransform(String value) {
- try {
- return new URI(value);
- } catch (URISyntaxException e) {
- return null;
- }
+ return URI.create(value);
}
-
}
diff --git a/src/main/java/com/l2jserver/util/vfs/ExtensionFileSelector.java b/src/main/java/com/l2jserver/util/vfs/ExtensionFileSelector.java
deleted file mode 100644
index ad6122908..000000000
--- a/src/main/java/com/l2jserver/util/vfs/ExtensionFileSelector.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-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 FILES that has an given extension.
- *
- * @author Rogiel
- */
-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);
- }
-}
diff --git a/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java b/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java
index cc615ad85..4e2128641 100644
--- a/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java
+++ b/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java
@@ -78,6 +78,7 @@ import com.l2jserver.util.geometry.Coordinate;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+@SuppressWarnings("restriction")
public class NPCTemplateConverter {
private static final String JDBC_URL = "jdbc:mysql://localhost/l2jlegacy";
private static final String JDBC_USERNAME = "l2j";
diff --git a/src/tool/java/com/l2jserver/model/template/SkillTemplateConverter.java b/src/tool/java/com/l2jserver/model/template/SkillTemplateConverter.java
index a0806e165..33fdb6070 100644
--- a/src/tool/java/com/l2jserver/model/template/SkillTemplateConverter.java
+++ b/src/tool/java/com/l2jserver/model/template/SkillTemplateConverter.java
@@ -47,6 +47,7 @@ import com.l2jserver.util.factory.CollectionFactory;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+@SuppressWarnings("restriction")
public class SkillTemplateConverter {
private static final String JDBC_URL = "jdbc:mysql://localhost/l2jlegacy";
private static final String JDBC_USERNAME = "l2j";