Permalink
Browse files

codigo aula 24

  • Loading branch information...
1 parent 53a953f commit 80247091540444b10d60a9639c9f1d64f025eac8 Fernando Miguel Carvalho committed May 7, 2012
Showing with 13,327 additions and 0 deletions.
  1. +1 −0 aula24-mvc/.gitignore
  2. +107 −0 aula24-mvc/build.xml
  3. 0 aula24-mvc/dist/.gitignore
  4. +32 −0 aula24-mvc/readme.txt
  5. 0 aula24-mvc/src/docs/.gitignore
  6. 0 aula24-mvc/src/main/java/.gitignore
  7. +21 −0 aula24-mvc/src/main/java/app/Program.java
  8. +136 −0 aula24-mvc/src/main/java/com/jtmdb/Auth.java
  9. +921 −0 aula24-mvc/src/main/java/com/jtmdb/BrowseOptions.java
  10. +304 −0 aula24-mvc/src/main/java/com/jtmdb/CastInfo.java
  11. +123 −0 aula24-mvc/src/main/java/com/jtmdb/Country.java
  12. +75 −0 aula24-mvc/src/main/java/com/jtmdb/Dimension.java
  13. +354 −0 aula24-mvc/src/main/java/com/jtmdb/FilmographyInfo.java
  14. +384 −0 aula24-mvc/src/main/java/com/jtmdb/GeneralSettings.java
  15. +96 −0 aula24-mvc/src/main/java/com/jtmdb/GeneralSettingsState.java
  16. +194 −0 aula24-mvc/src/main/java/com/jtmdb/Genre.java
  17. +138 −0 aula24-mvc/src/main/java/com/jtmdb/Log.java
  18. +416 −0 aula24-mvc/src/main/java/com/jtmdb/Media.java
  19. +2,028 −0 aula24-mvc/src/main/java/com/jtmdb/Movie.java
  20. +178 −0 aula24-mvc/src/main/java/com/jtmdb/MovieBackdrop.java
  21. +43 −0 aula24-mvc/src/main/java/com/jtmdb/MovieImages.java
  22. +196 −0 aula24-mvc/src/main/java/com/jtmdb/MoviePoster.java
  23. +42 −0 aula24-mvc/src/main/java/com/jtmdb/MovieVersionInfo.java
  24. +80 −0 aula24-mvc/src/main/java/com/jtmdb/Pair.java
  25. +941 −0 aula24-mvc/src/main/java/com/jtmdb/Person.java
  26. +179 −0 aula24-mvc/src/main/java/com/jtmdb/PersonProfile.java
  27. +27 −0 aula24-mvc/src/main/java/com/jtmdb/PersonVersionInfo.java
  28. +158 −0 aula24-mvc/src/main/java/com/jtmdb/ServerResponse.java
  29. +54 −0 aula24-mvc/src/main/java/com/jtmdb/Session.java
  30. +97 −0 aula24-mvc/src/main/java/com/jtmdb/Studio.java
  31. +60 −0 aula24-mvc/src/main/java/com/jtmdb/Translation.java
  32. +84 −0 aula24-mvc/src/main/java/com/jtmdb/VersionInfo.java
  33. +12 −0 aula24-mvc/src/main/java/movq/core/IMovie.java
  34. +5 −0 aula24-mvc/src/main/java/movq/core/IMovieController.java
  35. +5 −0 aula24-mvc/src/main/java/movq/core/IMovieFinder.java
  36. +5 −0 aula24-mvc/src/main/java/movq/core/IMovieQueryResult.java
  37. +5 −0 aula24-mvc/src/main/java/movq/core/IMovieUiRequest.java
  38. +8 −0 aula24-mvc/src/main/java/movq/core/MovieQueryException.java
  39. +32 −0 aula24-mvc/src/main/java/movq/ctrl/MovieController.java
  40. +80 −0 aula24-mvc/src/main/java/movq/finders/FinderDcService.java
  41. +28 −0 aula24-mvc/src/main/java/movq/finders/FinderJtmdbService.java
  42. +32 −0 aula24-mvc/src/main/java/movq/views/UiRequestConsole.java
  43. +51 −0 aula24-mvc/src/main/java/movq/views/UiRequestGui.java
  44. +15 −0 aula24-mvc/src/main/java/movq/views/ViewResultsInConsole.java
  45. +279 −0 aula24-mvc/src/main/java/org/json/CDL.java
  46. +169 −0 aula24-mvc/src/main/java/org/json/Cookie.java
  47. +90 −0 aula24-mvc/src/main/java/org/json/CookieList.java
  48. +163 −0 aula24-mvc/src/main/java/org/json/HTTP.java
  49. +77 −0 aula24-mvc/src/main/java/org/json/HTTPTokener.java
  50. +906 −0 aula24-mvc/src/main/java/org/json/JSONArray.java
  51. +28 −0 aula24-mvc/src/main/java/org/json/JSONException.java
  52. +465 −0 aula24-mvc/src/main/java/org/json/JSONML.java
  53. +1,593 −0 aula24-mvc/src/main/java/org/json/JSONObject.java
  54. +18 −0 aula24-mvc/src/main/java/org/json/JSONString.java
  55. +78 −0 aula24-mvc/src/main/java/org/json/JSONStringer.java
  56. +446 −0 aula24-mvc/src/main/java/org/json/JSONTokener.java
  57. +327 −0 aula24-mvc/src/main/java/org/json/JSONWriter.java
  58. +68 −0 aula24-mvc/src/main/java/org/json/README
  59. +508 −0 aula24-mvc/src/main/java/org/json/XML.java
  60. +365 −0 aula24-mvc/src/main/java/org/json/XMLTokener.java
  61. 0 aula24-mvc/src/main/sql/.gitignore
  62. 0 aula24-mvc/src/test/java/.gitignore
  63. 0 aula24-mvc/src/test/sql/.gitignore
  64. BIN aula24-mvc/vendor/main/lib/aopalliance.jar
  65. BIN aula24-mvc/vendor/main/lib/guice-2.0.jar
  66. BIN aula24-mvc/vendor/main/lib/sqljdbc4.jar
  67. BIN aula24-mvc/vendor/test/lib/junit-4.8.1.jar
View
@@ -0,0 +1 @@
+target/
View
@@ -0,0 +1,107 @@
+<!-- ======================================================================
+ <Project name>: <Project description>
+ ====================================================================== -->
+
+<project name="project-name" default="package" basedir=".">
+
+ <description>Ant build file</description>
+
+ <!--++++++++++ Properties ++++++++++-->
+ <property name="src-main" location="src/main/java"/>
+ <property name="src-test" location="src/test/java"/>
+ <property name="target" location="target"/>
+ <property name="target-classes" location="target/classes"/>
+ <property name="target-test-classes" location="target/test-classes"/>
+ <property name="target-test-reports" location="target/test-reports"/>
+ <property name="dist-dir" location="dist"/>
+ <property name="jar-name" value="${ant.project.name}"/>
+
+ <path id="main.extlibs.class.path">
+ <fileset dir="vendor/main/lib">
+ <include name="**/*.jar" />
+ </fileset>
+ </path>
+
+ <path id="test.extlibs.class.path">
+ <path refid="main.extlibs.class.path" />
+ <fileset dir="vendor/test/lib">
+ <include name="**/*.jar" />
+ </fileset>
+ </path>
+
+ <!--++++++++++ Targets ++++++++++-->
+
+ <target name="package" depends="test" description="Packages the main classes into a jar" >
+ <buildnumber />
+ <jar jarfile="${dist}/${jar-name}.${build.number}.jar" basedir="${target-classes}"/>
+ </target>
+
+
+ <target name="init" description ="Creates the target folders">
+ <mkdir dir="${target-classes}"/>
+ <mkdir dir="${target-test-classes}"/>
+ <mkdir dir="${target-test-reports}"/>
+ </target>
+
+
+ <target name="clean" description="Removes the target folders" >
+ <!--delete dir="${target}" excludes="applications" verbose="true"/-->
+ <delete includeEmptyDirs="true" failonerror="false" verbose="true" >
+ <fileset dir="${target}" defaultexcludes="false"/>
+ </delete>
+
+ </target>
+
+
+ <target name="compile-main" depends="init"
+ description="Compiles the main source" >
+
+ <javac debug="true"
+ srcdir="${src-main}"
+ destdir="${target-classes}"
+ includeantruntime="false">
+ <classpath>
+ <path refid="main.extlibs.class.path" />
+ </classpath>
+ </javac>
+ <copy todir="${target-classes}">
+ <fileset dir="${src-main}">
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
+ </target>
+
+
+ <target name="compile-test" depends="compile-main" description="Compiles the test source" >
+ <javac debug="true"
+ debugLevel="source"
+ srcdir="${src-test}"
+ destdir="${target-test-classes}"
+ includeantruntime="true">
+ <classpath>
+ <pathelement location="${target-classes}"/>
+ <path refid="test.extlibs.class.path" />
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="test" depends="compile-test" description="Runs the tests">
+ <junit printsummary="yes" haltonfailure="true" showoutput="true" >
+ <classpath>
+ <pathelement location="${target-classes}"/>
+ <pathelement location="${target-test-classes}"/>
+ <path refid="test.extlibs.class.path" />
+ </classpath>
+
+ <formatter type="plain"/>
+
+ <batchtest fork="yes" todir="${target-test-reports}" >
+ <fileset dir="${src-test}">
+ <include name="**/*Test*.java"/>
+ </fileset>
+ <formatter type="xml"/>
+ <formatter type="plain" usefile="false" />
+ </batchtest>
+ </junit>
+ </target>
+</project>
No changes.
View
@@ -0,0 +1,32 @@
+* Contents:
+ + build.xml - ant build file
+
+ + build.number - current build number
+
+ + src - source folder (follows Maven folder structure)
+
+ + docs
+
+ + main - main sources
+
+ + java - java main sources (package folders start here)
+ + packages ...
+
+ + sql
+
+ + resource
+
+ + test - test sources
+
+ + java - java test sources (package folders start here)
+ + packages ...
+
+ + sql
+
+ + resource
+
+ + vendor/lib/ - external libraries
+
+ + target (created by compile tasks and removed by "clean" task) - .class and .jar files
+
+ - shouldn't be on remote repository.
No changes.
No changes.
@@ -0,0 +1,21 @@
+package app;
+
+import movq.core.IMovieFinder;
+import movq.core.IMovieQueryResult;
+import movq.ctrl.MovieController;
+import movq.finders.FinderJtmdbService;
+import movq.views.UiRequestConsole;
+import movq.views.UiRequestGui;
+import movq.views.ViewResultsInConsole;
+
+public class Program {
+ public static void main(String[] args) throws Exception {
+ IMovieFinder finder = new FinderJtmdbService();
+ IMovieQueryResult results = new ViewResultsInConsole();
+ // new UiRequestConsole(finder, results).launch();
+ new UiRequestGui(
+ new MovieController(
+ finder, results)
+ ).launch();
+ }
+}
@@ -0,0 +1,136 @@
+package com.jtmdb;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.jtmdb.GeneralSettings.Utilities;
+import com.jtmdb.Log.Verbosity;
+
+/**
+ * Class that handles authorization with tmdb. The authentication procedure is
+ * as follows. The user must request a token from the server using the method
+ * {@link #getToken()}. Then using the method {@link #authorizeToken(String)}
+ * the user must browse to the returned URL and authenticate the token. Once the
+ * token is authenticated, the user can create an authenticated session using
+ * the method {@link #getSession(String)}
+ *
+ * @author Savvas Dalkitsis
+ */
+public class Auth {
+
+ private Auth() {
+
+ }
+
+ /**
+ * Gets the session for the authenticated token. Will return a pair of
+ * Session and the ServerResponse or null if there was an error with the API
+ * or an IOException occurred.
+ *
+ * @param token
+ * The authenticated token.
+ * @return A pair of Session and the ServerResponse or null if there was an
+ * error with the API or an IOException occurred.
+ */
+ public static Pair<Session, ServerResponse> getSession(String token) {
+ Log.log("Getting session for token " + token, Verbosity.NORMAL);
+ if (GeneralSettings.getApiKey() != null
+ && !GeneralSettings.getApiKey().equals("")) {
+ try {
+ URL call = new URL(GeneralSettings.BASE_URL
+ + GeneralSettings.AUTH_SESSION_URL
+ + GeneralSettings.API_MODE_URL + "/"
+ + GeneralSettings.getApiKey() + "/" + token);
+ String jsonString = Utilities.readUrlResponse(call);
+ try {
+ JSONObject jsonObject = new JSONObject(jsonString
+ .toString());
+ if (jsonObject.has("code")) {
+ return new Pair<Session, ServerResponse>(null,
+ ServerResponse.forID(jsonObject.getInt("code")));
+ }
+ String userName = jsonObject.getString("username");
+ String session = jsonObject.getString("session");
+ return new Pair<Session, ServerResponse>(new Session(
+ userName, session), ServerResponse.SUCCESS);
+ } catch (JSONException e) {
+ Log.log(e, Verbosity.NORMAL);
+ return new Pair<Session, ServerResponse>(null,
+ ServerResponse.UNKNOWN_ERROR);
+ }
+ } catch (IOException e) {
+ Log.log(e, Verbosity.ERROR);
+ }
+ } else {
+ Log.log("Error with the API key", Verbosity.ERROR);
+ }
+ return null;
+ }
+
+ /**
+ * Will return the URL that the user must browse to, in order to
+ * authenticate the provided token.
+ *
+ * @param token
+ * The token to authenticate.
+ * @return The URL that the user must browse to, in order to authenticate
+ * the provided token.
+ */
+ public static URL authorizeToken(String token) {
+ try {
+ return new URL("http://www.themoviedb.org/auth/" + token);
+ } catch (MalformedURLException e) {
+ Log.log(e, Verbosity.ERROR);
+ }
+ return null;
+ }
+
+ /**
+ * Requests a token from the server that can be used to create an
+ * authenticated session. Will be null if an error occurred.
+ *
+ * @return A token from the server that can be used to create an
+ * authenticated session. Will be null if an error occurred.
+ * @throws IOException
+ * @throws JSONException
+ */
+ public static String getToken() throws IOException, JSONException {
+ Log.log("Getting token for authentication", Verbosity.NORMAL);
+ if (GeneralSettings.getApiKey() != null
+ && !GeneralSettings.getApiKey().equals("")) {
+ try {
+ URL call = new URL(GeneralSettings.BASE_URL
+ + GeneralSettings.AUTH_TOKEN_URL
+ + GeneralSettings.API_MODE_URL + "/"
+ + GeneralSettings.getApiKey());
+ String jsonString = Utilities.readUrlResponse(call).trim();
+ if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
+ && !jsonString.equals("[\"Nothing found.\"]")) {
+ JSONObject jsonObject = new JSONObject(jsonString
+ .toString());
+ String token = jsonObject.getString("token");
+ return token;
+ } else {
+ Log
+ .log(
+ "Getting token for authentication returned no results",
+ Verbosity.NORMAL);
+ }
+ } catch (IOException e) {
+ Log.log(e, Verbosity.ERROR);
+ throw e;
+ } catch (JSONException e) {
+ Log.log(e, Verbosity.ERROR);
+ throw e;
+ }
+ } else {
+ Log.log("Error with the API key", Verbosity.ERROR);
+ }
+ return null;
+ }
+}
Oops, something went wrong.

0 comments on commit 8024709

Please sign in to comment.