Permalink
Browse files

Afegit tot el codi, això ja comença a furular.

  • Loading branch information...
lant lant
lant authored and lant committed Mar 18, 2010
1 parent cbe3ddb commit 86154b7b7cb816994800e5f38799bf14a563f3c9
View
@@ -0,0 +1,5 @@
+*.class
+*.jar
+.project
+.classpath
+doc/javadoc
View
@@ -0,0 +1,13 @@
+I don't like licenses. They bore me to death.
+
+But as i'm releasing this stuff to the wild:
+
+/*
+ * --------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phlegias@gmail.com> wrote this file. As long as you retain this notice
+ * you can do whatever you want with this stuff. If we meet some day, and
+ * you think this stuff is worth it, you can buy me a beer in return.
+ * --------------------------------------------------------------------
+ */
+
View
8 README
@@ -0,0 +1,8 @@
+idescat-java
+-------------
+
+Llibreria no oficial per utilitzar la API de Idescat mitjançant Java.
+
+Podeu trobar la documentació de la llibreria a: http://www.idescat.cat/api/
+
+i em podeu contactar a mi mitjançant les meves dades de contacte, que trobareu a http://www.loststone.net/lant
View
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+version = 0.0.1
+bin.includes = META-INF/,\
+ .
View
@@ -0,0 +1,82 @@
+<project name="idescat-java" basedir="." default="main" xmlns:ivy="antlib:org.apache.ivy.ant">
+
+<property name="src.dir" value="src"/>
+<property name="build.dir" value="build"/>
+<property name="classes.dir" value="${build.dir}/classes"/>
+<property name="jar.dir" value="${build.dir}/jar"/>
+<!--<property name="main-class" value="net.loststone.i.client.Client"/> -->
+<property name="lib.dir" value="lib"/>
+<property name="javadoc.dir" value="doc/javadoc"/>
+<property name="junit.report.dir" location="${build.dir}/junit"/>
+<property name="test.dir" location="test"/>
+
+<path id="classpath">
+ <fileset dir="${lib.dir}" includes="**/*.jar"/>
+</path>
+
+<target name="clean">
+ <delete dir="build"/>
+</target>
+
+<target name="resolve" description="--> retreive dependencies with ivy">
+ <ivy:retrieve/>
+</target>
+
+<target name="compile" depends="resolve">
+ <mkdir dir="${classes.dir}"/>
+ <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
+ <javac srcdir="${test.dir}" destdir="${classes.dir}" classpathref="classpath"/>
+</target>
+
+<target name="jar" depends="compile">
+ <mkdir dir="${jar.dir}"/>
+ <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" excludes="**/*Test*">
+ <manifest>
+ <attribute name="Main-Class" value="${main-class}"/>
+ </manifest>
+ </jar>
+</target>
+
+<target name="clean-build" depends="clean,jar"/>
+<target name="main" depends="clean,jar"/>
+
+<target name="javadoc">
+<mkdir dir="${javadoc.dir}"/>
+
+<javadoc packagenames="net.loststone.idescat.*"
+sourcepath="src"
+defaultexcludes="yes"
+destdir="${javadoc.dir}"
+author="true"
+version="true"
+use="true"
+windowtitle="Idescat Java API">
+</javadoc>
+</target>
+
+ <target name="test" depends="compile" description="Run the unit tests">
+ <delete dir="${junit.report.dir}"/>
+ <mkdir dir="${junit.report.dir}"/>
+
+
+ <junit printsummary="yes" failureproperty="testfailed" showoutput="true">
+ <classpath>
+ <pathelement location="${classes.dir}"/>
+ <path refid="classpath"/>
+ </classpath>
+
+ <formatter type="plain" usefile="true"/>
+
+ <batchtest todir="${junit.report.dir}" fork="yes">
+ <fileset dir="${test.dir}">
+ <include name="**/*Test*.java"/>
+ <exclude name="nothing"/>
+ </fileset>
+ </batchtest>
+
+ </junit>
+
+ <fail if="testfailed" message="Some test(s) failed. See '${junit.report.dir}' for details."/>
+ </target>
+
+</project>
View
@@ -0,0 +1,2 @@
+0.0.1 (17/03/2010)
+- Comencem!
View
@@ -0,0 +1,8 @@
+<ivy-module version="2.0">
+ <info organisation="org.loststone" module="toodledo-java"/>
+ <dependencies>
+ <dependency org="commons-httpclient" name="commons-httpclient" rev="3.1"/>
+ <dependency org="joda-time" name="joda-time" rev="1.6"/>
+ <dependency org="junit" name="junit" rev="4.7"/>
+ </dependencies>
+</ivy-module>
@@ -0,0 +1,18 @@
+package net.loststone.idescat;
+
+import net.loststone.idescat.common.Idioma;
+
+public abstract class AbstractFactory {
+
+ protected String lang;
+ protected String versio;
+ protected String format;
+ protected String codifcacio;
+
+
+ public abstract IndicadorsRequest getIndicadorsRequest();
+
+ public void setLang(Idioma idioma) {
+
+ }
+}
@@ -0,0 +1,59 @@
+package net.loststone.idescat;
+
+import java.io.IOException;
+
+import net.loststone.idescat.common.Codificacio;
+import net.loststone.idescat.common.Format;
+import net.loststone.idescat.common.Idioma;
+import net.loststone.idescat.common.Versio;
+
+import org.apache.commons.httpclient.HttpException;
+
+public abstract class AbstractRequest {
+
+ private static final String PARAM_LANG = "?lang=";
+ private static final String PARAM_CODIFICACIO = "?enc=";
+
+ protected InnerRequest innerRequest;
+
+ protected String lang;
+ protected String versio;
+ protected String format;
+ protected String codifcacio;
+
+ public AbstractRequest(InnerRequest innerRequest) {
+ this.innerRequest = innerRequest;
+ this.format = ".xml";
+ this.versio = "v1";
+ }
+
+ public void setLang(Idioma idioma) {
+ this.lang = PARAM_LANG+idioma.indicador();
+ }
+
+ public void setVersio(Versio versio) {
+ this.versio = versio.nom();
+ }
+
+ public void setFormat(Format format) {
+ this.format = "."+format.nom();
+ }
+
+ public void setCodificacio(Codificacio codificacio) {
+ this.codifcacio = PARAM_CODIFICACIO + codificacio.nom();
+ }
+
+ public void get() throws HttpException, IOException {
+ this.innerRequest.get(this.getUrl());
+ }
+
+ public String getResult() throws IOException {
+ return this.innerRequest.getResult();
+ }
+
+ public boolean getSuccess() {
+ return this.innerRequest.getSuccess();
+ }
+
+ public abstract String getUrl();
+}
@@ -0,0 +1,11 @@
+package net.loststone.idescat;
+
+public class HttpFactory extends AbstractFactory {
+
+ @Override
+ public IndicadorsRequest getIndicadorsRequest() {
+ IndicadorsRequest indReq = new IndicadorsRequest(new HttpInnerRequest());
+ return indReq;
+ }
+
+}
@@ -0,0 +1,43 @@
+package net.loststone.idescat;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+public class HttpInnerRequest implements InnerRequest {
+
+ HttpClient httpClient;
+ HttpMethod method;
+ int statusCode;
+ boolean executada;
+
+ public HttpInnerRequest() {
+ httpClient = new HttpClient();
+ executada = false;
+ }
+
+ public void get(String url) throws HttpException, IOException {
+ method = new GetMethod(url);
+ executada = true;
+ httpClient.executeMethod(method);
+ }
+
+ public String getResult() throws IOException {
+ if (executada)
+ return new String(method.getResponseBody());
+ else
+ return null;
+ }
+
+ public boolean getSuccess() {
+ if (executada)
+ return (statusCode == HttpStatus.SC_OK);
+ else
+ return false;
+ }
+
+}
@@ -0,0 +1,30 @@
+package net.loststone.idescat;
+
+public class IndicadorsRequest extends AbstractRequest {
+
+ public IndicadorsRequest(InnerRequest innerRequest) {
+ super(innerRequest);
+ }
+
+ @Override
+ public String getResult() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean getSuccess() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public String getUrl() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ // TODO falten els concrets
+
+
+}
@@ -0,0 +1,18 @@
+package net.loststone.idescat;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HttpException;
+
+/**
+ * Aquesta interficie Žs la que han d'implementar les classes que fan el request
+ * HTTP en si.
+ * @author lant
+ *
+ */
+public interface InnerRequest {
+ void get(String url) throws HttpException, IOException;
+ String getResult() throws IOException;
+ boolean getSuccess();
+}
+
@@ -0,0 +1,15 @@
+package net.loststone.idescat.common;
+
+public enum Codificacio {
+ UTF8("utf-8"), ISO88591("iso-8859-1");
+
+ private String nom;
+
+ Codificacio(String nom) {
+ this.nom = nom;
+ }
+
+ public String nom() {
+ return this.nom;
+ }
+}
@@ -0,0 +1,15 @@
+package net.loststone.idescat.common;
+
+public enum Format {
+ PHP("php"), XML("xml"), JSON("json");
+
+ private String nom;
+
+ Format(String nom) {
+ this.nom = nom;
+ }
+
+ public String nom() {
+ return nom;
+ }
+}
@@ -0,0 +1,19 @@
+package net.loststone.idescat.common;
+
+public enum Idioma {
+ EN ("en","Angls"),
+ CA ("ca","Catalˆ"),
+ ES ("es","Espanyol");
+
+ private String m;
+ private String ll;
+
+
+ Idioma(String m, String ll) {
+ this.m = m;
+ this.ll = ll;
+ }
+
+ public String indicador() { return m; }
+ public String nom() { return ll; }
+}
@@ -0,0 +1,15 @@
+package net.loststone.idescat.common;
+
+public enum Versio {
+ V1("v1");
+
+ private final String nom;
+
+ Versio(String vers) {
+ this.nom = vers;
+ }
+
+ public String nom() {
+ return nom;
+ }
+}

0 comments on commit 86154b7

Please sign in to comment.