1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +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

@@ -1,4 +1,4 @@
jdbc.mysql.url = jdbc:mysql://localhost/l2jserver2 jdbc.mysql.url = jdbc:mysql://localhost/l2jserver2
jdbc.mysql.driver = com.mysql.jdbc.Driver jdbc.mysql.driver = com.mysql.jdbc.Driver
jdbc.mysql.username = l2j123 jdbc.mysql.username = l2j
jdbc.mysql.password = changeme jdbc.mysql.password = changeme

View File

@@ -1,24 +0,0 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!--
~ 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 <http://www.gnu.org/licenses/>.
-->
<scriptlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../contexts.xsd">
<scriptinfo root="./target/templates"/>
<compiler>com.l2jserver.service.game.scripting.impl.compiled.PrecompiledScriptCompiler</compiler>
</scriptlist>

View File

@@ -1 +1 @@
#template.descriptor = config/template-compiled.xml template.directory = data/templates

32
data/sample/skill.xml Normal file
View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<skill id="3" name="Power Strike" delay="3000" cooldown="720">
<stats overhit="true" type="PHYSICAL_DAMAGE" range="40">
<levels max="9">
<level level="1" mpConsume="9" runSpeed="spd" abnormal="1" power="30" magic="3" />
<level level="2" mpConsume="9" power="32" magic="4" />
<level level="3" mpConsume="10" power="35" magic="5" />
<level level="4" mpConsume="11" power="46" magic="8" />
<level level="5" mpConsume="12" power="61" magic="9" />
<level level="6" mpConsume="13" power="65" magic="10" />
<level level="7" mpConsume="16" power="71" magic="13" />
<level level="8" mpConsume="16" power="78" magic="14" />
<level level="9" mpConsume="17" power="84" magic="15" />
</levels>
<soulshot count="1" boost="2.0" />
<hit time="1080" />
<effects range="400">
<effect name="BUFF" duration="15" abnormalType="speed_up_special">
<add order="0x40" stat="RUN_SPEED" />
</effect>
</effects>
</stats>
<info nextAction="ATTACK" target="SINGLE">
<weapon>
<allowed type="SWORD" />
<allowed type="BIG_SWORD" />
<allowed type="BLUNT" />
<allowed type="BIG_BLUNT" />
</weapon>
<operate type="OP_ACTIVE" />
</info>
</skill>

105
pom.xml
View File

@@ -9,6 +9,7 @@
<inceptionYear>2011</inceptionYear> <inceptionYear>2011</inceptionYear>
<dependencies> <dependencies>
<!-- junit -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
@@ -16,12 +17,14 @@
<type>jar</type> <type>jar</type>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- netty -->
<dependency> <dependency>
<groupId>org.jboss.netty</groupId> <groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId> <artifactId>netty</artifactId>
<version>3.2.4.Final</version> <version>3.2.4.Final</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- google guice -->
<dependency> <dependency>
<groupId>com.google.inject</groupId> <groupId>com.google.inject</groupId>
<artifactId>guice</artifactId> <artifactId>guice</artifactId>
@@ -36,6 +39,14 @@
<type>jar</type> <type>jar</type>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>3.0</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<!-- logging -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
@@ -43,6 +54,14 @@
<type>jar</type> <type>jar</type>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<!-- database -->
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
@@ -50,6 +69,44 @@
<type>jar</type> <type>jar</type>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<!-- cache -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.4.2</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<!-- html parser/generator -->
<dependency>
<groupId>org.htmlparser</groupId>
<artifactId>htmlparser</artifactId>
<version>2.1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<!-- utils -->
<dependency>
<groupId>javolution</groupId>
<artifactId>javolution</artifactId>
<version>5.5.1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r09</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>javacc</groupId> <groupId>javacc</groupId>
<artifactId>javacc</artifactId> <artifactId>javacc</artifactId>
@@ -64,13 +121,6 @@
<type>jar</type> <type>jar</type>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>commons-pool</groupId> <groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId> <artifactId>commons-pool</artifactId>
@@ -92,47 +142,14 @@
<type>jar</type> <type>jar</type>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- vfs -->
<dependency> <dependency>
<groupId>net.sf.ehcache</groupId> <groupId>commons-vfs</groupId>
<artifactId>ehcache-core</artifactId> <artifactId>commons-vfs</artifactId>
<version>2.4.2</version> <version>20050307052300</version>
<type>jar</type> <type>jar</type>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>3.0</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javolution</groupId>
<artifactId>javolution</artifactId>
<version>5.5.1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.htmlparser</groupId>
<artifactId>htmlparser</artifactId>
<version>2.1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r09</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.2.0</version>
<scope>runtime</scope>
</dependency>
</dependencies> </dependencies>
<issueManagement> <issueManagement>

