Example usage for javax.activation MimeTypeParseException printStackTrace

List of usage examples for javax.activation MimeTypeParseException printStackTrace

Introduction

In this page you can find the example usage for javax.activation MimeTypeParseException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.kalypso.model.wspm.pdb.internal.wspm.DocumentConverter.java

private MimeType convertMimeType(final String mimeType) {
    try {/*from  ww  w  .j av  a  2 s.  c o m*/
        if (StringUtils.isBlank(mimeType))
            return null;

        return new MimeType(mimeType);
    } catch (final MimeTypeParseException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.kalypso.commons.java.activation.MimeTypeFinder.java

public MimeTypeFinder() {
    try {//from w w  w  . j  av  a  2 s. co m
        m_knownTypes.put("dwg", new MimeType(MIME_APPLICATION, "acad")); // AutoCAD-Dateien (nach NCSA) //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("dxf", new MimeType(MIME_APPLICATION, "dxf")); // AutoCAD-Dateien (nach CERN) //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("gz", new MimeType(MIME_APPLICATION, "gzip")); // GNU Zip-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("xls", new MimeType(MIME_APPLICATION, "msexcel")); // Microsoft Excel Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("ppt", new MimeType(MIME_APPLICATION, "mspowerpoint")); // Microsoft Powerpoint Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("doc", new MimeType(MIME_APPLICATION, "msword")); // Microsoft Word Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("pdf", new MimeType(MIME_APPLICATION, "pdf")); // Adobe PDF-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("ps", new MimeType(MIME_APPLICATION, "postscript")); // Adobe PostScript-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("eps", new MimeType(MIME_APPLICATION, "postscript")); // Adobe PostScript-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("rtf", new MimeType(MIME_APPLICATION, "rtf")); // Microsoft RTF-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("htm", new MimeType(MIME_APPLICATION, "xhtml+xml")); // XHTML-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("html", new MimeType(MIME_APPLICATION, "xhtml+xml")); // XHTML-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("xhtml", new MimeType(MIME_APPLICATION, "xhtml+xml")); // XHTML-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("xml", new MimeType(MIME_APPLICATION, "xml")); // XML-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("gtar", new MimeType(MIME_APPLICATION, "x-gtar")); // GNU tar-Archivdateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("swf", new MimeType(MIME_APPLICATION, "x-shockwave-flash")); // Flash Shockwave-Dateien //$NON-NLS-1$ //$NON-NLS-2$

        m_knownTypes.put("tar", new MimeType(MIME_APPLICATION, "x-tar")); // tar-Archivdateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("zip", new MimeType(MIME_APPLICATION, "zip")); // ZIP-Archivdateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("mp2", new MimeType(MIME_AUDIO, "x-mpeg")); // MPEG-Dateien //$NON-NLS-1$ //$NON-NLS-2$

        m_knownTypes.put("jpg", new MimeType(MIME_IMAGE, "jpg")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("jpeg", new MimeType(MIME_IMAGE, "jpg")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("jpe", new MimeType(MIME_IMAGE, "jpg")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("gif", new MimeType(MIME_IMAGE, "gif")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("png", new MimeType(MIME_IMAGE, "png")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("tiff", new MimeType(MIME_IMAGE, "tiff")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("tif", new MimeType(MIME_IMAGE, "tiff")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("bmp", new MimeType(MIME_IMAGE, "bmp")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("ico", new MimeType(MIME_IMAGE, "ico")); //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("ico", new MimeType(MIME_IMAGE, "x-icon")); // Icon-Dateien (z.B. Favoriten-Icons) //$NON-NLS-1$ //$NON-NLS-2$

        m_knownTypes.put("csv", new MimeType(MIME_TEXT, "comma-separated-values")); // kommaseparierte //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("txt", new MimeType(MIME_TEXT, "plain")); // *.txt reine Textdateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("tsv", new MimeType(MIME_TEXT, "tab-separated-values")); // *.tsv tabulator-separierte //$NON-NLS-1$ //$NON-NLS-2$

        m_knownTypes.put("xml", new MimeType(MIME_TEXT, "xml")); // XML-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("mpeg", new MimeType(MIME_VIDEO, "mpeg")); // MPEG-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("mpg", new MimeType(MIME_VIDEO, "mpeg")); // MPEG-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("mpe", new MimeType(MIME_VIDEO, "mpeg")); // MPEG-Dateien //$NON-NLS-1$ //$NON-NLS-2$
        m_knownTypes.put("avi", new MimeType(MIME_VIDEO, "x-msvideo")); // Microsoft AVI-Dateien //$NON-NLS-1$ //$NON-NLS-2$
    } catch (final MimeTypeParseException e) {
        e.printStackTrace();
    }
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

@Override
public Object postPortfolioZip(MimeType mimeType, MimeType mimeType2, HttpServletRequest httpServletRequest,
        int userId, int groupId, String modelId) throws FileNotFoundException, IOException {
    if (!credential.isAdmin(userId))
        throw new RestWebApplicationException(Status.FORBIDDEN, "No admin right");

    DataInputStream inZip = new DataInputStream(httpServletRequest.getInputStream());

    ByteArrayOutputStream byte2 = new ByteArrayOutputStream();
    StringBuffer outTrace = new StringBuffer();

    String portfolioId = null;/*w ww . jav a2 s .com*/
    portfolioId = httpServletRequest.getParameter("portfolio");

    String foldersfiles = null;
    String filename;
    String[] xmlFiles;
    String[] allFiles;
    String[] ImgFiles;
    int formDataLength = httpServletRequest.getContentLength();
    byte[] buff = new byte[formDataLength];

    // Recuperation de l'heure  laquelle le zip est cr
    //Calendar cal = Calendar.getInstance();
    //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss_S");
    //String now = sdf.format(cal.getTime());

    this.genererPortfolioUuidPreliminaire();

    javax.servlet.http.HttpSession session = httpServletRequest.getSession(true);
    String ppath = session.getServletContext().getRealPath(File.separator);
    String outsideDir = ppath.substring(0, ppath.lastIndexOf(File.separator)) + "_files" + File.separator;
    File outsideDirectoryFile = new File(outsideDir);
    System.out.println(outsideDir);
    // if the directory does not exist, create it
    if (!outsideDirectoryFile.exists()) {
        outsideDirectoryFile.mkdir();
    }

    //Creation du zip
    filename = outsideDir + "xml_" + this.portfolioUuidPreliminaire + ".zip";
    FileOutputStream outZip = new FileOutputStream(filename);

    int len;

    while ((len = inZip.read(buff)) != -1) {
        outZip.write(buff, 0, len);
    }

    inZip.close();
    outZip.close();

    //-- unzip --
    foldersfiles = unzip(filename, outsideDir + this.portfolioUuidPreliminaire + File.separator);
    //TODO Attention si plusieurs XML dans le fichier
    xmlFiles = findFiles(outsideDir + this.portfolioUuidPreliminaire + File.separator, "xml");
    allFiles = findFiles(outsideDir + this.portfolioUuidPreliminaire + File.separator, null);

    for (int i = 0; i < allFiles.length; i++) {
        portfolioRessourcesImportPath.add(allFiles[i]);
        String tmpFileName = allFiles[i].substring(allFiles[i].lastIndexOf(File.separator) + 1);
        String uuid = tmpFileName.substring(0, tmpFileName.indexOf("_"));
        portfolioRessourcesImportUuid.add(uuid);

        tmpFileName = allFiles[i].substring(allFiles[i].lastIndexOf(File.separator) + 1);
        String lang;
        try {
            int tmpPos = tmpFileName.indexOf("_");
            lang = tmpFileName.substring(tmpPos + 1, tmpPos + 3);
        } catch (Exception ex) {
            lang = "";
        }
        InputStream is = new FileInputStream(allFiles[i]);
        byte b[] = new byte[is.available()];
        is.read(b);
        String extension;
        try {
            extension = tmpFileName.substring(tmpFileName.lastIndexOf(".") + 1);
        } catch (Exception ex) {
            extension = null;

        }

        // trop long
        //String tmpMimeType = FileUtils.getMimeType("file://"+allFiles[i]);
        String tmpMimeType = FileUtils.getMimeTypeFromExtension(extension);

        // Attention on initialise la ligne file
        // avec l'UUID d'origine de l'asmContext parent
        // Il sera mis  jour avec l'UUID asmContext final dans writeNode
        try {
            UUID tmpUuid = UUID.fromString(uuid);

            if (tmpUuid.toString().equals(uuid))
                this.putFile(uuid, lang, tmpFileName, outsideDir, tmpMimeType, extension, b.length, b, userId);
        } catch (Exception ex) {
            // Le nom du fichier ne commence pas par un UUID,
            // ce n'est donc pas une ressource
        }
    }

    //TODO Supprimer le zip quand a fonctionnera bien

    //--- Read xml fileL ----
    for (int i = 0; i < xmlFiles.length; i++) {
        BufferedReader br = new BufferedReader(new FileReader(new File(xmlFiles[i])));
        String line;
        StringBuilder sb = new StringBuilder();

        while ((line = br.readLine()) != null) {
            sb.append(line.trim());
        }
        String xml = "?";
        xml = sb.toString();

        if (xml.contains("<portfolio id=")) {
            try {
                Object returnValue = postPortfolio(new MimeType("text/xml"), new MimeType("text/xml"), xml,
                        userId, groupId, null);
                return returnValue;
            } catch (MimeTypeParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

    return false;
}