Skip to content

Commit 1f8252a

Browse files
authored
Merge pull request #26 from mendrika261/dev
Unidao integration
2 parents 0db7303 + 1d55532 commit 1f8252a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1450
-163
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package etu2024.framework.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.PARAMETER)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface FormObject {
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package etu2024.framework.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.PARAMETER)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface JsonObject {
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package etu2024.framework.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.PARAMETER)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface Object {
11+
}

.framework/dev_files/etu2024/framework/annotation/Url.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
@Target(ElementType.METHOD)
1212
public @interface Url {
1313
// Takes a string as a parameter to set the url
14-
public String url();
14+
String url();
15+
String method() default "GET";
1516
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package etu2024.framework.annotation;
2+
3+
import java.lang.annotation.Retention;
4+
import java.lang.annotation.RetentionPolicy;
5+
6+
@Retention(RetentionPolicy.RUNTIME)
7+
public @interface Xml {
8+
}

.framework/dev_files/etu2024/framework/core/File.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package etu2024.framework.core;
22

3-
import etu2024.framework.annotation.Auth;
43
import jakarta.servlet.http.Part;
54

65
import java.io.ByteArrayOutputStream;
6+
import java.io.FileOutputStream;
77
import java.io.IOException;
88
import java.io.InputStream;
99

@@ -22,6 +22,19 @@ public File(String name, String path, byte[] content) {
2222

2323
public File(Part filePart) throws IOException {
2424
setContent(File.partToByte(filePart));
25+
setName(getFileNameWithExtension(filePart));
26+
}
27+
28+
public String getFileNameWithExtension(Part part) {
29+
String contentDispositionHeader = part.getHeader("content-disposition");
30+
String[] elements = contentDispositionHeader.split(";");
31+
for (String element : elements) {
32+
if (element.trim().startsWith("filename")) {
33+
String fileName = element.substring(element.indexOf('=') + 1).trim().replace("\"", "");
34+
return new java.io.File(fileName).getName();
35+
}
36+
}
37+
return null;
2538
}
2639

2740
// To check if the file is ready to be used (if it has been uploaded)
@@ -52,6 +65,19 @@ public static byte[] partToByte(Part filePart) throws IOException {
5265
return bytes;
5366
}
5467

68+
public void uploadToFile(String filePath) throws IOException {
69+
java.io.File file = new java.io.File(filePath+getName());
70+
71+
// Create the file if it doesn't exist
72+
if (!file.exists()) {
73+
file.createNewFile();
74+
}
75+
76+
try (FileOutputStream fos = new FileOutputStream(file)) {
77+
fos.write(getContent());
78+
}
79+
}
80+
5581
// Getters and setters
5682
public String getName() {
5783
return name;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package etu2024.framework.servlet;
2+
3+
import jakarta.servlet.annotation.WebFilter;
4+
import jakarta.servlet.http.HttpServletResponse;
5+
6+
import java.io.IOException;
7+
8+
@WebFilter(asyncSupported = true, urlPatterns = { "/*" })
9+
public class CORSInterceptor implements Filter {
10+
11+
@Override
12+
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
13+
HttpServletResponse httpResponse = ((HttpServletResponse) servletResponse);
14+
15+
// Cors Parameters
16+
httpResponse.setHeader("Access-Control-Allow-Origin", "*");
17+
httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
18+
httpResponse.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers," +
19+
"Authorization, Origin, Access-Control-Request-Method, ngrok-skip-browser-warning");
20+
21+
filterChain.doFilter(servletRequest, servletResponse);
22+
}
23+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy