commit 8ffc185e46ab6b4d303daa615a5c95a61024363ce2ad6448cd3c6960c2253333 Author: William Cardoso Simas Date: Wed Nov 18 09:41:25 2026 -0300 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c05d38 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* +.fake \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0e629e7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar", + "gson-2.10.1.jar" + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..6bf77cb --- /dev/null +++ b/README.md @@ -0,0 +1,101 @@ +## Alura-Stickers + +Projeto desenvolvido na imersão Java da Alura, realizada entre os dias 27/03/2023 e 31/03/2023. Trata-se de um programa em Java para baixar imagens de algumas APIs e gerar figurinhas para redes sociais. + +Clique na imagem abaixo para assistir o vídeo. + +[![Watch the video](https://img.youtube.com/vi/ujaCt-Mt6Qo/hqdefault.jpg)](https://www.youtube.com/watch?v=ujaCt-Mt6Qo) + + \ No newline at end of file diff --git a/gson-2.10.1/META-INF/MANIFEST.MF b/gson-2.10.1/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c57dfaf --- /dev/null +++ b/gson-2.10.1/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Created-By: 11.0.16.1 (Azul Systems, Inc.) +Build-Jdk-Spec: 11 +Bnd-LastModified: 1673019830620 +Bundle-ContactAddress: https://github.com/google/gson +Bundle-Description: Gson JSON library +Bundle-Developers: google;organization=Google;organizationUrl="https://w + ww.google.com" +Bundle-DocURL: https://github.com/google/gson/gson +Bundle-License: "Apache-2.0";link="https://www.apache.org/licenses/LICEN + SE-2.0.txt" +Bundle-ManifestVersion: 2 +Bundle-Name: Gson +Bundle-RequiredExecutionEnvironment: JavaSE-1.7, JavaSE-1.8 +Bundle-SCM: url="https://github.com/google/gson/gson/",connection="scm:g + it:https://github.com/google/gson.git/gson",developer-connection="scm:g + it:git@github.com:google/gson.git/gson",tag="gson-parent-2.10.1" +Bundle-SymbolicName: com.google.gson +Bundle-Vendor: Google Gson Project +Bundle-Version: 2.10.1 +Export-Package: com.google.gson;uses:="com.google.gson.reflect,com.googl + e.gson.stream";version="2.10.1",com.google.gson.annotations;version="2. + 10.1",com.google.gson.reflect;version="2.10.1",com.google.gson.stream;v + ersion="2.10.1" +Import-Package: sun.misc;resolution:=optional,com.google.gson.annotation + s +Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))" +Tool: Bnd-6.4.0.202211291949 +Multi-Release: true + diff --git a/gson-2.10.1/META-INF/maven/com.google.code.gson/gson/pom.properties b/gson-2.10.1/META-INF/maven/com.google.code.gson/gson/pom.properties new file mode 100644 index 0000000..05f8bf1 --- /dev/null +++ b/gson-2.10.1/META-INF/maven/com.google.code.gson/gson/pom.properties @@ -0,0 +1,3 @@ +artifactId=gson +groupId=com.google.code.gson +version=2.10.1 diff --git a/gson-2.10.1/META-INF/maven/com.google.code.gson/gson/pom.xml b/gson-2.10.1/META-INF/maven/com.google.code.gson/gson/pom.xml new file mode 100644 index 0000000..8107038 --- /dev/null +++ b/gson-2.10.1/META-INF/maven/com.google.code.gson/gson/pom.xml @@ -0,0 +1,253 @@ + + 4.0.0 + + + com.google.code.gson + gson-parent + 2.10.1 + + + gson + Gson + + + + Apache-2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + **/Java17* + + + + + junit + junit + test + + + + + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filtering-java-templates + + filter-sources + + + ${basedir}/src/main/java-templates + ${project.build.directory}/generated-sources/java-templates + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + + + + module-info.java + + + + + default-testCompile + test-compile + + testCompile + + + + ${excludeTestCompilation} + + + + + + + biz.aQute.bnd + bnd-maven-plugin + 6.4.0 + + + + bnd-process + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + + --illegal-access=deny + + + + com.coderplus.maven.plugins + copy-rename-maven-plugin + 1.0.1 + + + pre-obfuscate-class + process-test-classes + + rename + + + + + ${project.build.directory}/test-classes/com/google/gson/functional/EnumWithObfuscatedTest.class + ${project.build.directory}/test-classes-obfuscated-injar/com/google/gson/functional/EnumWithObfuscatedTest.class + + + ${project.build.directory}/test-classes/com/google/gson/functional/EnumWithObfuscatedTest$Gender.class + ${project.build.directory}/test-classes-obfuscated-injar/com/google/gson/functional/EnumWithObfuscatedTest$Gender.class + + + + + + + + com.github.wvengen + proguard-maven-plugin + 2.6.0 + + + obfuscate-test-class + process-test-classes + + proguard + + + + + true + test-classes-obfuscated-injar + test-classes-obfuscated-outjar + **/*.class + ${basedir}/src/test/resources/testcases-proguard.conf + + ${project.build.directory}/classes + ${java.home}/jmods/java.base.jmod + + + + + maven-resources-plugin + 3.3.0 + + + post-obfuscate-class + process-test-classes + + copy-resources + + + ${project.build.directory}/test-classes/com/google/gson/functional + + + ${project.build.directory}/test-classes-obfuscated-outjar/com/google/gson/functional + + EnumWithObfuscatedTest.class + EnumWithObfuscatedTest$Gender.class + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + + + org.moditect + moditect-maven-plugin + 1.0.0.RC2 + + + add-module-info + package + + add-module-info + + + 9 + + ${project.build.sourceDirectory}/module-info.java + + + true + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + com.google.gson.internal:com.google.gson.internal.bind + + + + + + + JDK17 + + [17,) + + + 17 + + + + + diff --git a/img/Aula 01/MostPopularMovies_TopTvs.png b/img/Aula 01/MostPopularMovies_TopTvs.png new file mode 100644 index 0000000..91e8805 Binary files /dev/null and b/img/Aula 01/MostPopularMovies_TopTvs.png differ diff --git a/img/Aula 01/TopMovies.png b/img/Aula 01/TopMovies.png new file mode 100644 index 0000000..f8e7ffb Binary files /dev/null and b/img/Aula 01/TopMovies.png differ diff --git a/img/Aula 01/TopTvs_MostPopularTvs.png b/img/Aula 01/TopTvs_MostPopularTvs.png new file mode 100644 index 0000000..fab7af4 Binary files /dev/null and b/img/Aula 01/TopTvs_MostPopularTvs.png differ diff --git a/img/Aula 02/12 Angry Men.png b/img/Aula 02/12 Angry Men.png new file mode 100644 index 0000000..a232e89 Binary files /dev/null and b/img/Aula 02/12 Angry Men.png differ diff --git a/img/Aula 02/Breaking Bad.png b/img/Aula 02/Breaking Bad.png new file mode 100644 index 0000000..9472477 Binary files /dev/null and b/img/Aula 02/Breaking Bad.png differ diff --git a/img/Aula 02/Elvis.png b/img/Aula 02/Elvis.png new file mode 100644 index 0000000..6cc865d Binary files /dev/null and b/img/Aula 02/Elvis.png differ diff --git a/img/Aula 02/Planet Earth II.png b/img/Aula 02/Planet Earth II.png new file mode 100644 index 0000000..2b7caec Binary files /dev/null and b/img/Aula 02/Planet Earth II.png differ diff --git a/img/Aula 02/Planet Earth.png b/img/Aula 02/Planet Earth.png new file mode 100644 index 0000000..6d659a7 Binary files /dev/null and b/img/Aula 02/Planet Earth.png differ diff --git a/img/Aula 02/Pulp Fiction.png b/img/Aula 02/Pulp Fiction.png new file mode 100644 index 0000000..724ba40 Binary files /dev/null and b/img/Aula 02/Pulp Fiction.png differ diff --git a/img/Aula 02/Schindler's List.png b/img/Aula 02/Schindler's List.png new file mode 100644 index 0000000..3551687 Binary files /dev/null and b/img/Aula 02/Schindler's List.png differ diff --git a/img/Aula 02/Stranger Things.png b/img/Aula 02/Stranger Things.png new file mode 100644 index 0000000..0f9b296 Binary files /dev/null and b/img/Aula 02/Stranger Things.png differ diff --git a/img/Aula 02/The Boys.png b/img/Aula 02/The Boys.png new file mode 100644 index 0000000..f1e3465 Binary files /dev/null and b/img/Aula 02/The Boys.png differ diff --git a/img/Aula 02/The Dark Knight.png b/img/Aula 02/The Dark Knight.png new file mode 100644 index 0000000..56b9d40 Binary files /dev/null and b/img/Aula 02/The Dark Knight.png differ diff --git a/img/Aula 02/The Godfather - Part II.png b/img/Aula 02/The Godfather - Part II.png new file mode 100644 index 0000000..b1ac37c Binary files /dev/null and b/img/Aula 02/The Godfather - Part II.png differ diff --git a/img/Aula 02/The Godfather.png b/img/Aula 02/The Godfather.png new file mode 100644 index 0000000..a5812ef Binary files /dev/null and b/img/Aula 02/The Godfather.png differ diff --git a/img/Aula 02/The Good, the Bad and the Ugly.png b/img/Aula 02/The Good, the Bad and the Ugly.png new file mode 100644 index 0000000..f195cd3 Binary files /dev/null and b/img/Aula 02/The Good, the Bad and the Ugly.png differ diff --git a/img/Aula 02/The Lord of the Rings - The Fellowship of the Ring.png b/img/Aula 02/The Lord of the Rings - The Fellowship of the Ring.png new file mode 100644 index 0000000..09f1337 Binary files /dev/null and b/img/Aula 02/The Lord of the Rings - The Fellowship of the Ring.png differ diff --git a/img/Aula 02/The Lord of the Rings - The Return of the King.png b/img/Aula 02/The Lord of the Rings - The Return of the King.png new file mode 100644 index 0000000..4886613 Binary files /dev/null and b/img/Aula 02/The Lord of the Rings - The Return of the King.png differ diff --git a/img/Aula 02/The Shawshank Redemption.png b/img/Aula 02/The Shawshank Redemption.png new file mode 100644 index 0000000..6b0ca5f Binary files /dev/null and b/img/Aula 02/The Shawshank Redemption.png differ diff --git a/img/Aula 02/The Terminal List.png b/img/Aula 02/The Terminal List.png new file mode 100644 index 0000000..1bf1e00 Binary files /dev/null and b/img/Aula 02/The Terminal List.png differ diff --git a/img/Aula 02/Thor - Love and Thunder.png b/img/Aula 02/Thor - Love and Thunder.png new file mode 100644 index 0000000..8f470fc Binary files /dev/null and b/img/Aula 02/Thor - Love and Thunder.png differ diff --git a/img/Aula 02/Top Gun - Maverick.png b/img/Aula 02/Top Gun - Maverick.png new file mode 100644 index 0000000..041cd98 Binary files /dev/null and b/img/Aula 02/Top Gun - Maverick.png differ diff --git a/img/Aula 03/12 Angry Men.png b/img/Aula 03/12 Angry Men.png new file mode 100644 index 0000000..75e697a Binary files /dev/null and b/img/Aula 03/12 Angry Men.png differ diff --git a/img/Aula 03/Find the Man in the Moon.png b/img/Aula 03/Find the Man in the Moon.png new file mode 100644 index 0000000..1fb42ad Binary files /dev/null and b/img/Aula 03/Find the Man in the Moon.png differ diff --git a/img/Aula 03/M51 - The Whirlpool Galaxy from Hubble.png b/img/Aula 03/M51 - The Whirlpool Galaxy from Hubble.png new file mode 100644 index 0000000..8374854 Binary files /dev/null and b/img/Aula 03/M51 - The Whirlpool Galaxy from Hubble.png differ diff --git a/img/Aula 03/Pulp Fiction.png b/img/Aula 03/Pulp Fiction.png new file mode 100644 index 0000000..7455bc0 Binary files /dev/null and b/img/Aula 03/Pulp Fiction.png differ diff --git a/img/Aula 03/Satellites Behind Pinnacles.png b/img/Aula 03/Satellites Behind Pinnacles.png new file mode 100644 index 0000000..0a2835e Binary files /dev/null and b/img/Aula 03/Satellites Behind Pinnacles.png differ diff --git a/img/Aula 03/Schindler's List.png b/img/Aula 03/Schindler's List.png new file mode 100644 index 0000000..0153920 Binary files /dev/null and b/img/Aula 03/Schindler's List.png differ diff --git a/img/Aula 03/The Dark Knight.png b/img/Aula 03/The Dark Knight.png new file mode 100644 index 0000000..140f073 Binary files /dev/null and b/img/Aula 03/The Dark Knight.png differ diff --git a/img/Aula 03/The Godfather - Part II.png b/img/Aula 03/The Godfather - Part II.png new file mode 100644 index 0000000..4e4fd8e Binary files /dev/null and b/img/Aula 03/The Godfather - Part II.png differ diff --git a/img/Aula 03/The Godfather.png b/img/Aula 03/The Godfather.png new file mode 100644 index 0000000..0f365a2 Binary files /dev/null and b/img/Aula 03/The Godfather.png differ diff --git a/img/Aula 03/The Good, the Bad and the Ugly.png b/img/Aula 03/The Good, the Bad and the Ugly.png new file mode 100644 index 0000000..096cd75 Binary files /dev/null and b/img/Aula 03/The Good, the Bad and the Ugly.png differ diff --git a/img/Aula 03/The Lord of the Rings - The Fellowship of the Ring.png b/img/Aula 03/The Lord of the Rings - The Fellowship of the Ring.png new file mode 100644 index 0000000..cf7f52b Binary files /dev/null and b/img/Aula 03/The Lord of the Rings - The Fellowship of the Ring.png differ diff --git a/img/Aula 03/The Lord of the Rings - The Return of the King.png b/img/Aula 03/The Lord of the Rings - The Return of the King.png new file mode 100644 index 0000000..2ee15eb Binary files /dev/null and b/img/Aula 03/The Lord of the Rings - The Return of the King.png differ diff --git a/img/Aula 03/The Shawshank Redemption.png b/img/Aula 03/The Shawshank Redemption.png new file mode 100644 index 0000000..54b8342 Binary files /dev/null and b/img/Aula 03/The Shawshank Redemption.png differ diff --git a/img/Aula 04/Java.png b/img/Aula 04/Java.png new file mode 100644 index 0000000..e8e34db Binary files /dev/null and b/img/Aula 04/Java.png differ diff --git a/img/Aula 04/JavaScript.png b/img/Aula 04/JavaScript.png new file mode 100644 index 0000000..4e41b13 Binary files /dev/null and b/img/Aula 04/JavaScript.png differ diff --git a/img/Aula 04/Kotlin.png b/img/Aula 04/Kotlin.png new file mode 100644 index 0000000..0bb329d Binary files /dev/null and b/img/Aula 04/Kotlin.png differ diff --git a/img/Aula 04/PHP.png b/img/Aula 04/PHP.png new file mode 100644 index 0000000..6d26553 Binary files /dev/null and b/img/Aula 04/PHP.png differ diff --git a/img/Aula 04/Ruby.png b/img/Aula 04/Ruby.png new file mode 100644 index 0000000..faf9e8e Binary files /dev/null and b/img/Aula 04/Ruby.png differ diff --git a/img/Aula 05/Java.png b/img/Aula 05/Java.png new file mode 100644 index 0000000..aa8a098 Binary files /dev/null and b/img/Aula 05/Java.png differ diff --git a/img/Aula 05/JavaScript.png b/img/Aula 05/JavaScript.png new file mode 100644 index 0000000..a8a5873 Binary files /dev/null and b/img/Aula 05/JavaScript.png differ diff --git a/img/Aula 05/Kotlin.png b/img/Aula 05/Kotlin.png new file mode 100644 index 0000000..5578521 Binary files /dev/null and b/img/Aula 05/Kotlin.png differ diff --git a/img/Aula 05/Menu.png b/img/Aula 05/Menu.png new file mode 100644 index 0000000..e74b692 Binary files /dev/null and b/img/Aula 05/Menu.png differ diff --git a/img/Aula 05/Ruby.png b/img/Aula 05/Ruby.png new file mode 100644 index 0000000..5f98a12 Binary files /dev/null and b/img/Aula 05/Ruby.png differ diff --git a/src/API.java b/src/API.java new file mode 100644 index 0000000..ca50bbe --- /dev/null +++ b/src/API.java @@ -0,0 +1,28 @@ +public enum API +{ + IMDB_TOP_MOVIES("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/TopMovies.json", new ExtratorDeConteudoDoIMDB()), + IMDB_TOP_TVS("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/TopTVs.json", new ExtratorDeConteudoDoIMDB()), + IMDB_MOST_POPULAR_MOVIES("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/MostPopularMovies.json", new ExtratorDeConteudoDoIMDB()), + IMDB_MOST_POPULAR_TVS("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/MostPopularTVs.json", new ExtratorDeConteudoDoIMDB()), + NASA("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&start_date=2022-06-12&end_date=2022-06-14", new ExtratorDeConteudoDaNasa()), + LINGUAGENS("https://alura-linguagens-simaswilliam2.fly.dev/linguagens", new ExtratorDeConteudoLinguagens()); + + private String url; + private ExtratorDeConteudo extratorDeConteudo; + + API(String url, ExtratorDeConteudo extratorDeConteudo) + { + this.url = url; + this.extratorDeConteudo = extratorDeConteudo; + } + + public String getUrl() + { + return url; + } + + public ExtratorDeConteudo getExtrator() + { + return extratorDeConteudo; + } +} diff --git a/src/App.java b/src/App.java new file mode 100644 index 0000000..6a117e0 --- /dev/null +++ b/src/App.java @@ -0,0 +1,92 @@ +import java.io.InputStream; +import java.net.URL; +import java.util.List; +import java.util.Scanner; + +public class App +{ + public static void main(String[] args) throws Exception + { + limparTerminal(); + Scanner scanner = new Scanner(System.in); + + int op = 0; + do + { + System.out.println(FormataTerminal.formatar("Selecione a API desejada para gerar as figurinhas: ",new String[]{FormataTerminal.TEXTO_CIANO})); + System.out.println(FormataTerminal.formatar("1",new String[]{FormataTerminal.TEXTO_CIANO}) + " - TopMovies IMDB"); + System.out.println(FormataTerminal.formatar("2",new String[]{FormataTerminal.TEXTO_CIANO}) + " - TopTVs IMDB"); + System.out.println(FormataTerminal.formatar("3",new String[]{FormataTerminal.TEXTO_CIANO}) + " - MostPopularMovies IMDB"); + System.out.println(FormataTerminal.formatar("4",new String[]{FormataTerminal.TEXTO_CIANO}) + " - MostPopularTVs IMDB"); + System.out.println(FormataTerminal.formatar("5",new String[]{FormataTerminal.TEXTO_CIANO}) + " - Nasa"); + System.out.println(FormataTerminal.formatar("6",new String[]{FormataTerminal.TEXTO_CIANO}) + " - Linguagens"); + System.out.println(FormataTerminal.formatar("0",new String[]{FormataTerminal.TEXTO_CIANO}) + " - Sair"); + System.out.print(FormataTerminal.formatar("Escolha uma opção: ",new String[]{FormataTerminal.TEXTO_CIANO})); + + op = scanner.nextInt(); + + switch(op) + { + case 0: break; + case 1: gerarFigurinhas(API.IMDB_TOP_MOVIES,scanner); break; + case 2: gerarFigurinhas(API.IMDB_TOP_TVS,scanner); break; + case 3: gerarFigurinhas(API.IMDB_MOST_POPULAR_MOVIES,scanner); break; + case 4: gerarFigurinhas(API.IMDB_MOST_POPULAR_TVS,scanner); break; + case 5: gerarFigurinhas(API.NASA,scanner); break; + case 6: gerarFigurinhas(API.LINGUAGENS,scanner); break; + default: System.out.println("Opção inválida!"); + } + + limparTerminal(); + }while(op!=0); + + scanner.close(); + } + + private static void limparTerminal() throws Exception + { + if (System.getProperty("os.name").contains("Windows")) + { + new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); + } + else + { + Runtime.getRuntime().exec("clear"); + } + } + + private static void gerarFigurinhas(API api, Scanner scanner) throws Exception + { + limparTerminal(); + String url = api.getUrl(); + ExtratorDeConteudo extrator = api.getExtrator(); + + if(url!=null) + { + ClienteHttp http = new ClienteHttp(); + String json = http.buscarDados(url); + + // Extrair só os dados que interessam (Título, poster, classificação) + List listaDeConteudos = extrator.extrairConteudos(json); + + //Exibir e manipular os dados. + for (Conteudo conteudo : listaDeConteudos) + { + System.out.println(FormataTerminal.formatar(conteudo.titulo(), new String[]{FormataTerminal.NEGRITO,FormataTerminal.TEXTO_AMARELO})); + + String urlImagem = conteudo.urlImagem(); + System.out.print(FormataTerminal.formatar("Imagem: ", new String[]{FormataTerminal.NEGRITO,FormataTerminal.TEXTO_VERMELHO})); + System.out.println(FormataTerminal.formatar(urlImagem, new String[]{FormataTerminal.NEGRITO,FormataTerminal.TEXTO_CIANO})); + System.out.println(""); + + InputStream inputStream = new URL(urlImagem).openStream(); + + + GeradoraDeFigurinhas geradoraDeFigurinhas = new GeradoraDeFigurinhas(); + geradoraDeFigurinhas.cria(inputStream, conteudo.titulo().replace(":", " -") +".png", conteudo.titulo()); + } + } + + System.out.println("Geração concluída!"); + } +} diff --git a/src/ClienteHttp.java b/src/ClienteHttp.java new file mode 100644 index 0000000..4589a07 --- /dev/null +++ b/src/ClienteHttp.java @@ -0,0 +1,31 @@ +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; + +public class ClienteHttp +{ + public String buscarDados(String url) + { + String body = ""; + + try + { + URI endereco = URI.create(url); + + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder(endereco).GET().build(); + + HttpResponse response = client.send(request, BodyHandlers.ofString()); + body = response.body(); + } + catch (IOException | InterruptedException e) + { + throw new ClienteHttpException("Falha ao consultar a API"); + } + + return body; + } +} diff --git a/src/ClienteHttpException.java b/src/ClienteHttpException.java new file mode 100644 index 0000000..13594b5 --- /dev/null +++ b/src/ClienteHttpException.java @@ -0,0 +1,8 @@ + +public class ClienteHttpException extends RuntimeException +{ + public ClienteHttpException(String mensagem) + { + super(mensagem); + } +} diff --git a/src/Conteudo.java b/src/Conteudo.java new file mode 100644 index 0000000..d162141 --- /dev/null +++ b/src/Conteudo.java @@ -0,0 +1,4 @@ +public record Conteudo(String titulo, String urlImagem) +{ + +} diff --git a/src/ExtratorDeConteudo.java b/src/ExtratorDeConteudo.java new file mode 100644 index 0000000..267b941 --- /dev/null +++ b/src/ExtratorDeConteudo.java @@ -0,0 +1,6 @@ +import java.util.List; + +public interface ExtratorDeConteudo +{ + List extrairConteudos(String json); +} diff --git a/src/ExtratorDeConteudoDaNasa.java b/src/ExtratorDeConteudoDaNasa.java new file mode 100644 index 0000000..343823b --- /dev/null +++ b/src/ExtratorDeConteudoDaNasa.java @@ -0,0 +1,16 @@ +import java.util.List; +import java.util.Map; + +public class ExtratorDeConteudoDaNasa implements ExtratorDeConteudo +{ + + public List extrairConteudos(String json) + { + MyJsonParser parser = new MyJsonParser(); + List> listaDeAtributos = parser.parse(json, new String[]{"title","url"}); + + return listaDeAtributos.stream().map(atributos-> + new Conteudo(atributos.get("title"), atributos.get("url")) + ).toList(); + } +} diff --git a/src/ExtratorDeConteudoDoIMDB.java b/src/ExtratorDeConteudoDoIMDB.java new file mode 100644 index 0000000..d074c8f --- /dev/null +++ b/src/ExtratorDeConteudoDoIMDB.java @@ -0,0 +1,15 @@ +import java.util.List; +import java.util.Map; + +public class ExtratorDeConteudoDoIMDB implements ExtratorDeConteudo +{ + public List extrairConteudos(String json) + { + MyJsonParser parser = new MyJsonParser(); + List> listaDeAtributos = parser.parse(json, new String[]{"title","image"}); + + return listaDeAtributos.stream().map(atributos-> + new Conteudo(atributos.get("title"), atributos.get("image")) + ).toList(); + } +} diff --git a/src/ExtratorDeConteudoLinguagens.java b/src/ExtratorDeConteudoLinguagens.java new file mode 100644 index 0000000..bc987e8 --- /dev/null +++ b/src/ExtratorDeConteudoLinguagens.java @@ -0,0 +1,18 @@ +import java.util.List; +import java.util.Map; + +public class ExtratorDeConteudoLinguagens implements ExtratorDeConteudo +{ + + @Override + public List extrairConteudos(String json) + { + MyJsonParser parser = new MyJsonParser(); + List> listaDeAtributos = parser.parse(json, new String[]{"title","image"}); + + return listaDeAtributos.stream().map(atributos-> + new Conteudo(atributos.get("title"), atributos.get("image")) + ).toList(); + } + +} diff --git a/src/FormataTerminal.java b/src/FormataTerminal.java new file mode 100644 index 0000000..17317b0 --- /dev/null +++ b/src/FormataTerminal.java @@ -0,0 +1,40 @@ +public class FormataTerminal +{ + public static final String NEGRITO = "\u001b[1m"; + public static final String ITALICO = "\u001b[3m"; + public static final String SUBLINHADO = "\u001b[4m"; + public static final String PISCANDO = "\u001b[5m"; + public static final String INVERTIDO = "\u001b[7m"; + public static final String RISCADO = "\u001b[9m"; + + public static final String TEXTO_PRETO = "\u001b[30m"; + public static final String TEXTO_VERMELHO = "\u001b[31m"; + public static final String TEXTO_VERDE = "\u001b[32m"; + public static final String TEXTO_AMARELO = "\u001b[33m"; + public static final String TEXTO_AZUL = "\u001b[34m"; + public static final String TEXTO_MAGENTA = "\u001b[35m"; + public static final String TEXTO_CIANO = "\u001b[36m"; + public static final String TEXTO_BRANCO = "\u001b[37m"; + + public static final String FUNDO_PRETO = "\u001b[40m"; + public static final String FUNDO_VERMELHO = "\u001b[41m"; + public static final String FUNDO_VERDE = "\u001b[42m"; + public static final String FUNDO_AMARELO = "\u001b[43m"; + public static final String FUNDO_AZUL = "\u001b[44m"; + public static final String FUNDO_MAGENTA = "\u001b[45m"; + public static final String FUNDO_CIANO = "\u001b[46m"; + public static final String FUNDO_BRANCO = "\u001b[47m"; + + public static String formatar(String texto, String[] formatos) + { + String retorno = ""; + for (String formato : formatos) + { + retorno += formato; + } + retorno+=texto; + retorno+="\u001b[m"; + + return retorno; + } +} diff --git a/src/GeradoraDeFigurinhas.java b/src/GeradoraDeFigurinhas.java new file mode 100644 index 0000000..c1adc38 --- /dev/null +++ b/src/GeradoraDeFigurinhas.java @@ -0,0 +1,132 @@ +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.InputStream; + +import javax.imageio.ImageIO; + +public class GeradoraDeFigurinhas +{ + public void cria(InputStream inputStream, String nomeArquivo, String texto) throws Exception + { + texto = texto.toUpperCase(); + + // leitura da imagem + BufferedImage imagemOriginal = ImageIO.read(inputStream); + + String[] partes = texto.split(":"); + if(partes.length == 1) + { + partes = texto.split(","); + } + + int fontSize = obterTamanhoFonte(partes,(Graphics2D)imagemOriginal.getGraphics(),imagemOriginal.getWidth()-40); + int alturaLinha = obterTamanhoLinha(partes,(Graphics2D)imagemOriginal.getGraphics(),fontSize); + int espacoLegenda = partes.length * alturaLinha + 20; + + // cria nova imagem em memória com transparência e com tamanho novo + int largura = imagemOriginal.getWidth(); + int altura = imagemOriginal.getHeight(); + int novaAltura = altura + espacoLegenda; + + BufferedImage novaImagem = new BufferedImage(largura, novaAltura, BufferedImage.TRANSLUCENT); + + //copiar a imagem original para nova imagem (em memória) + Graphics2D graphics = (Graphics2D) novaImagem.getGraphics(); + graphics.drawImage(imagemOriginal, 0, 0, null); + + // Configurar a fonte e cor + Font fonte = new Font("Comic Sans MS", Font.BOLD, fontSize); + graphics.setColor(Color.RED); + graphics.setFont(fonte); + + int[] espacamentosSuperiores = new int[partes.length]; + int[] espacamentosLaterais = new int[partes.length]; + + //Calculando espaçamento para centralizar o texto + for (int i=0; ilarguraMaxima) + { + parar = true; + } + } + + fontSize++; + } + + return fontSize-1; + } + + private int obterTamanhoLinha(String[] partes, Graphics2D graphics, int fontSize) + { + double alturaLinha = 0; + // Configurar a fonte e cor + Font fonte = new Font("Comic Sans MS", Font.BOLD, fontSize); + graphics.setFont(fonte); + + //Calculando espaçamento para centralizar o texto + for (int i=0; ialturaLinha) + { + alturaLinha = alturaTexto; + } + } + + return (int) alturaLinha; + } +} diff --git a/src/MyJsonParser.java b/src/MyJsonParser.java new file mode 100644 index 0000000..e9ad3bf --- /dev/null +++ b/src/MyJsonParser.java @@ -0,0 +1,44 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +//Classe desenvolvida para fazer o parse das imagens da nasa +//Sugestão encontrada em https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java +public class MyJsonParser +{ + public List> parse(String json, String[] fields) + { + List> mapList = new ArrayList<>(); + + int index =0; + int oldIndex = 0; + String jSonPart=""; + + index = json.indexOf("[", 0)+1; + oldIndex = json.indexOf("[", 0)+1; + + do + { + index = json.indexOf("}", oldIndex); + if(index>=0 && oldIndex>=0) + { + jSonPart = json.substring(oldIndex, index+1); + JsonObject jsonObject = new JsonParser().parse(jSonPart).getAsJsonObject(); + + Map mapItem = new HashMap<>(); + for (String field : fields) + { + mapItem.put(field, jsonObject.get(field).getAsString()); + } + + mapList.add(mapItem); + } + oldIndex = json.indexOf("{", index); + }while(index>=0 && oldIndex>=0); + + return mapList; + } +}