List of usage examples for javax.activation MimeType getSubType
public String getSubType()
From source file:com.portfolio.data.provider.MysqlDataProvider.java
@Override public Object getPortfolio(MimeType outMimeType, String portfolioUuid, int userId, int groupId, String label, String resource, String files, int substid) throws Exception { String rootNodeUuid = getPortfolioRootNode(portfolioUuid); String header = ""; String footer = ""; NodeRight nodeRight = credential.getPortfolioRight(userId, groupId, portfolioUuid, Credential.READ); if (!nodeRight.read) { userId = credential.getPublicUid(); // NodeRight nodeRight = new NodeRight(false,false,false,false,false,false); /// Vrifie les droits avec le compte publique (dernire chance) nodeRight = credential.getPublicRight(userId, 123, rootNodeUuid, "dummy"); if (!nodeRight.read) return "faux"; }//from w w w .j a v a 2s . c o m if (outMimeType.getSubType().equals("xml")) { // header = "<portfolio xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' schemaVersion='1.0'>"; // footer = "</portfolio>"; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder; Document document = null; try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); document = documentBuilder.newDocument(); document.setXmlStandalone(true); } catch (ParserConfigurationException e) { e.printStackTrace(); } Element root = document.createElement("portfolio"); root.setAttribute("id", portfolioUuid); root.setAttribute("code", "0"); //// Noeuds supplmentaire pour WAD // Version Element verNode = document.createElement("version"); Text version = document.createTextNode("4"); verNode.appendChild(version); root.appendChild(verNode); // metadata-wad // Element metawad = document.createElement("metadata-wad"); // metawad.setAttribute("prog", "main.jsp"); // metawad.setAttribute("owner", "N"); // root.appendChild(metawad); int owner = credential.getOwner(userId, portfolioUuid); String isOwner = "N"; if (owner == userId) isOwner = "Y"; root.setAttribute("owner", isOwner); // root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); // root.setAttribute("schemaVersion", "1.0"); document.appendChild(root); getLinearXml(portfolioUuid, rootNodeUuid, root, true, null, userId, nodeRight.groupId, nodeRight.groupLabel); StringWriter stw = new StringWriter(); Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.transform(new DOMSource(document), new StreamResult(stw)); if (resource != null && files != null) { if (resource.equals("true") && files.equals("true")) { String adressedufichier = System.getProperty("user.dir") + "/tmp_getPortfolio_" + new Date() + ".xml"; String adresseduzip = System.getProperty("user.dir") + "/tmp_getPortfolio_" + new Date() + ".zip"; File file = null; PrintWriter ecrire; try { file = new File(adressedufichier); ecrire = new PrintWriter(new FileOutputStream(adressedufichier)); ecrire.println(stw.toString()); ecrire.flush(); ecrire.close(); System.out.print("fichier cree "); } catch (IOException ioe) { System.out.print("Erreur : "); ioe.printStackTrace(); } try { ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(adresseduzip)); zip.setMethod(ZipOutputStream.DEFLATED); zip.setLevel(Deflater.BEST_COMPRESSION); File dataDirectories = new File(file.getName()); FileInputStream fis = new FileInputStream(dataDirectories); byte[] bytes = new byte[fis.available()]; fis.read(bytes); ZipEntry entry = new ZipEntry(file.getName()); entry.setTime(dataDirectories.lastModified()); zip.putNextEntry(entry); zip.write(bytes); zip.closeEntry(); fis.close(); //zipDirectory(dataDirectories, zip); zip.close(); file.delete(); return adresseduzip; } catch (FileNotFoundException fileNotFound) { fileNotFound.printStackTrace(); } catch (IOException io) { io.printStackTrace(); } } } return stw.toString(); } else if (outMimeType.getSubType().equals("json")) { header = "{\"portfolio\": { \"-xmlns:xsi\": \"http://www.w3.org/2001/XMLSchema-instance\",\"-schemaVersion\": \"1.0\","; footer = "}}"; } return header + getNode(outMimeType, rootNodeUuid, true, userId, groupId, label).toString() + footer; }