Skip to content

Commit

Permalink
Add validation by url pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
EkaterinaKomar committed Aug 31, 2023
1 parent bfa4c1f commit ef618d1
Showing 1 changed file with 51 additions and 29 deletions.
80 changes: 51 additions & 29 deletions src/main/java/org/verapdf/rest/resources/ValidateResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,17 @@
*/
package org.verapdf.rest.resources;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.NotSupportedException;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.verapdf.component.ComponentDetails;
import org.verapdf.core.ModelParsingException;
import org.verapdf.core.VeraPDFException;
import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider;
import org.verapdf.pdfa.Foundries;
import org.verapdf.pdfa.PDFAParser;
import org.verapdf.pdfa.PDFAValidator;
import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider;
import org.verapdf.pdfa.flavours.PDFAFlavour;
import org.verapdf.pdfa.results.ValidationResult;
import org.verapdf.pdfa.results.ValidationResults;
Expand All @@ -55,7 +28,20 @@
import org.verapdf.processor.reports.BatchSummary;
import org.verapdf.processor.reports.Reports;
import org.verapdf.processor.reports.ValidationReport;
import org.verapdf.report.HTMLReport;

import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import java.io.*;
import java.net.URL;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.List;

/**
* @author <a href="mailto:[email protected]">Carl Wilson</a>
Expand Down Expand Up @@ -109,6 +95,18 @@ public static InputStream validateXml(@PathParam("profileId") String profileId,
return validate(uploadedInputStream, profileId, FormatOption.XML);
}

@POST
@Path("/url/{profileId}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML })
public static InputStream validateXml(@PathParam("profileId") String profileId,
@FormDataParam("url") String urlLink)
throws VeraPDFException, IOException {
InputStream uploadedInputStream = new URL(urlLink).openStream();

return validate(uploadedInputStream, profileId, FormatOption.XML);
}

/**
* @param profileId
* the String id of the Validation profile
Expand Down Expand Up @@ -138,6 +136,18 @@ public static InputStream validateJson(@PathParam("profileId") String profileId,
return validate(uploadedInputStream, profileId, FormatOption.JSON);
}

@POST
@Path("/url/{profileId}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
public static InputStream validateJson(@PathParam("profileId") String profileId,
@FormDataParam("url") String urlLink)
throws VeraPDFException, IOException {
InputStream uploadedInputStream = new URL(urlLink).openStream();

return validate(uploadedInputStream, profileId, FormatOption.JSON);
}

/**
* @param profileId
* the String id of the Validation profile
Expand Down Expand Up @@ -165,6 +175,18 @@ public static InputStream validateHtml(@PathParam("profileId") String profileId,
return validate(uploadedInputStream, profileId, FormatOption.HTML);
}

@POST
@Path("/url/{profileId}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.TEXT_HTML })
public static InputStream validateHtml(@PathParam("profileId") String profileId,
@FormDataParam("url") String urlLink)
throws VeraPDFException, IOException {
InputStream uploadedInputStream = new URL(urlLink).openStream();

return validate(uploadedInputStream, profileId, FormatOption.HTML);
}

/**
* @param profileId
* the String id of the Validation profile (auto, 1b, 1a, 2b,
Expand Down

0 comments on commit ef618d1

Please sign in to comment.