diff options
Diffstat (limited to 'src/org/traccar/web')
-rw-r--r-- | src/org/traccar/web/ConsoleServlet.java | 10 | ||||
-rw-r--r-- | src/org/traccar/web/CsvBuilder.java | 16 | ||||
-rw-r--r-- | src/org/traccar/web/GpxBuilder.java | 73 | ||||
-rw-r--r-- | src/org/traccar/web/JsonConverter.java | 2 | ||||
-rw-r--r-- | src/org/traccar/web/WebServer.java | 38 |
5 files changed, 104 insertions, 35 deletions
diff --git a/src/org/traccar/web/ConsoleServlet.java b/src/org/traccar/web/ConsoleServlet.java index b219eaba4..9b3d8d54b 100644 --- a/src/org/traccar/web/ConsoleServlet.java +++ b/src/org/traccar/web/ConsoleServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,10 +40,16 @@ public class ConsoleServlet extends WebServlet { + Context.getConfig().getString("database.url") + "|" + Context.getConfig().getString("database.user")); - Method method = org.h2.server.web.WebServer.class.getDeclaredMethod("updateSetting", ConnectionInfo.class); + Method method; + + method = org.h2.server.web.WebServer.class.getDeclaredMethod("updateSetting", ConnectionInfo.class); method.setAccessible(true); method.invoke(server, connectionInfo); + method = org.h2.server.web.WebServer.class.getDeclaredMethod("setAllowOthers", boolean.class); + method.setAccessible(true); + method.invoke(server, true); + } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { Log.warning(e); } diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java index f59aabc7f..532f06e3d 100644 --- a/src/org/traccar/web/CsvBuilder.java +++ b/src/org/traccar/web/CsvBuilder.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org) + * + * 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.web; import java.beans.Introspector; diff --git a/src/org/traccar/web/GpxBuilder.java b/src/org/traccar/web/GpxBuilder.java new file mode 100644 index 000000000..bac7182dc --- /dev/null +++ b/src/org/traccar/web/GpxBuilder.java @@ -0,0 +1,73 @@ +/* + * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org) + * + * 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.web; + +import java.util.Collection; + +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +public class GpxBuilder { + + private StringBuilder builder = new StringBuilder(); + private static final String HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>" + + "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"Traccar\" version=\"1.1\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 " + + "http://www.topografix.com/GPX/1/1/gpx.xsd\"><trk>\n"; + private static final String NAME = "<name>%1$s</name><trkseg>%n"; + private static final String POINT = "<trkpt lat=\"%1$f\" lon=\"%2$f\">" + + "<time>%3$s</time>" + + "<geoidheight>%4$f</geoidheight>" + + "<course>%5$f</course>" + + "<speed>%6$f</speed>" + + "</trkpt>%n"; + private static final String FOOTER = "</trkseg></trk></gpx>"; + + private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime(); + + public GpxBuilder() { + builder.append(HEADER); + builder.append("<trkseg>\n"); + } + + public GpxBuilder(String name) { + builder.append(HEADER); + builder.append(String.format(NAME, name)); + } + + public void addPosition(Position position) { + builder.append(String.format(POINT, position.getLatitude(), position.getLongitude(), + DATE_FORMAT.print(new DateTime(position.getFixTime())), position.getAltitude(), + position.getCourse(), UnitsConverter.mpsFromKnots(position.getSpeed()))); + } + + public void addPositions(Collection<Position> positions) { + for (Position position : positions) { + addPosition(position); + } + } + + public String build() { + builder.append(FOOTER); + return builder.toString(); + } + +} diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java index 19ac6f777..bec0afe8e 100644 --- a/src/org/traccar/web/JsonConverter.java +++ b/src/org/traccar/web/JsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index ec15ea2be..8201f8d16 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,24 +34,7 @@ import org.traccar.api.CorsResponseFilter; import org.traccar.api.ObjectMapperProvider; import org.traccar.api.ResourceErrorHandler; import org.traccar.api.SecurityRequestFilter; -import org.traccar.api.resource.AttributeAliasResource; -import org.traccar.api.resource.CommandResource; -import org.traccar.api.resource.GroupPermissionResource; import org.traccar.api.resource.ServerResource; -import org.traccar.api.resource.SessionResource; -import org.traccar.api.resource.DevicePermissionResource; -import org.traccar.api.resource.UserResource; -import org.traccar.api.resource.GroupResource; -import org.traccar.api.resource.NotificationResource; -import org.traccar.api.resource.DeviceResource; -import org.traccar.api.resource.PositionResource; -import org.traccar.api.resource.ReportResource; -import org.traccar.api.resource.CommandTypeResource; -import org.traccar.api.resource.DeviceGeofenceResource; -import org.traccar.api.resource.EventResource; -import org.traccar.api.resource.GeofencePermissionResource; -import org.traccar.api.resource.GeofenceResource; -import org.traccar.api.resource.GroupGeofenceResource; import org.traccar.helper.Log; import javax.naming.InitialContext; @@ -120,9 +103,7 @@ public class WebServer { resourceHandler.setResourceBase(config.getString("web.path")); if (config.getBoolean("web.debug")) { resourceHandler.setWelcomeFiles(new String[] {"debug.html"}); - //Troubleshooting Locked UI Files on Windows while app is running (like html, js, css, etc...), - //you can make changes to the UI Files and refresh the page in the browser without stopping the app first - resourceHandler.setMinMemoryMappedContentLength(-1); + resourceHandler.setMinMemoryMappedContentLength(-1); // avoid locking files on Windows } else { resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"}); } @@ -152,17 +133,10 @@ public class WebServer { servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket"); ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig.register(ObjectMapperProvider.class); - resourceConfig.register(JacksonFeature.class); - resourceConfig.register(ResourceErrorHandler.class); - resourceConfig.register(SecurityRequestFilter.class); - resourceConfig.register(CorsResponseFilter.class); - resourceConfig.registerClasses(ServerResource.class, SessionResource.class, CommandResource.class, - GroupPermissionResource.class, DevicePermissionResource.class, UserResource.class, - GroupResource.class, DeviceResource.class, PositionResource.class, - CommandTypeResource.class, EventResource.class, GeofenceResource.class, - DeviceGeofenceResource.class, GeofencePermissionResource.class, GroupGeofenceResource.class, - NotificationResource.class, ReportResource.class, AttributeAliasResource.class); + resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class); + resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class); + resourceConfig.packages(ServerResource.class.getPackage().getName()); + servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*"); handlers.addHandler(servletHandler); |