List of usage examples for javax.activation MimeType getSubType
public String getSubType()
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
@Override public Object getResources(MimeType outMimeType, String portfolioUuid, int userId, int groupId) throws Exception { java.sql.ResultSet res = getMysqlResources(portfolioUuid); String returnValue = ""; if (outMimeType.getSubType().equals("xml")) { returnValue += "<resources>"; while (res.next()) { if (!credential.hasNodeRight(userId, groupId, res.getString("res_node_uuid"), Credential.READ)) { //returnValue += null; }//from www . j a va 2s .c om returnValue += "<resource " + DomUtils.getXmlAttributeOutput("id", res.getString("res_node_uuid")) + " />"; } returnValue += "</resources>"; } else { returnValue += "{"; boolean firstNode = true; while (res.next()) { if (firstNode) firstNode = false; else returnValue += " , "; if (!credential.hasNodeRight(userId, groupId, res.getString("res_node_uuid"), Credential.READ)) { //returnValue += null; } else { returnValue += "resource: { " + DomUtils.getJsonAttributeOutput("id", res.getString("res_node_uuid")) + " } "; } } returnValue += "}"; } return returnValue; }
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
@Override public Object getPortfolios(MimeType outMimeType, int userId, int groupId, Boolean portfolioActive) throws SQLException { ResultSet res = getMysqlPortfolios(userId, portfolioActive); String result = ""; if (outMimeType.getSubType().equals("xml")) { result = "<portfolios>"; while (res.next()) { String isOwner = "N"; if (Integer.parseInt(res.getString("user_id")) == userId) isOwner = "Y"; result += "<portfolio "; result += DomUtils.getXmlAttributeOutput("id", res.getString("portfolio_id")) + " "; result += DomUtils.getXmlAttributeOutput("root_node_id", res.getString("root_node_uuid")) + " "; result += DomUtils.getXmlAttributeOutput("owner", isOwner) + " "; result += DomUtils.getXmlAttributeOutput("modified", res.getString("modif_date")) + " "; result += ">"; result += getNodeXmlOutput(res.getString("root_node_uuid"), false, "nodeRes", userId, groupId, null, false);//from ww w . j a v a 2 s.c om result += "</portfolio>"; } result += "</portfolios>"; } else if (outMimeType.getSubType().equals("json")) { result = "{ \"portfolios\": { \"portfolio\": ["; boolean firstPass = false; while (res.next()) { if (firstPass) result += ","; result += "{ "; result += DomUtils.getJsonAttributeOutput("id", res.getString("portfolio_id")) + ", "; result += DomUtils.getJsonAttributeOutput("root_node_id", res.getString("root_node_uuid")) + ", "; result += getNodeJsonOutput(res.getString("root_node_uuid"), false, "nodeRes", userId, groupId, null, false); result += "} "; firstPass = true; } result += "] } }"; } res.close(); return result; }
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
@Override public Object getNodesBySemanticTag(MimeType outMimeType, int userId, int groupId, String portfolioUuid, String semanticTag) throws SQLException { ResultSet res = this.getMysqlNodeUuidBySemanticTag(portfolioUuid, semanticTag); String result = ""; if (outMimeType.getSubType().equals("xml")) { result = "<nodes>"; while (res.next()) { String nodeUuid = res.getString("node_uuid"); if (!credential.hasNodeRight(userId, groupId, nodeUuid, credential.READ)) return null; result += "<node "; result += DomUtils.getXmlAttributeOutput("id", nodeUuid) + " "; result += ">"; result += "</node>"; }//from ww w . j av a 2s. c o m result += "</nodes>"; } else if (outMimeType.getSubType().equals("json")) { result = "{ \"nodes\": { \"node\": ["; boolean firstPass = false; while (res.next()) { if (firstPass) result += ","; result += "{ "; result += DomUtils.getJsonAttributeOutput("id", res.getString("id")) + ", "; result += "} "; firstPass = true; } result += "] } }"; } return result; }
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
@Override public Object getNodeBySemanticTag(MimeType outMimeType, String portfolioUuid, String semantictag, int userId, int groupId) throws Exception { ResultSet res;/*from ww w .ja v a 2s . c o m*/ String nodeUuid; // On recupere d'abord l'uuid du premier noeud trouv correspondant au semantictag res = this.getMysqlNodeUuidBySemanticTag(portfolioUuid, semantictag); res.next(); nodeUuid = res.getString("node_uuid"); if (!credential.hasNodeRight(userId, groupId, nodeUuid, credential.READ)) return null; if (outMimeType.getSubType().equals("xml")) return getNodeXmlOutput(nodeUuid, true, null, userId, groupId, null, true); else if (outMimeType.getSubType().equals("json")) return "{" + getNodeJsonOutput(nodeUuid, true, null, userId, groupId, null, true) + "}"; else return null; }
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
@Override public Object getPortfolio(MimeType outMimeType, String portfolioUuid, int userId, int groupId, String label, String resource, String files) throws Exception { String rootNodeUuid = getPortfolioRootNode(portfolioUuid); String header = ""; String footer = ""; NodeRight nodeRight = credential.getPortfolioRight(userId, groupId, portfolioUuid, Credential.READ); if (!nodeRight.read) return "faux"; 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 {//from w w w . j a v a 2 s . com documentBuilder = documentBuilderFactory.newDocumentBuilder(); document = documentBuilder.newDocument(); document.setXmlStandalone(true); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block 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("3"); 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); // 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, groupId); 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; PrintWriter ecri; 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 { String fileName = portfolioUuid + ".zip"; 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; }
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
@Override public Object getNode(MimeType outMimeType, String nodeUuid, boolean withChildren, int userId, int groupId, String label) throws SQLException, TransformerFactoryConfigurationError, ParserConfigurationException, UnsupportedEncodingException, DOMException, SAXException, IOException, TransformerException { StringBuffer nodexml = new StringBuffer(); NodeRight nodeRight = credential.getNodeRight(userId, groupId, nodeUuid, label); if (!nodeRight.read) return nodexml; if (outMimeType.getSubType().equals("xml")) { ResultSet result = getNodePerLevel(nodeUuid, userId, groupId); /// Prparation du XML que l'on va renvoyer DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; Document document = null; documentBuilder = documentBuilderFactory.newDocumentBuilder(); document = documentBuilder.newDocument(); document.setXmlStandalone(true); HashMap<String, Node> resolve = new HashMap<String, Node>(); /// Node -> parent ArrayList<Object[]> entries = new ArrayList<Object[]>(); processQuery(result, resolve, entries, document, documentBuilder); result.close();//from w w w .j a va 2 s . co m for (int i = 0; i < entries.size(); ++i) { Object[] obj = entries.get(i); Node node = (Node) obj[0]; String childsId = (String) obj[1]; String[] tok = childsId.split(","); for (int j = 0; j < tok.length; ++j) { String id = tok[j]; Node child = resolve.get(id); if (child != null) node.appendChild(child); } } Node root = resolve.get(nodeUuid); Node node = document.createElement("node"); node.appendChild(root); document.appendChild(node); StringWriter stw = new StringWriter(); Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.transform(new DOMSource(document), new StreamResult(stw)); nodexml.append(stw.toString()); // StringBuffer sb = getNodeXmlOutput(nodeUuid,withChildren,null,userId, groupId, label,true); // StringBuffer sb = getLinearNodeXml(nodeUuid,withChildren,null,userId, groupId, label,true); // sb.insert(0, "<node>"); // sb.append("</node>"); return nodexml; } else if (outMimeType.getSubType().equals("json")) return "{" + getNodeJsonOutput(nodeUuid, withChildren, null, userId, groupId, label, true) + "}"; else return null; }
From source file:com.portfolio.data.provider.MysqlDataProvider.java
@Override public Object getPortfolios(MimeType outMimeType, int userId, int groupId, Boolean portfolioActive, int substid) throws SQLException { ResultSet res = getMysqlPortfolios(userId, substid, portfolioActive); String result = ""; if (outMimeType.getSubType().equals("xml")) { result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><portfolios>"; while (res.next()) { String isOwner = "N"; if (Integer.parseInt(res.getString("user_id")) == userId) isOwner = "Y"; result += "<portfolio "; result += DomUtils.getXmlAttributeOutput("id", res.getString("portfolio_id")) + " "; result += DomUtils.getXmlAttributeOutput("root_node_id", res.getString("root_node_uuid")) + " "; result += DomUtils.getXmlAttributeOutput("owner", isOwner) + " "; result += DomUtils.getXmlAttributeOutput("modified", res.getString("modif_date")) + " "; result += ">"; result += getNodeXmlOutput(res.getString("root_node_uuid"), false, "nodeRes", userId, groupId, null, false);/*from w w w . j ava 2 s.c o m*/ result += "</portfolio>"; } result += "</portfolios>"; } else if (outMimeType.getSubType().equals("json")) { result = "{ \"portfolios\": { \"portfolio\": ["; boolean firstPass = false; while (res.next()) { if (firstPass) result += ","; result += "{ "; result += DomUtils.getJsonAttributeOutput("id", res.getString("portfolio_id")) + ", "; result += DomUtils.getJsonAttributeOutput("root_node_id", res.getString("root_node_uuid")) + ", "; result += getNodeJsonOutput(res.getString("root_node_uuid"), false, "nodeRes", userId, groupId, null, false); result += "} "; firstPass = true; } result += "] } }"; } res.close(); return result; }
From source file:com.portfolio.data.provider.MysqlDataProvider.java
@Override public Object getNodesBySemanticTag(MimeType outMimeType, int userId, int groupId, String portfolioUuid, String semanticTag) throws SQLException { ResultSet res = this.getMysqlNodeUuidBySemanticTag(portfolioUuid, semanticTag); String result = ""; if (outMimeType.getSubType().equals("xml")) { result = "<nodes>"; while (res.next()) { String nodeUuid = res.getString("node_uuid"); if (!credential.hasNodeRight(userId, groupId, nodeUuid, Credential.READ)) return null; result += "<node "; result += DomUtils.getXmlAttributeOutput("id", nodeUuid) + " "; result += ">"; result += "</node>"; }/* w w w . j a va 2 s. com*/ result += "</nodes>"; } else if (outMimeType.getSubType().equals("json")) { result = "{ \"nodes\": { \"node\": ["; boolean firstPass = false; while (res.next()) { if (firstPass) result += ","; result += "{ "; result += DomUtils.getJsonAttributeOutput("id", res.getString("id")) + ", "; result += "} "; firstPass = true; } result += "] } }"; } return result; }
From source file:com.portfolio.data.provider.MysqlDataProvider.java
@Override public Object getNodeBySemanticTag(MimeType outMimeType, String portfolioUuid, String semantictag, int userId, int groupId) throws Exception { ResultSet res;/*from w w w . j a va 2s . c o m*/ String nodeUuid; // On recupere d'abord l'uuid du premier noeud trouv correspondant au semantictag res = this.getMysqlNodeUuidBySemanticTag(portfolioUuid, semantictag); res.next(); nodeUuid = res.getString("node_uuid"); if (!credential.hasNodeRight(userId, groupId, nodeUuid, Credential.READ)) return null; if (outMimeType.getSubType().equals("xml")) return getNodeXmlOutput(nodeUuid, true, null, userId, groupId, null, true); else if (outMimeType.getSubType().equals("json")) return "{" + getNodeJsonOutput(nodeUuid, true, null, userId, groupId, null, true) + "}"; else return null; }
From source file:com.portfolio.data.provider.MysqlDataProvider.java
@Override public Object getNode(MimeType outMimeType, String nodeUuid, boolean withChildren, int userId, int groupId, String label) throws SQLException, TransformerFactoryConfigurationError, ParserConfigurationException, UnsupportedEncodingException, DOMException, SAXException, IOException, TransformerException { StringBuffer nodexml = new StringBuffer(); NodeRight nodeRight = credential.getNodeRight(userId, groupId, nodeUuid, label); if (!nodeRight.read) { userId = credential.getPublicUid(); /// Vrifie les droits avec le compte publique (dernire chance) credential.getPublicRight(userId, 123, nodeUuid, "dummy"); if (!nodeRight.read) return nodexml; }//w w w .j ava 2s . co m if (outMimeType.getSubType().equals("xml")) { ResultSet result = getNodePerLevel(nodeUuid, userId, nodeRight.groupId); /// Prparation du XML que l'on va renvoyer DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; Document document = null; documentBuilder = documentBuilderFactory.newDocumentBuilder(); document = documentBuilder.newDocument(); document.setXmlStandalone(true); HashMap<String, Node> resolve = new HashMap<String, Node>(); /// Node -> parent ArrayList<Object[]> entries = new ArrayList<Object[]>(); processQuery(result, resolve, entries, document, documentBuilder, nodeRight.groupLabel); result.close(); for (int i = 0; i < entries.size(); ++i) { Object[] obj = entries.get(i); Node node = (Node) obj[0]; String childsId = (String) obj[1]; String[] tok = childsId.split(","); for (int j = 0; j < tok.length; ++j) { String id = tok[j]; Node child = resolve.get(id); if (child != null) node.appendChild(child); } } Node root = resolve.get(nodeUuid); Node node = document.createElement("node"); node.appendChild(root); document.appendChild(node); StringWriter stw = new StringWriter(); Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.transform(new DOMSource(document), new StreamResult(stw)); nodexml.append(stw.toString()); // StringBuffer sb = getNodeXmlOutput(nodeUuid,withChildren,null,userId, groupId, label,true); // StringBuffer sb = getLinearNodeXml(nodeUuid,withChildren,null,userId, groupId, label,true); // sb.insert(0, "<node>"); // sb.append("</node>"); return nodexml; } else if (outMimeType.getSubType().equals("json")) return "{" + getNodeJsonOutput(nodeUuid, withChildren, null, userId, groupId, label, true) + "}"; else return null; }