diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-12 17:54:00 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-12 17:54:00 +1200 |
commit | a2dac324574dde8fe8e57bd46dd7f94d0fb60231 (patch) | |
tree | 061e957cb53e00214a33acb6317be9c0849c50fa | |
parent | f1ae2d73584d4ddded6f727c665d97f03ecf9c25 (diff) | |
download | trackermap-server-a2dac324574dde8fe8e57bd46dd7f94d0fb60231.tar.gz trackermap-server-a2dac324574dde8fe8e57bd46dd7f94d0fb60231.tar.bz2 trackermap-server-a2dac324574dde8fe8e57bd46dd7f94d0fb60231.zip |
Re-factor configuration access
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 34 | ||||
-rw-r--r-- | src/org/traccar/Config.java | 74 | ||||
-rw-r--r-- | src/org/traccar/Context.java | 47 | ||||
-rw-r--r-- | src/org/traccar/FilterHandler.java | 22 | ||||
-rw-r--r-- | src/org/traccar/ServerManager.java | 2 | ||||
-rw-r--r-- | src/org/traccar/TrackerServer.java | 5 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 60 | ||||
-rw-r--r-- | src/org/traccar/helper/Log.java | 8 | ||||
-rw-r--r-- | src/org/traccar/http/WebServer.java | 23 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gl200ProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/GlobalSatProtocolDecoder.java | 22 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 16 | ||||
-rw-r--r-- | src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 14 | ||||
-rw-r--r-- | src/org/traccar/protocol/Mta6Protocol.java | 5 | ||||
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 5 | ||||
-rw-r--r-- | src/org/traccar/protocol/XexunProtocol.java | 5 |
16 files changed, 179 insertions, 165 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 689b63ab6..478038317 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -35,9 +35,11 @@ import org.traccar.helper.Log; public abstract class BasePipelineFactory implements ChannelPipelineFactory { private final TrackerServer server; - private FilterHandler filterHandler; - private Integer resetDelay; + private int resetDelay; private Boolean processInvalidPositions; + + private FilterHandler filterHandler; + private ReverseGeocoderHandler reverseGeocoderHandler; protected class OpenChannelHandler extends SimpleChannelHandler { @@ -87,21 +89,17 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { public BasePipelineFactory(TrackerServer server, String protocol) { this.server = server; + + resetDelay = Context.getConfig().getInteger(protocol + ".resetDelay", 0); + processInvalidPositions = Context.getConfig().getBoolean("geocode.processInvalidPositions"); - String resetDelayProperty = Context.getProps().getProperty(protocol + ".resetDelay"); - if (resetDelayProperty != null) { - resetDelay = Integer.valueOf(resetDelayProperty); - } - - String enableFilter = Context.getProps().getProperty("filter.enable"); - if (enableFilter != null && Boolean.valueOf(enableFilter)) { + if (Context.getConfig().getBoolean("filter.enable")) { filterHandler = new FilterHandler(); } - + if (Context.getReverseGeocoder() != null) { - // Default behavior is to process invalid positions (i.e., the "null" case) - String invalidPositions = Context.getProps().getProperty("geocode.processInvalidPositions"); - processInvalidPositions = (invalidPositions == null || Boolean.valueOf(invalidPositions)); + reverseGeocoderHandler = new ReverseGeocoderHandler( + Context.getReverseGeocoder(), Context.getConfig().getBoolean("geocode.processInvalidPositions")); } } @@ -110,7 +108,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { @Override public ChannelPipeline getPipeline() { ChannelPipeline pipeline = Channels.pipeline(); - if (resetDelay != null) { + if (resetDelay != 0) { pipeline.addLast("idleHandler", new IdleStateHandler(GlobalTimer.getTimer(), resetDelay, 0, 0)); } pipeline.addLast("openHandler", new OpenChannelHandler(server)); @@ -121,15 +119,15 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { if (filterHandler != null) { pipeline.addLast("filter", filterHandler); } - if (Context.getReverseGeocoder() != null) { - pipeline.addLast("geocoder", new ReverseGeocoderHandler(Context.getReverseGeocoder(), processInvalidPositions)); + if (reverseGeocoderHandler != null) { + pipeline.addLast("geocoder", reverseGeocoderHandler); } pipeline.addLast("remoteAddress", new RemoteAddressHandler()); if (Context.getDataManager() != null) { pipeline.addLast("dataHandler", new DefaultDataHandler()); } - if (Boolean.valueOf(Context.getProps().getProperty("forward.enable"))) { - pipeline.addLast("webHandler", new WebDataHandler(Context.getProps().getProperty("forward.url"))); + if (Context.getConfig().getBoolean("forward.enable")) { + pipeline.addLast("webHandler", new WebDataHandler(Context.getConfig().getString("forward.url"))); } pipeline.addLast("mainHandler", new MainEventHandler()); return pipeline; diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java new file mode 100644 index 000000000..90f064601 --- /dev/null +++ b/src/org/traccar/Config.java @@ -0,0 +1,74 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +public class Config { + + private final Properties properties = new Properties(); + + public void load(String file) throws IOException { + properties.loadFromXML(new FileInputStream(file)); + } + + public boolean hasKey(String key) { + return properties.containsKey(key); + } + + public boolean getBoolean(String key) { + return Boolean.valueOf(properties.getProperty(key)); + } + + public int getInteger(String key) { + return getInteger(key, 0); + } + + public int getInteger(String key, int defaultValue) { + if (properties.containsKey(key)) { + return Integer.valueOf(properties.getProperty(key)); + } else { + return defaultValue; + } + } + + public long getLong(String key) { + return getLong(key, 0); + } + + public long getLong(String key, long defaultValue) { + if (properties.containsKey(key)) { + return Long.valueOf(properties.getProperty(key)); + } else { + return defaultValue; + } + } + + public String getString(String key) { + return properties.getProperty(key); + } + + public String getString(String key, String defaultValue) { + if (properties.containsKey(key)) { + return properties.getProperty(key); + } else { + return defaultValue; + } + } + +} diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index 6fb812f4f..0b74eacd0 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -15,8 +15,6 @@ */ package org.traccar; -import java.io.FileInputStream; -import java.util.Properties; import org.traccar.database.ConnectionManager; import org.traccar.database.DataManager; import org.traccar.database.IdentityManager; @@ -29,24 +27,12 @@ import org.traccar.helper.Log; import org.traccar.http.WebServer; public class Context { - - private static Properties properties; - - public static Properties getProps() { - return properties; - } - /*public static boolean getPropBoolean(String key) { - return Boolean.valueOf(properties.getProperty(key)); - } + private static Config config; - public static int getPropInt() { - return Integer.valueOf(null); + public static Config getConfig() { + return config; } - - public static String getPropString() { - return null; - }*/ private static boolean loggerEnabled; @@ -98,37 +84,38 @@ public class Context { public static void init(String[] arguments) throws Exception { - properties = new Properties(); + config = new Config(); if (arguments.length > 0) { - properties.loadFromXML(new FileInputStream(arguments[0])); + config.load(arguments[0]); } - loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable")); + loggerEnabled = config.getBoolean("logger.enable"); if (loggerEnabled) { - Log.setupLogger(properties); + Log.setupLogger(config); } - dataManager = new DataManager(properties); + dataManager = new DataManager(config); identityManager = dataManager; connectionManager = new ConnectionManager(); - if (!Boolean.valueOf(properties.getProperty("web.old"))) { + if (!config.getBoolean("web.old")) { permissionsManager = new PermissionsManager(); } - if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) { - String type = properties.getProperty("geocoder.type"); + if (config.getBoolean("geocoder.enable")) { + String type = config.getString("geocoder.type"); + String url = config.getString("geocoder.url"); if (type != null && type.equals("nominatim")) { - reverseGeocoder = new NominatimReverseGeocoder(properties.getProperty("geocoder.url")); + reverseGeocoder = new NominatimReverseGeocoder(url); } else if (type != null && type.equals("gisgraphy")) { - reverseGeocoder = new GisgraphyReverseGeocoder(properties.getProperty("geocoder.url")); + reverseGeocoder = new GisgraphyReverseGeocoder(url); } else { reverseGeocoder = new GoogleReverseGeocoder(); } } - if (Boolean.valueOf(properties.getProperty("web.enable"))) { - webServer = new WebServer(); + if (config.getBoolean("web.enable")) { + webServer = new WebServer(config); } serverManager = new ServerManager(); @@ -141,7 +128,7 @@ public class Context { * Initialize context for unit testing */ public static void init(IdentityManager identityManager) { - properties = new Properties(); + config = new Config(); connectionManager = new ConnectionManager(); Context.identityManager = identityManager; } diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index a5be11463..a04789a28 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -15,7 +15,6 @@ */ package org.traccar; -import java.util.Properties; import org.traccar.helper.DistanceCalculator; import org.traccar.helper.Log; import org.traccar.model.Position; @@ -43,22 +42,13 @@ public class FilterHandler extends BaseDataHandler { } public FilterHandler() { - Properties properties = Context.getProps(); + Config config = Context.getConfig(); - String value = properties.getProperty("filter.invalid"); - if (value != null) filterInvalid = Boolean.valueOf(value); - - value = properties.getProperty("filter.zero"); - if (value != null) filterZero = Boolean.valueOf(value); - - value = properties.getProperty("filter.duplicate"); - if (value != null) filterDuplicate = Boolean.valueOf(value); - - value = properties.getProperty("filter.distance"); - if (value != null) filterDistance = Integer.valueOf(value); - - value = properties.getProperty("filter.limit"); - if (value != null) filterLimit = Long.valueOf(value) * 1000; + filterInvalid = config.getBoolean("filter.invalid"); + filterZero = config.getBoolean("filter.zero"); + filterDuplicate = config.getBoolean("filter.duplicate"); + filterDistance = config.getInteger("filter.distance"); + filterLimit = config.getLong("filter.limit") * 1000; } private Position getLastPosition(long deviceId) { diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index de167b9d2..04a3fc317 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -87,7 +87,7 @@ public class ServerManager { } private boolean isProtocolEnabled(String protocol) { - return Context.getProps().containsKey(protocol + ".port"); + return Context.getConfig().hasKey(protocol + ".port"); } private void initProtocolDetector() throws SQLException { diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index 6796f2064..596d6097a 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -51,9 +51,8 @@ public abstract class TrackerServer { bootstrap.setFactory(GlobalChannelFactory.getDatagramFactory()); } - address = Context.getProps().getProperty(protocol + ".address"); - String portProperty = Context.getProps().getProperty(protocol + ".port"); - port = Integer.valueOf(portProperty); + address = Context.getConfig().getString(protocol + ".address"); + port = Context.getConfig().getInteger(protocol + ".port"); bootstrap.setPipelineFactory(new BasePipelineFactory(this, protocol) { @Override diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index c1b769447..959602512 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -29,10 +29,9 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import javax.naming.InitialContext; import javax.sql.DataSource; -import org.traccar.Context; +import org.traccar.Config; import org.traccar.helper.DriverDelegate; import org.traccar.helper.Log; import org.traccar.http.AsyncServlet; @@ -47,37 +46,30 @@ public class DataManager implements IdentityManager { private static final long DEFAULT_REFRESH_DELAY = 300; - private final Properties properties; + private final Config config; private DataSource dataSource; private final Map<String, Device> devices = new HashMap<String, Device>(); private long devicesLastUpdate; - private long devicesRefreshDelay; - - public DataManager(Properties properties) throws Exception { - this.properties = properties; - if (properties != null) { - initDatabase(properties); - initDatabaseSchema(); - - // Refresh delay - String refreshDelay = properties.getProperty("database.refreshDelay"); - if (refreshDelay != null) { - devicesRefreshDelay = Long.valueOf(refreshDelay) * 1000; - } else { - devicesRefreshDelay = DEFAULT_REFRESH_DELAY * 1000; - } - } + private final long devicesRefreshDelay; + + public DataManager(Config config) throws Exception { + this.config = config; + + initDatabase(); + initDatabaseSchema(); + + devicesRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000; } public DataSource getDataSource() { return dataSource; } - private void initDatabase(Properties properties) throws Exception { + private void initDatabase() throws Exception { - String jndiName = properties.getProperty("database.jndi"); + String jndiName = config.getString("database.jndi"); if (jndiName != null) { @@ -86,9 +78,9 @@ public class DataManager implements IdentityManager { } else { // Load driver - String driver = properties.getProperty("database.driver"); + String driver = config.getString("database.driver"); if (driver != null) { - String driverFile = properties.getProperty("database.driverFile"); + String driverFile = config.getString("database.driverFile"); if (driverFile != null) { URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/"); @@ -102,15 +94,15 @@ public class DataManager implements IdentityManager { // Initialize data source ComboPooledDataSource ds = new ComboPooledDataSource(); - ds.setDriverClass(properties.getProperty("database.driver")); - ds.setJdbcUrl(properties.getProperty("database.url")); - ds.setUser(properties.getProperty("database.user")); - ds.setPassword(properties.getProperty("database.password")); + ds.setDriverClass(config.getString("database.driver")); + ds.setJdbcUrl(config.getString("database.url")); + ds.setUser(config.getString("database.user")); + ds.setPassword(config.getString("database.password")); ds.setIdleConnectionTestPeriod(600); ds.setTestConnectionOnCheckin(true); - String maxPoolSize = properties.getProperty("database.maxPoolSize"); - if (maxPoolSize != null) { - ds.setMaxPoolSize(Integer.valueOf(maxPoolSize)); + int maxPoolSize = config.getInteger("database.maxPoolSize"); + if (maxPoolSize != 0) { + ds.setMaxPoolSize(maxPoolSize); } dataSource = ds; } @@ -132,7 +124,7 @@ public class DataManager implements IdentityManager { } private String getQuery(String key) { - String query = properties.getProperty(key); + String query = config.getString(key); if (query == null) { Log.info("Query not provided: " + key); } @@ -141,14 +133,14 @@ public class DataManager implements IdentityManager { private void initDatabaseSchema() throws SQLException { - if (!Boolean.valueOf(properties.getProperty("web.old"))) { + if (!config.getBoolean("web.old")) { Connection connection = dataSource.getConnection(); ResultSet result = connection.getMetaData().getTables( connection.getCatalog(), null, null, null); boolean exist = false; - String checkTable = properties.getProperty("database.checkTable"); + String checkTable = config.getString("database.checkTable"); while (result.next()) { if (result.getString("TABLE_NAME").equalsIgnoreCase(checkTable)) { exist = true; @@ -179,7 +171,7 @@ public class DataManager implements IdentityManager { } private void mockData(long userId) { - if (Boolean.valueOf(Context.getProps().getProperty("database.mock"))) { + if (config.getBoolean("database.mock")) { try { Device device = new Device(); diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java index 6ae46163b..e4b0168a9 100644 --- a/src/org/traccar/helper/Log.java +++ b/src/org/traccar/helper/Log.java @@ -20,7 +20,6 @@ import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.OperatingSystemMXBean; import java.lang.management.RuntimeMXBean; -import java.util.Properties; import org.apache.log4j.Appender; import org.apache.log4j.DailyRollingFileAppender; import org.apache.log4j.Layout; @@ -32,6 +31,7 @@ import org.apache.log4j.varia.NullAppender; import org.jboss.netty.logging.AbstractInternalLogger; import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.logging.InternalLoggerFactory; +import org.traccar.Config; public class Log { @@ -42,19 +42,19 @@ public class Log { private static Logger logger = null; - public static void setupLogger(Properties properties) throws IOException { + public static void setupLogger(Config config) throws IOException { Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %5p: %m%n"); Appender appender = new DailyRollingFileAppender( - layout, properties.getProperty("logger.file"), "'.'yyyyMMdd"); + layout, config.getString("logger.file"), "'.'yyyyMMdd"); LogManager.resetConfiguration(); LogManager.getRootLogger().addAppender(new NullAppender()); logger = Logger.getLogger(LOGGER_NAME); logger.addAppender(appender); - logger.setLevel(Level.toLevel(properties.getProperty("logger.level"), Level.ALL)); + logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL)); // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem" InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() { diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 21a7ba775..a9238964c 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -16,7 +16,6 @@ package org.traccar.http; import java.net.InetSocketAddress; -import java.util.Properties; import javax.naming.InitialContext; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; @@ -25,6 +24,7 @@ import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.webapp.WebAppContext; +import org.traccar.Config; import org.traccar.Context; import org.traccar.helper.Log; @@ -35,18 +35,17 @@ public class WebServer { private Server server; - public WebServer() { - Properties properties = Context.getProps(); - - String address = properties.getProperty("web.address"); - Integer port = Integer.valueOf(properties.getProperty("web.port", "8082")); + public WebServer(Config config) { + + String address = config.getString("web.address"); + int port = config.getInteger("web.port", 8082); if (address == null) { server = new Server(port); } else { server = new Server(new InetSocketAddress(address, port)); } - if (!Boolean.valueOf(properties.getProperty("web.old"))) { + if (!config.getBoolean("web.old")) { ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletHandler.setContextPath("/api"); @@ -65,11 +64,11 @@ public class WebServer { mobileContext.setHandler(mobileResourceHandler);*/ ResourceHandler resourceHandler = new ResourceHandler(); - resourceHandler.setResourceBase(properties.getProperty("web.path")); - if (Boolean.valueOf(properties.getProperty("web.debug"))) { - resourceHandler.setWelcomeFiles(new String[]{"debug.html"}); + resourceHandler.setResourceBase(config.getString("web.path")); + if (config.getBoolean("web.debug")) { + resourceHandler.setWelcomeFiles(new String[] { "debug.html" }); } else { - resourceHandler.setWelcomeFiles(new String[]{"release.html"}); + resourceHandler.setWelcomeFiles(new String[] { "release.html" }); } HandlerList handlerList = new HandlerList(); @@ -88,7 +87,7 @@ public class WebServer { WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); - webapp.setWar(properties.getProperty("web.application")); + webapp.setWar(config.getString("web.application")); server.setHandler(webapp); } diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index b71ace1a1..3628730e3 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -147,7 +147,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } position.set(Event.KEY_BATTERY, parser.group(index++)); - if (Boolean.valueOf(Context.getProps().getProperty(getProtocolName() + ".ack")) && channel != null) { + if (Context.getConfig().getBoolean(getProtocolName() + ".ack") && channel != null) { channel.write("+SACK:" + parser.group(index++) + "$", remoteAddress); } diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index c411b4c25..04b88114f 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java @@ -17,14 +17,10 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.util.Calendar; -import java.util.Properties; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; - import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.helper.UnitsConverter; @@ -33,22 +29,14 @@ import org.traccar.model.Position; public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { - // Default values - private String format0 = "TSPRXAB27GHKLMnaicz*U!"; - private String format1 = "SARY*U!"; + private String format0; + private String format1; public GlobalSatProtocolDecoder(GlobalSatProtocol protocol) { super(protocol); - - Properties properties = Context.getProps(); - if (properties != null) { - if (properties.containsKey(protocol + ".format0")) { - format0 = properties.getProperty(protocol + ".format0"); - } - if (properties.containsKey(protocol + ".format1")) { - format1 = properties.getProperty(protocol + ".format1"); - } - } + + format0 = Context.getConfig().getString(protocol + ".format0", "TSPRXAB27GHKLMnaicz*U!"); + format1 = Context.getConfig().getString(protocol + ".format1", "SARY*U!"); } public void setFormat0(String format) { diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 5e527dd9c..06c3985dc 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -15,10 +15,12 @@ */ package org.traccar.protocol; +import java.net.SocketAddress; +import java.util.Calendar; +import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.helper.Crc; @@ -26,11 +28,6 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Event; import org.traccar.model.Position; -import java.net.SocketAddress; -import java.util.Calendar; -import java.util.Properties; -import java.util.TimeZone; - public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private boolean forceTimeZone = false; @@ -38,11 +35,10 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public Gt06ProtocolDecoder(Gt06Protocol protocol) { super(protocol); - - Properties properties = Context.getProps(); - if (properties != null && properties.containsKey(protocol + ".timezone")) { + + if (Context.getConfig().hasKey(protocol + ".timezone")) { forceTimeZone = true; - timeZone.setRawOffset(Integer.valueOf(properties.getProperty(protocol + ".timezone")) * 1000); + timeZone.setRawOffset(Context.getConfig().getInteger(protocol + ".timezone") * 1000); } } diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index f0b3ee9e6..4df757d22 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -16,17 +16,15 @@ package org.traccar.protocol; import java.net.InetSocketAddress; -import java.nio.charset.Charset; import java.net.SocketAddress; +import java.nio.charset.Charset; import java.util.Calendar; -import java.util.Properties; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.helper.Crc; @@ -117,14 +115,12 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } private String getMeiligaoServer(Channel channel) { - Properties p = Context.getProps(); - - if (p != null && p.containsKey(getProtocolName() + ".server")) { - return p.getProperty(getProtocolName() + ".server"); - } else { + String server = Context.getConfig().getString(getProtocolName() + ".server"); + if (server == null) { InetSocketAddress address = (InetSocketAddress) channel.getLocalAddress(); - return address.getAddress().getHostAddress() + ":" + address.getPort(); + server = address.getAddress().getHostAddress() + ":" + address.getPort(); } + return server; } @Override diff --git a/src/org/traccar/protocol/Mta6Protocol.java b/src/org/traccar/protocol/Mta6Protocol.java index 7d4ea68f7..8232b850c 100644 --- a/src/org/traccar/protocol/Mta6Protocol.java +++ b/src/org/traccar/protocol/Mta6Protocol.java @@ -15,6 +15,7 @@ */ package org.traccar.protocol; +import java.util.List; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.handler.codec.http.HttpRequestDecoder; @@ -23,8 +24,6 @@ import org.traccar.BaseProtocol; import org.traccar.Context; import org.traccar.TrackerServer; -import java.util.List; - public class Mta6Protocol extends BaseProtocol { public Mta6Protocol() { @@ -39,7 +38,7 @@ public class Mta6Protocol extends BaseProtocol { pipeline.addLast("httpDecoder", new HttpRequestDecoder()); pipeline.addLast("httpEncoder", new HttpResponseEncoder()); pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder( - Mta6Protocol.this, !Boolean.valueOf(Context.getProps().getProperty(getName() + ".can")))); + Mta6Protocol.this, !Context.getConfig().getBoolean(getName() + ".can"))); } }); } diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 1b34f3f81..e884f4be2 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -20,10 +20,7 @@ import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; - import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.helper.UnitsConverter; @@ -123,7 +120,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(longitude); // Speed - if (Boolean.valueOf(Context.getProps().getProperty(getProtocolName() + ".mph"))) { + if (Context.getConfig().getBoolean(getProtocolName() + ".mph")) { position.setSpeed(UnitsConverter.knotsFromMph(Double.valueOf(parser.group(index++)))); } else { position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++)))); diff --git a/src/org/traccar/protocol/XexunProtocol.java b/src/org/traccar/protocol/XexunProtocol.java index 52d022b05..ea3ed8c10 100644 --- a/src/org/traccar/protocol/XexunProtocol.java +++ b/src/org/traccar/protocol/XexunProtocol.java @@ -15,6 +15,7 @@ */ package org.traccar.protocol; +import java.util.List; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; @@ -23,8 +24,6 @@ import org.traccar.BaseProtocol; import org.traccar.Context; import org.traccar.TrackerServer; -import java.util.List; - public class XexunProtocol extends BaseProtocol { public XexunProtocol() { @@ -36,7 +35,7 @@ public class XexunProtocol extends BaseProtocol { serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { - boolean full = Boolean.valueOf(Context.getProps().getProperty(getName() + ".extended")); + boolean full = Context.getConfig().getBoolean(getName() + ".extended"); if (full) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); // tracker bug \n\r } else { |