diff options
15 files changed, 77 insertions, 40 deletions
@@ -58,7 +58,7 @@ <reportSet> <reports> <report>dependencies</report> - <report>index</report> + <report>index</report> <!-- <report>project-team</report> <report>mailing-list</report> <report>cim</report> <report>issue-tracking</report> --> <report>license</report> @@ -92,6 +92,11 @@ <version>3.8.1</version> <scope>test</scope> </dependency> + <dependency> + <groupId>ws-commons-util</groupId> + <artifactId>ws-commons-util</artifactId> + <version>1.0.1</version> + </dependency> </dependencies> diff --git a/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java b/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java index c60349f..89e566c 100644 --- a/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java +++ b/src/main/java/de/dhbw/horb/calendar/dualis/DualisConnection.java @@ -31,7 +31,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage; import de.dhbw.horb.calendar.dualis.DualisException.DualisAuthenticationException; import de.dhbw.horb.calendar.dualis.DualisException.DualisScrapingException; -import de.dhbw.horb.calendar.ics.VEvent; +import de.dhbw.horb.calendar.ics.VEventComponent; public class DualisConnection { public static final String DUALIS_URL = "https://dualis.dhbw.de/scripts/mgrqcgi?APPNAME=CampusNet&PRGNAME=EXTERNALPAGES&ARGUMENTS=-N000000000000001,-N,-Awelcome"; @@ -56,13 +56,13 @@ public class DualisConnection { this.password = password; } - public List<VEvent> getEvents() throws FailingHttpStatusCodeException, + public List<VEventComponent> getEvents() throws FailingHttpStatusCodeException, IOException, DualisScrapingException, DualisAuthenticationException { HtmlPage page, loginPage; final HtmlForm loginForm; final HtmlInput usernameField, passwordField, submitButton; final WebClient webClient = new WebClient(); - final List<VEvent> events = new ArrayList<VEvent>(); + final List<VEventComponent> events = new ArrayList<VEventComponent>(); webClient.setIncorrectnessListener(new IncorrectnessListener() { @Override @@ -179,7 +179,7 @@ public class DualisConnection { return events; } - private void getEventsFromPage(HtmlPage page, final List<VEvent> events) { + private void getEventsFromPage(HtmlPage page, final List<VEventComponent> events) { for (HtmlElement elem : page.getElementsByTagName("div")) { if (!elem.getAttribute("class").equals("tbMonthDay")) continue; @@ -223,7 +223,7 @@ public class DualisConnection { cstart.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); cend.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); - VEvent event = new VEvent.Builder().dtstart(cstart) + VEventComponent event = new VEventComponent.Builder().dtstart(cstart) .dtstamp(cstart).dtend(cend).summary(title) .description(title).location(room) .status("CONFIRMED").build(); diff --git a/src/main/java/de/dhbw/horb/calendar/dualis/package.html b/src/main/java/de/dhbw/horb/calendar/dualis/package.html new file mode 100644 index 0000000..7a37853 --- /dev/null +++ b/src/main/java/de/dhbw/horb/calendar/dualis/package.html @@ -0,0 +1,5 @@ +<html> +<body> +This package contains the Dualis Webscraper Classes based on htmlunit. +</body> +</html>
\ No newline at end of file diff --git a/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java b/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java index a03de64..272148f 100644 --- a/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java +++ b/src/main/java/de/dhbw/horb/calendar/ics/AbstractICSType.java @@ -4,6 +4,12 @@ import java.text.SimpleDateFormat; import org.apache.commons.lang.StringEscapeUtils; +/** + * icalendar specifies Events, Todo, Journal, Free/Buse, TimeZone, Alarm + * Components. + * + * {@link AbstractICSType} is a superclass for those. + */ public abstract class AbstractICSType { /** * Serialisierert dieses Calenderteil. Dem Ergebnis Fehlt noch der vCalendar @@ -14,6 +20,7 @@ public abstract class AbstractICSType { /** * <b>RFC says:</b> + * * <pre> * FORM #2: DATE WITH UTC TIME * @@ -38,6 +45,6 @@ public abstract class AbstractICSType { * @return */ public static String escapeText(String text) { - return StringEscapeUtils.escapeJava(text); //XXX TODO + return StringEscapeUtils.escapeJava(text); // XXX TODO } } diff --git a/src/main/java/de/dhbw/horb/calendar/ics/VCalendar.java b/src/main/java/de/dhbw/horb/calendar/ics/ICalendarObject.java index fcf083a..e687d04 100644 --- a/src/main/java/de/dhbw/horb/calendar/ics/VCalendar.java +++ b/src/main/java/de/dhbw/horb/calendar/ics/ICalendarObject.java @@ -3,11 +3,18 @@ package de.dhbw.horb.calendar.ics; import java.util.ArrayList; import java.util.List; -public class VCalendar { +/** + * Represent an iCalender Object. + * + * A iCalender object can consist of many components of different type. They are + * implemented as subclasses of {@link AbstractICSType} and can be added to an + * instance of {@link ICalendarObject}. + */ +public class ICalendarObject { List<AbstractICSType> icsObjects = new ArrayList<AbstractICSType>(); private final String title; - public VCalendar(final String title) { + public ICalendarObject(final String title) { this.title = title; } @@ -16,8 +23,8 @@ public class VCalendar { } /** - * - * @return + * + * @return serialized iCalendar Object */ public String serialize() { final StringBuilder sb = new StringBuilder(); @@ -38,9 +45,9 @@ public class VCalendar { // sb.append("X-WR-TIMEZONE:UTC\n"); // Name des Kalenders - sb.append("X-WR-CALDESC:" + AbstractICSType.escapeText(title)+"\n"); - sb.append("X-WR-CALNAME:" + AbstractICSType.escapeText(title)+"\n"); - + sb.append("X-WR-CALDESC:" + AbstractICSType.escapeText(title) + "\n"); + sb.append("X-WR-CALNAME:" + AbstractICSType.escapeText(title) + "\n"); + // Elemente for (AbstractICSType ics : icsObjects) { sb.append(ics.serialize()); diff --git a/src/main/java/de/dhbw/horb/calendar/ics/VEvent.java b/src/main/java/de/dhbw/horb/calendar/ics/VEventComponent.java index dea4a17..bfc2162 100644 --- a/src/main/java/de/dhbw/horb/calendar/ics/VEvent.java +++ b/src/main/java/de/dhbw/horb/calendar/ics/VEventComponent.java @@ -3,7 +3,7 @@ package de.dhbw.horb.calendar.ics; import java.util.Calendar; import java.util.TimeZone; -public class VEvent extends AbstractICSType { +public class VEventComponent extends AbstractICSType { public Calendar dtstamp = Calendar.getInstance(); public Calendar dtstart = Calendar.getInstance(); public Calendar dtend = Calendar.getInstance(); @@ -41,7 +41,7 @@ public class VEvent extends AbstractICSType { } public static class Builder { - VEvent event = new VEvent(); + VEventComponent event = new VEventComponent(); public Builder dtstamp(Calendar cstart) { event.dtstamp = cstart; @@ -73,7 +73,7 @@ public class VEvent extends AbstractICSType { return this; } - public VEvent build() { + public VEventComponent build() { return event; } diff --git a/src/main/java/de/dhbw/horb/calendar/ics/package.html b/src/main/java/de/dhbw/horb/calendar/ics/package.html new file mode 100644 index 0000000..d35c7ea --- /dev/null +++ b/src/main/java/de/dhbw/horb/calendar/ics/package.html @@ -0,0 +1,5 @@ +<html> +<body> +Classes to produce iCalendar formatted data +</body> +</html>
\ No newline at end of file diff --git a/src/main/java/de/dhbw/horb/calendar/util/AuthenticatedServlet.java b/src/main/java/de/dhbw/horb/calendar/servlet/AuthenticatedServlet.java index 47ca537..df6d499 100644 --- a/src/main/java/de/dhbw/horb/calendar/util/AuthenticatedServlet.java +++ b/src/main/java/de/dhbw/horb/calendar/servlet/AuthenticatedServlet.java @@ -1,4 +1,4 @@ -package de.dhbw.horb.calendar.util; +package de.dhbw.horb.calendar.servlet; import java.io.IOException; import java.util.StringTokenizer; @@ -9,13 +9,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringEscapeUtils; - -import sun.misc.BASE64Decoder; +import org.apache.ws.commons.util.Base64; public abstract class AuthenticatedServlet extends HttpServlet { private static final long serialVersionUID = 1L; - - + private String loginRealm = "Servlet Login"; public void setLoginRealm(String loginRealm) { @@ -35,10 +33,7 @@ public abstract class AuthenticatedServlet extends HttpServlet { if (basic.equalsIgnoreCase("Basic")) { String credentials = st.nextToken(); - // XXX fixme, dont use sun.misc - BASE64Decoder decoder = new BASE64Decoder(); - String userPass = new String( - decoder.decodeBuffer(credentials)); + String userPass = new String(Base64.decode(credentials)); // The decoded string is in the form // "userID:password". diff --git a/src/main/java/de/dhbw/horb/calendar/ICSServlet.java b/src/main/java/de/dhbw/horb/calendar/servlet/ICSServlet.java index 8a1be3e..a76f781 100644 --- a/src/main/java/de/dhbw/horb/calendar/ICSServlet.java +++ b/src/main/java/de/dhbw/horb/calendar/servlet/ICSServlet.java @@ -1,4 +1,4 @@ -package de.dhbw.horb.calendar; +package de.dhbw.horb.calendar.servlet; import java.io.IOException; @@ -7,10 +7,13 @@ import javax.servlet.http.HttpServletResponse; import de.dhbw.horb.calendar.dualis.DualisConnection; import de.dhbw.horb.calendar.dualis.DualisException; -import de.dhbw.horb.calendar.ics.VCalendar; -import de.dhbw.horb.calendar.ics.VEvent; -import de.dhbw.horb.calendar.util.AuthenticatedServlet; +import de.dhbw.horb.calendar.ics.ICalendarObject; +import de.dhbw.horb.calendar.ics.VEventComponent; +/** + * Das ICS-Servlet ist ein HTTP-Servlet das von der Kalenderapplikation + * aufgerufen wird um die iCalendar Daten zu bekommen. + */ public class ICSServlet extends AuthenticatedServlet { private static final long serialVersionUID = 1L; @@ -23,12 +26,12 @@ public class ICSServlet extends AuthenticatedServlet { HttpServletResponse response, String username, String password) throws IOException { response.setHeader("Content-Type", "text/calendar; charset=utf-8"); - - VCalendar calendar = new VCalendar("DHBW Calendar"); + + ICalendarObject calendar = new ICalendarObject("DHBW Calendar"); try { DualisConnection connection = new DualisConnection(username, password); - for (VEvent event : connection.getEvents()) { + for (VEventComponent event : connection.getEvents()) { calendar.add(event); } } catch (DualisException e) { diff --git a/src/main/java/de/dhbw/horb/calendar/servlet/package.html b/src/main/java/de/dhbw/horb/calendar/servlet/package.html new file mode 100644 index 0000000..a8d65b8 --- /dev/null +++ b/src/main/java/de/dhbw/horb/calendar/servlet/package.html @@ -0,0 +1,5 @@ +<html> +<body> +HTTP-Servlet to serve /ics +</body> +</html>
\ No newline at end of file diff --git a/src/main/java/de/dhbw/horb/calendar/ui/LoginWorker.java b/src/main/java/de/dhbw/horb/calendar/ui/InteractiveLoginWorker.java index 34941c0..01258e9 100644 --- a/src/main/java/de/dhbw/horb/calendar/ui/LoginWorker.java +++ b/src/main/java/de/dhbw/horb/calendar/ui/InteractiveLoginWorker.java @@ -21,7 +21,7 @@ import de.dhbw.horb.calendar.dualis.DualisConnection; import de.dhbw.horb.calendar.dualis.DualisException; import de.dhbw.horb.calendar.dualis.DualisException.DualisAuthenticationException; -class LoginWorker implements Runnable { +class InteractiveLoginWorker implements Runnable { private final WebClient client; private HtmlPage page = null; private HtmlForm loginForm = null; @@ -32,7 +32,7 @@ class LoginWorker implements Runnable { private final String password; private final LoginWorkerListener listener; - public LoginWorker(final LoginWorkerListener listener, final String username, final String password) { + public InteractiveLoginWorker(final LoginWorkerListener listener, final String username, final String password) { this.listener = listener; this.username = username; this.password = password; diff --git a/src/main/java/de/dhbw/horb/calendar/ui/MyApplication.java b/src/main/java/de/dhbw/horb/calendar/ui/MyApplication.java index 9a0f222..4fc5749 100644 --- a/src/main/java/de/dhbw/horb/calendar/ui/MyApplication.java +++ b/src/main/java/de/dhbw/horb/calendar/ui/MyApplication.java @@ -13,7 +13,7 @@ import com.vaadin.ui.ProgressIndicator; import com.vaadin.ui.TabSheet; import com.vaadin.ui.Window; -import de.dhbw.horb.calendar.ui.LoginWorker.LoginWorkerListener; +import de.dhbw.horb.calendar.ui.InteractiveLoginWorker.LoginWorkerListener; public class MyApplication extends Application { private static final long serialVersionUID = 1L; @@ -142,7 +142,7 @@ public class MyApplication extends Application { @Override public void onLogin(LoginEvent event) { - new Thread(new LoginWorker(loginWorkerListener, event + new Thread(new InteractiveLoginWorker(loginWorkerListener, event .getLoginParameter("username"), event .getLoginParameter("password"))).start(); loginForm.setVisible(false); diff --git a/src/main/java/de/dhbw/horb/calendar/ui/StundenplanComponent.java b/src/main/java/de/dhbw/horb/calendar/ui/StundenplanComponent.java index 0357610..29ddecc 100644 --- a/src/main/java/de/dhbw/horb/calendar/ui/StundenplanComponent.java +++ b/src/main/java/de/dhbw/horb/calendar/ui/StundenplanComponent.java @@ -12,7 +12,7 @@ import com.vaadin.ui.Table; import com.vaadin.ui.VerticalLayout; import de.dhbw.horb.calendar.dualis.DualisConnection; -import de.dhbw.horb.calendar.ics.VEvent; +import de.dhbw.horb.calendar.ics.VEventComponent; import de.dhbw.horb.calendar.ui.MyApplication.MyMainWindow; public class StundenplanComponent extends FormLayout { @@ -34,7 +34,7 @@ public class StundenplanComponent extends FormLayout { myMainWindow.getUsername(), myMainWindow.getPassword()); try { - for (VEvent vevent : dualisConnection.getEvents()) { + for (VEventComponent vevent : dualisConnection.getEvents()) { synchronized (getApplication()) { table.addItem(new Object[] { vevent.dtstart.getTime(), vevent.dtend.getTime(), vevent.summary, diff --git a/src/main/java/de/dhbw/horb/calendar/ui/package.html b/src/main/java/de/dhbw/horb/calendar/ui/package.html new file mode 100644 index 0000000..3591a6b --- /dev/null +++ b/src/main/java/de/dhbw/horb/calendar/ui/package.html @@ -0,0 +1,5 @@ +<html> +<body> +vaadin based Webinterface. +</body> +</html>
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 1bed2f5..119e38f 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -6,7 +6,7 @@ <servlet> <servlet-name>ics-connector</servlet-name> - <servlet-class>de.dhbw.horb.calendar.ICSServlet</servlet-class> + <servlet-class>de.dhbw.horb.calendar.servlet.ICSServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ics-connector</servlet-name> |