Subversion Repositories bacoAlunos

Compare Revisions

Ignore whitespace Rev 1830 → Rev 1845

/branches/v3/impl/src/java/jomm/utils/FilesUtils.java
1,6 → 1,11
package jomm.utils;
 
import org.apache.log4j.Logger;
 
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.util.zip.ZipEntry;
14,8 → 19,11
*/
public class FilesUtils
{
private static final Logger logger = Logger.getLogger(FilesUtils.class);
 
public static String getExtension(String filename)
{
 
String extension = "";
if(filename == null)
return extension;
230,6 → 238,47
return false;
}
 
/**
* Relative path without /
* @param path
* @return
*/
public static File getFileFromRelativeContextClassLoaderPath(String path)
{
File f;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 
URL fileUrl = classLoader.getResource(path);
 
 
try {
try {
f = new File(fileUrl.toURI());
System.out.println(f.toString());
System.out.println(f.getAbsolutePath());
return f;
} catch (URISyntaxException ex) {
logger.error(ex,ex);
return null;
} catch (IllegalArgumentException ex) {
 
 
try {
System.out.println("Decoding from fileUrl.getFile");
f = new File(URLDecoder.decode(fileUrl.getFile(), "UTF-8"));
System.out.println(f.getAbsolutePath());
return f;
} catch (Exception ex2) {
logger.error(ex2,ex2);
}
}
}catch (Throwable e) {
throw new IllegalArgumentException("The properties file "
+ fileUrl.toExternalForm() + " could not be loaded.", e);
}
return null;
}
 
public static void main(String[] args) throws Exception {
System.out.println(getMD5Checksum(new File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2")));
 
/branches/v3/impl/src/java/jomm/utils/PdfUtils.java
57,7 → 57,9
private static Map<String, Templates> templates = new Hashtable<String, Templates>();
 
private static Transformer getTransformer(String xsltFile, boolean cache) throws TransformerConfigurationException, IOException {
Templates tpl = null;
if(xsltFile.startsWith("/"))
xsltFile = xsltFile.substring(1);
Templates tpl = null;
if (cache)
tpl = templates.get(xsltFile);
if (tpl == null) {
67,7 → 69,19
if(xsltFile.indexOf("http://")>=0 || xsltFile.indexOf("ftp://")>=0 || xsltFile.indexOf("https://")>= 0)
xsltSource = new StreamSource(new File(url.getPath()));
else
xsltSource = new StreamSource(new File( url.getPath().replace("%20"," ")));
 
 
{
//PRIMEIRA VERSAO QUE FUNCIONA NO TOMCAT
//BASTA MUDAR AQUI AS CHAMADAS ESTAO BEM
//xsltSource = new StreamSource(new File( url.getPath().replace("%20"," ")));
System.out.println(xsltFile);
//xsltSource = new StreamSource(PdfUtils.class.getResourceAsStream(xsltFile));
//É necessário o caminho como um ficheiro para poder haver includes entre XSL's
//if(xsltFile.startsWith("/"))
// xsltFile = xsltFile.substring(1);
xsltSource = new StreamSource(FilesUtils.getFileFromRelativeContextClassLoaderPath(xsltFile));
}
tpl = transFact.newTemplates(xsltSource);
templates.put(xsltFile, tpl);
}