View File

@@ -15,8 +15,6 @@
<outputDirectory>/</outputDirectory> <outputDirectory>/</outputDirectory>
<includes> <includes>
<include>data/**</include> <include>data/**</include>
<include>README</include>
<include>LICENSE</include>
</includes> </includes>
</fileSet> </fileSet>
<fileSet> <fileSet>
@@ -35,6 +33,13 @@
</excludes> </excludes>
</fileSet> </fileSet>
</fileSets> </fileSets>
<!-- <files> -->
<!-- <file> -->
<!-- <outputDirectory>/data/</outputDirectory> -->
<!-- <destName>templates.zip</destName> -->
<!-- <source>*templates.zip</source> -->
<!-- </file> -->
<!-- </files> -->
<dependencySets> <dependencySets>
<dependencySet> <dependencySet>
<outputDirectory>/libs</outputDirectory> <outputDirectory>/libs</outputDirectory>

View File

@@ -16,8 +16,6 @@
<includes> <includes>
<include>data/**</include> <include>data/**</include>
<include>src/**</include> <include>src/**</include>
<include>README</include>
<include>LICENSE</include>
</includes> </includes>
</fileSet> </fileSet>
<fileSet> <fileSet>

View File

@@ -28,8 +28,6 @@ import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue; import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.eclipse.persistence.oxm.annotations.XmlCDATA;
import com.l2jserver.model.id.template.ItemTemplateID; import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.id.template.NPCTemplateID; import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.world.Actor.ActorSex; import com.l2jserver.model.world.Actor.ActorSex;
@@ -240,7 +238,6 @@ public class NPCTemplate extends ActorTemplate<NPC> {
@XmlAttribute(name = "id") @XmlAttribute(name = "id")
protected String id = null; protected String id = null;
@XmlValue @XmlValue
@XmlCDATA
protected String html = null; protected String html = null;
} }

View File

@@ -25,6 +25,8 @@ import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.configuration.ProxyConfigurationService; import com.l2jserver.service.configuration.ProxyConfigurationService;
import com.l2jserver.service.core.Log4JLoggingService; import com.l2jserver.service.core.Log4JLoggingService;
import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.core.vfs.VFSService;
import com.l2jserver.service.core.vfs.VFSServiceImpl;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.MySQLDatabaseService; import com.l2jserver.service.database.MySQLDatabaseService;
import com.l2jserver.service.game.character.CharacterService; import com.l2jserver.service.game.character.CharacterService;
@@ -63,6 +65,7 @@ public class ServiceModule extends AbstractModule {
bind(ServiceManager.class).in(Scopes.SINGLETON); bind(ServiceManager.class).in(Scopes.SINGLETON);
bind(LoggingService.class).to(Log4JLoggingService.class).in( bind(LoggingService.class).to(Log4JLoggingService.class).in(
Scopes.SINGLETON); Scopes.SINGLETON);
bind(VFSService.class).to(VFSServiceImpl.class).in(Scopes.SINGLETON);
bind(ConfigurationService.class).to(ProxyConfigurationService.class) bind(ConfigurationService.class).to(ProxyConfigurationService.class)
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
bind(CacheService.class).to(EhCacheService.class).in(Scopes.SINGLETON); bind(CacheService.class).to(EhCacheService.class).in(Scopes.SINGLETON);

View File

@@ -0,0 +1,55 @@
/*
* 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.service.core.vfs;
import java.net.URI;
import org.apache.commons.vfs.FileObject;
import com.l2jserver.service.Service;
/**
* The VFS service provides access to files. With this service is possible to
* change the location of files.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface VFSService extends Service {
/**
* Resolves an file. If the file cannot be resolved, null will be returned.
* <p>
* 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.
* <p>
* Please note that event if the file DOES NOT exists a valid object will be
* returned.
*
* @param uri
* the file uri as an string
* @return the resolved file. Will return null if could not resolve.
*/
FileObject resolve(String uri);
}

