Package eu.planets_project.pp.plato.services.characterisation

Examples of eu.planets_project.pp.plato.services.characterisation.FormatIdentification


            possibleFormatsString = null;
           
            /**
             * DROID is used for file identification.
             */
            FormatIdentification ident = null;
           
            String filename = tempDigitalObjects.get(rec);
           
            if (filename == null || "".equals(filename)) {
                SampleObject rec2 = em.merge(rec);
                ident = DROIDIntegration.getInstance().identifyFormat(rec2.getData().getData(), rec2.getFullname());   
            } else {
                ident = DROIDIntegration.getInstance().identify(filename);
            }
           
            if (ident.getResult() == FormatIdentificationResult.ERROR) {
                /*
                 * DROID could not identify this file.
                 */
                log.error(ident.getInfo());
                formatMessage = "DROID could not identify the format of the file." + ident.getInfo();
            } else if (ident.getResult() == FormatIdentificationResult.NOHIT) {
                /*
                 * DROID could not identify this file.
                 */
                log.info(ident.getInfo());
                formatMessage = "DROID could not identify the format of the file." + ident.getInfo();
            } else if ((ident.getResult() == FormatIdentificationResult.POSITIVE) &&
                    (ident.getFormatHits().size() == 1)){
                /*
                 *  exact match, format identification successful
                 */
                rec.getFormatInfo().assignValues(ident.getFormatHits().get(0).getFormat());
                rec.touch();
                formatMessage = ident.getInfo();
            } else {
                /*
                 * Here, we either have more than one POSITIVE hit or any number of TENTATIVE hits.
                 * DROID provides only some guesses as it cannot identify it, the user has to decide.
                 */
                formatMessage = "Droid identified several potential formats of this file. " + ident.getInfo() + " Please choose the most adequate one:";

                for (FormatHit hit : ident.getFormatHits()){
                    String key = hit.getFormat().getName();
                    if (hit.getFormat().getVersion() != null)
                        key = key + ' ' + hit.getFormat().getVersion();

                    possibleFormats.put(key, hit);
                }
               
                possibleFormatsString = possibleFormats.keySet().toArray(new String[]{});
                // set format info to first entry in the list - as the drop down box suggests
                selectedFormat.setValue(possibleFormatsString[0]);
                rec.getFormatInfo().assignValues(possibleFormats.get(selectedFormat.getValue()).getFormat());
                rec.touch();

                FacesMessages.instance().add(FacesMessage.SEVERITY_INFO, ident.getInfo());
            }
        } catch (Exception e) {
            /*
             * An error occured, maybe it would help to try it again.
             */
 
View Full Code Here


       
       
        /**
         * DROID is used for file identification.
         */
        FormatIdentification ident = null;
       
        String filename = tempFiles.get(dobject);
       
        if (filename == null || "".equals(filename)) {
            DigitalObject o2 = em.merge(dobject);
            try {
                ident = DROIDIntegration.getInstance().identifyFormat(
                        o2.getData().getData(),
                        o2.getFullname());
            } catch (Exception e) {
                log.error(e.getMessage(),e);
            }   
        } else {
            ident = DROIDIntegration.getInstance().identify(filename);
        }
       
        if (ident == null)  {
            return;
        }
        if (ident.getResult() == FormatIdentificationResult.ERROR) {
            /*
             * DROID could not identify this file.
             */
            log.error("DROID could not identify the format of the file." + ident.getInfo());
        } else if (ident.getResult() == FormatIdentificationResult.NOHIT) {
            /*
             * DROID could not identify this file.
             */
            log.info("DROID did not get a hit identifying the file. "+ident.getInfo());
        } else if ((ident.getResult() == FormatIdentificationResult.POSITIVE)){
            /*
             *  match, format identification successful:
             *  if it is a multiple match, we simply take the first one here.
             */
            dobject.getFormatInfo().assignValues(ident.getFormatHits().get(0).getFormat());
            dobject.touch();
        }
        }
View Full Code Here

TOP

Related Classes of eu.planets_project.pp.plato.services.characterisation.FormatIdentification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.