GroupDocsGists
10/24/2017 - 1:11 PM

Examples-src-main-java-com-groupdocs-signature-examples-CommonUtilities-CommonUtilitiesClass.java

// For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-Java
public class CommonUtilities {
	// Storage path\
	public static final String storagePath = (System.getProperty("user.dir") + "\\Data\\Storage\\");
	// License path
	public static final String licensePath = (System.getProperty("user.dir")
			+ "\\Data\\Storage\\GroupDocs.Total.Java.lic");
	// Output path
	public static final String outputPath = (System.getProperty("user.dir") + "\\Data\\Output\\");
	// Output image path
	public static final String outputImagePath = (System.getProperty("user.dir") + "\\Data\\Output\\Images\\");
	//Certificates path
	public static final String certificatePath = (System.getProperty("user.dir") + "\\Data\\Certificates\\");
	// Image path
	public static final String imagePath = (System.getProperty("user.dir") + "\\Data\\Images\\");

	/*
	 * get imagep ath
	 */
	public static String getImagesPath(String imageName) {
		return imagePath + imageName;
	}
	/*
	 * get output path
	 */
	public static String getOutputPath(String fileName) {
		return outputPath + fileName;
	}
	/*
	 * get storage path
	 */
	public static String getStoragePath(String outputFileName) {
		return storagePath + outputFileName;
	}
	/*
	 * Takes digitial certificate file and set path
	 */
	public static String getCertificatePath(String fileName){
		return certificatePath + fileName;
	}
	/*
	 * apply license 
	 */
	public static void applyLicense() throws IOException {
		License license = new License();
		// Set license
		license.setLicense(licensePath);
	}
	/*
	 * apply license from stream
	 */
	public static void applyLicenseFromStream() throws IOException {
		// Obtain license stream
		InputStream licenseStream = new FileInputStream(licensePath);
		// Instantiate GroupDocs.Signature handler
		License license = new License();
		// setup license
		license.setLicense(licenseStream);
	}

	public static SignatureConfig getConfiguration() {
		try {
			SignatureConfig signConfig = new SignatureConfig(); 
			signConfig.setStoragePath(storagePath);
			signConfig.setOutputPath(outputPath);
			signConfig.setImagesPath(outputImagePath);
			return signConfig;

		} catch (Exception exp) {
			System.out.println("Exception: " + exp.getMessage());
			exp.printStackTrace();
			return null;
		}
	}
}