View File

@@ -0,0 +1,79 @@
/*
* 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.service.core.vfs;
import java.io.File;
import java.net.URI;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.impl.StandardFileSystemManager;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
/**
* Default implementation for VFS system
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class VFSServiceImpl extends AbstractService implements VFSService {
/**
* The CommonsVFS {@link FileSystemManager}
*/
private DefaultFileSystemManager manager;
@Override
protected void doStart() throws ServiceStartException {
manager = new StandardFileSystemManager();
try {
manager.init();
manager.setBaseFile(new File("./"));
} catch (FileSystemException e) {
manager = null;
throw new ServiceStartException(e);
}
}
@Override
public FileObject resolve(URI uri) {
return resolve(uri.toString());
}
@Override
public FileObject resolve(String uri) {
try {
return manager.resolveFile(uri);
} catch (FileSystemException e) {
return null;
}
}
@Override
protected void doStop() throws ServiceStopException {
try {
manager.getBaseFile().close();
} catch (FileSystemException e) {
throw new ServiceStopException(e);
} finally {
manager = null;
}
}
}

View File

@@ -16,8 +16,8 @@
*/ */
package com.l2jserver.service.game.template; package com.l2jserver.service.game.template;
import java.io.File; import java.io.IOException;
import java.util.Collection; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -30,7 +30,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import org.apache.commons.io.FileUtils; import org.apache.commons.vfs.FileObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -48,17 +48,21 @@ import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.core.vfs.VFSService;
import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter; import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter; import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
import com.l2jserver.util.jaxb.NPCTemplateIDAdapter; import com.l2jserver.util.jaxb.NPCTemplateIDAdapter;
import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter; import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
import com.l2jserver.util.vfs.ExtensionFileSelector;
@Depends({ LoggingService.class, ConfigurationService.class }) @Depends({ LoggingService.class, VFSService.class, ConfigurationService.class })
public class XMLTemplateService extends AbstractService implements public class XMLTemplateService extends AbstractService implements
TemplateService { TemplateService {
private final Logger log = LoggerFactory.getLogger(this.getClass()); private final Logger log = LoggerFactory.getLogger(this.getClass());
private final VFSService vfsService;
private final XMLTemplateServiceConfiguration config; private final XMLTemplateServiceConfiguration config;
private final NPCTemplateIDAdapter npcTemplateIdAdapter; private final NPCTemplateIDAdapter npcTemplateIdAdapter;
private final ItemTemplateIDAdapter itemTemplateIdAdapter; private final ItemTemplateIDAdapter itemTemplateIdAdapter;
@@ -72,11 +76,13 @@ public class XMLTemplateService extends AbstractService implements
private Map<TemplateID, Template> templates = CollectionFactory.newMap(); private Map<TemplateID, Template> templates = CollectionFactory.newMap();
@Inject @Inject
public XMLTemplateService(ConfigurationService configService, public XMLTemplateService(final VFSService vfsService,
ConfigurationService configService,
NPCTemplateIDAdapter npcTemplateIdAdapter, NPCTemplateIDAdapter npcTemplateIdAdapter,
ItemTemplateIDAdapter itemTemplateIdAdapter, ItemTemplateIDAdapter itemTemplateIdAdapter,
CharacterTemplateIDAdapter charIdTemplateAdapter, CharacterTemplateIDAdapter charIdTemplateAdapter,
TeleportationTemplateIDAdapter teleportationIdTemplateAdapter) { TeleportationTemplateIDAdapter teleportationIdTemplateAdapter) {
this.vfsService = vfsService;
this.config = configService.get(XMLTemplateServiceConfiguration.class); this.config = configService.get(XMLTemplateServiceConfiguration.class);
this.npcTemplateIdAdapter = npcTemplateIdAdapter; this.npcTemplateIdAdapter = npcTemplateIdAdapter;
this.itemTemplateIdAdapter = itemTemplateIdAdapter; this.itemTemplateIdAdapter = itemTemplateIdAdapter;
@@ -104,24 +110,33 @@ public class XMLTemplateService extends AbstractService implements
unmarshaller.setAdapter(TeleportationTemplateIDAdapter.class, unmarshaller.setAdapter(TeleportationTemplateIDAdapter.class,
teleportationIdTemplateAdapter); teleportationIdTemplateAdapter);
@SuppressWarnings("unchecked") final FileObject root = vfsService.resolve(config
Collection<File> files = FileUtils .getTemplateDirectory());
.listFiles(config.getTemplateDirectory(),
new String[] { "xml" }, true); log.info("Scanning {} for XML templates", root);
log.debug("Located {} XML template files", files.size());
for (final File file : files) { FileObject[] files = root.findFiles(ExtensionFileSelector
log.debug("Loading template {}", file); .ext("xml"));
log.info("Located {} XML template files", files.length);
for (final FileObject file : files) {
loadTemplate(file); loadTemplate(file);
} }
final FileObject teleportsXml = root.getParent().resolveFile(
"teleports.xml");
final InputStream in = teleportsXml.getContent().getInputStream();
try {
TeleportationTemplateContainer container = (TeleportationTemplateContainer) unmarshaller TeleportationTemplateContainer container = (TeleportationTemplateContainer) unmarshaller
.unmarshal(new File(config.getTemplateDirectory(), .unmarshal(in);
"../teleports.xml"));
for (final TeleportationTemplate template : container.templates) { for (final TeleportationTemplate template : container.templates) {
templates.put(template.getID(), template); templates.put(template.getID(), template);
} }
} finally {
in.close();
}
} catch (JAXBException e) { } catch (JAXBException e) {
e.printStackTrace(); throw new ServiceStartException(e);
System.exit(0); } catch (IOException e) {
throw new ServiceStartException(e); throw new ServiceStartException(e);
} }
} }
@@ -133,11 +148,18 @@ public class XMLTemplateService extends AbstractService implements
return (T) templates.get(id); return (T) templates.get(id);
} }
public void loadTemplate(File file) throws JAXBException { public void loadTemplate(FileObject file) throws JAXBException, IOException {
Preconditions.checkNotNull(file, "file"); Preconditions.checkNotNull(file, "file");
final Template<?> template = (Template<?>) unmarshaller.unmarshal(file); log.debug("Loading template {}", file);
final InputStream in = file.getContent().getInputStream();
try {
final Template<?> template = (Template<?>) unmarshaller
.unmarshal(in);
if (template.getID() != null) if (template.getID() != null)
templates.put(template.getID(), template); templates.put(template.getID(), template);
} finally {
in.close();
}
} }
public void removeTemplate(Template<?> template) { public void removeTemplate(Template<?> template) {

View File

@@ -16,16 +16,16 @@
*/ */
package com.l2jserver.service.game.template; package com.l2jserver.service.game.template;
import java.io.File; import java.net.URI;
import com.l2jserver.service.configuration.Configuration; import com.l2jserver.service.configuration.Configuration;
import com.l2jserver.service.configuration.Configuration.ConfigurationName; import com.l2jserver.service.configuration.Configuration.ConfigurationName;
@ConfigurationName("template") @ConfigurationName("template")
public interface XMLTemplateServiceConfiguration extends Configuration { public interface XMLTemplateServiceConfiguration extends Configuration {
@ConfigurationPropertyGetter(name = "template.directory", defaultValue = "data/templates") @ConfigurationPropertyGetter(name = "template.directory", defaultValue = "zip:data/templates.zip")
File getTemplateDirectory(); URI getTemplateDirectory();
@ConfigurationPropertySetter(name = "template.directory") @ConfigurationPropertySetter(name = "template.directory")
void setTemplateDirectory(File file); void setTemplateDirectory(URI file);
} }

View File

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