Subversion Repositories linid-dm

Compare Revisions

Rev 344 → Rev 345

/wui/branches/2.0/src/main/java/org/linid/dm/wui/t5lib/WuiCommonModule.java
38,6 → 38,7
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.InjectService;
import org.apache.tapestry5.ioc.annotations.SubModule;
import org.apache.tapestry5.ioc.annotations.Value;
55,6 → 56,7
import org.linid.dm.wui.t5lib.data.DropDownList;
import org.linid.dm.wui.t5lib.pages.SimplePropertyEditBlocks;
import org.linid.dm.wui.t5lib.services.AttributeValidatorAssignement;
import org.linid.dm.wui.t5lib.services.JpegFileFormatChecker;
import org.linid.dm.wui.t5lib.services.LdapEditorAnalyzer;
import org.linid.dm.wui.t5lib.services.LdapTypeAnalyzer;
import org.linid.dm.wui.t5lib.services.LdapViewerAnalyzer;
67,6 → 69,7
import org.linid.dm.wui.t5lib.services.impl.DefaultLocaleService;
import org.linid.dm.wui.t5lib.services.impl.ESchemaLdapOperatorTranslator;
import org.linid.dm.wui.t5lib.services.impl.IByteStringTranslator;
import org.linid.dm.wui.t5lib.services.impl.JpegFileFormatCheckerImpl;
import org.linid.dm.wui.t5lib.services.impl.PropertiesSymbolProvider;
import org.linid.dm.wui.validator.EqualsValidator;
import org.linid.dm.wui.validator.RequiredAttributeValidator;
320,4 → 323,8
return new DefaultLocaleService(persistentLocale, request);
}
public static void bind(ServiceBinder binder) {
binder.bind(JpegFileFormatChecker.class, JpegFileFormatCheckerImpl.class);
}
}
/wui/branches/2.0/src/main/java/org/linid/dm/wui/t5lib/services/impl/JpegFileFormatCheckerImpl.java New file
0,0 → 1,60
/* *********************************************************
* This file is a part of LinID Directory Manager.
* This software is a computer program whose purpose is
* to manage electronic identity thanks to LDAP directories.
*
* ==LICENSE NOTICE==
* LinID Directory Manager is a free software subjected to the
* ** GNU Affero Public License ** as published by the
* Free Software Foundation, ** version 3 ** of the license.
*
* By application to section 7 in the GNU Affero GPLv3,
* dynamic and static links do not extend license to other
* softwares.
*
* You can redistribute and/or modify since you respect
* the term of the license.
*
* NOTICE : THIS LICENSE IS FREE OF CHARGE AND THE SOFTWARE
* IS DISTRIBUTED WITHOUT ANY WARRANTIES OF ANY KIND
*
* ==LICENSE NOTICE==
*
* (c) 2008-2010 Linagora - http://linagora.com/
********************************************************* */
package org.linid.dm.wui.t5lib.services.impl;
 
import java.io.IOException;
import java.io.InputStream;
 
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.jpeg.JpegParser;
import org.apache.tika.sax.BodyContentHandler;
import org.linid.dm.wui.t5lib.services.JpegFileFormatChecker;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
 
public class JpegFileFormatCheckerImpl implements JpegFileFormatChecker {
private JpegParser parser;
 
public JpegFileFormatCheckerImpl() {
parser = new JpegParser();
}
 
@Override
public boolean check(InputStream stream) throws IOException {
try {
Metadata metadata = new Metadata();
ContentHandler handler = new BodyContentHandler();
parser.parse(stream, handler, metadata, null);
} catch (SAXException e) {
return false;
} catch (TikaException e) {
return false;
}
return true;
}
 
}
/wui/branches/2.0/src/main/java/org/linid/dm/wui/t5lib/services/JpegFileFormatChecker.java New file
0,0 → 1,37
/* *********************************************************
* This file is a part of LinID Directory Manager.
* This software is a computer program whose purpose is
* to manage electronic identity thanks to LDAP directories.
*
* ==LICENSE NOTICE==
* LinID Directory Manager is a free software subjected to the
* ** GNU Affero Public License ** as published by the
* Free Software Foundation, ** version 3 ** of the license.
*
* By application to section 7 in the GNU Affero GPLv3,
* dynamic and static links do not extend license to other
* softwares.
*
* You can redistribute and/or modify since you respect
* the term of the license.
*
* NOTICE : THIS LICENSE IS FREE OF CHARGE AND THE SOFTWARE
* IS DISTRIBUTED WITHOUT ANY WARRANTIES OF ANY KIND
*
* ==LICENSE NOTICE==
*
* (c) 2008-2010 Linagora - http://linagora.com/
********************************************************* */
package org.linid.dm.wui.t5lib.services;
 
import java.io.IOException;
import java.io.InputStream;
 
 
/**
* Service to check that an uploaded file matches the required format
*/
public interface JpegFileFormatChecker {
 
boolean check(InputStream stream) throws IOException;
}
/wui/branches/2.0/src/main/java/org/linid/dm/wui/t5lib/components/PhotoEditor.java
1,6 → 1,8
package org.linid.dm.wui.t5lib.components;
 
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
 
import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
12,11 → 14,15
import org.apache.tapestry5.ioc.annotations.Value;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.upload.services.UploadedFile;
import org.linid.dm.wui.t5lib.services.JpegFileFormatChecker;
 
public class PhotoEditor {
 
@Inject
private Messages messages;
@Inject
private JpegFileFormatChecker jpegChecker;
 
@Property
@Parameter(required=true)
41,12 → 47,16
public void onSuccess()
{
if(userUid!=null){
File copied = new File(photoDirectory,userUid+PHOTO_EXT);
file.write(copied);
if (!checkFileFormat()) {
throw new RuntimeException("Invalid format, JPEG expected");
} else {
File copied = new File(photoDirectory,userUid+PHOTO_EXT);
file.write(copied);
}
}
}
 
/**
/**
* manage action link to delete photo
*/
public void onActionFromDelete(){
79,4 → 89,19
}
}
 
private boolean checkFileFormat() {
InputStream stream = file.getStream();
try {
return jpegChecker.check(stream);
} catch (IOException e) {
return false;
} finally {
try {
stream.close();
} catch (IOException e) {
throw new RuntimeException("Can't close uploaded file input stream");
}
}
}
 
}
/wui/branches/2.0/pom.xml
333,6 → 333,12
<artifactId>tapestry5-jquery</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.3</version>
</dependency>
</dependencies>