85 | | SortedSet<String> sortedClasses = new TreeSet<String>(); // display + url |
| 85 | if ( ep == null ){ |
| 86 | JsonBuilderFactory jbfactory = Json.createBuilderFactory(null); |
| 87 | JsonObjectBuilder job = jbfactory.createObjectBuilder(); |
| 88 | |
| 89 | String[] eplist = qpg.getFactory().getEndpointURIList(); |
| 90 | for ( int i = 0; i < eplist.length; i++ ){ |
| 91 | try{ |
| 92 | qpg.setSPARQLendpoint(eplist[i]); |
| 93 | SClass[] classes = qpg.getClasses(null); |
| 94 | sortedClasses = qpg.getSortedClasses(classes); |
| 95 | JsonArray ja = getJsonArrayFromSortedClasses(jbfactory, sortedClasses); |
| 96 | job.add(eplist[i], ja); |
| 97 | }catch(Exception e){ |
| 98 | System.err.println(e); |
| 99 | } |
| 100 | } |
| 101 | JsonObject jo = job.build(); |
| 102 | out.print(jo); |
| 103 | return; |
| 104 | } |
| 105 | String classURI = request.getParameter("class"); |
92 | | SClass[] classes = qpg.getClasses(null); |
93 | | qpg.setClassLabels(classes); |
94 | | for (int i = 0 ; i < classes.length; i++ ){ |
95 | | String uri = classes[i].getClassURI(); |
96 | | /* |
97 | | //if ( ocg.getNumberOfEdge(uri) == 0 ){ |
98 | | // continue; |
99 | | //} |
100 | | if ( classURI != null ){ |
101 | | if ( qpg.getOWLClassGraph().visitedNode(uri) == false ){ |
102 | | continue; |
103 | | } |
104 | | } |
105 | | Label[] labels = classes[i].getLabels(); |
106 | | String label = null; |
107 | | for ( int j = 0 ; j < labels.length; j++ ){ |
108 | | if ( labels[j].getLanguage() == null ){ |
109 | | label = labels[j].getLabel(); break; |
110 | | }else if ( labels[j].getLanguage().equals("en") ){ |
111 | | label = labels[j].getLabel(); break; |
112 | | } |
113 | | } |
114 | | if ( label == null ){ |
115 | | qpg.getClassLabelfromExternal(uri); |
116 | | } |
117 | | if ( label == null ){ |
118 | | String[] uris = uri.split("/"); |
119 | | String tmplabel = uris[uris.length-1]; |
120 | | String[] tmplabel2 = tmplabel.split("#"); |
121 | | label = tmplabel2[tmplabel2.length-1]; |
122 | | } |
123 | | */ |
124 | | String label = qpg.getClassLabel(uri); |
125 | | StringBuilder classbuilder = new StringBuilder(label); |
126 | | classbuilder.append(" "); |
127 | | classbuilder.append(classes[i].getNumOfInstances()); |
128 | | classbuilder.append(" "); |
129 | | classbuilder.append(uri); |
130 | | sortedClasses.add(classbuilder.toString()); |
131 | | } |
| 117 | JsonArray ja = getJsonArrayFromSortedClasses(jbfactory, sortedClasses); |
| 118 | out.print(ja); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Handles the HTTP <code>POST</code> method. |
| 123 | * |
| 124 | * @param request servlet request |
| 125 | * @param response servlet response |
| 126 | * @throws ServletException if a servlet-specific error occurs |
| 127 | * @throws IOException if an I/O error occurs |
| 128 | */ |
| 129 | @Override |
| 130 | protected void doPost(HttpServletRequest request, HttpServletResponse response) |
| 131 | throws ServletException, IOException { |
| 132 | processRequest(request, response); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Returns a short description of the servlet. |
| 137 | * |
| 138 | * @return a String containing servlet description |
| 139 | */ |
| 140 | @Override |
| 141 | public String getServletInfo() { |
| 142 | return "Short description"; |
| 143 | }// </editor-fold> |
| 144 | |
| 145 | private JsonArray getJsonArrayFromSortedClasses(JsonBuilderFactory jbfactory, SortedSet<String> sortedClasses){ |
167 | | |
168 | | /** |
169 | | * Handles the HTTP <code>POST</code> method. |
170 | | * |
171 | | * @param request servlet request |
172 | | * @param response servlet response |
173 | | * @throws ServletException if a servlet-specific error occurs |
174 | | * @throws IOException if an I/O error occurs |
175 | | */ |
176 | | @Override |
177 | | protected void doPost(HttpServletRequest request, HttpServletResponse response) |
178 | | throws ServletException, IOException { |
179 | | processRequest(request, response); |
180 | | } |
181 | | |
182 | | /** |
183 | | * Returns a short description of the servlet. |
184 | | * |
185 | | * @return a String containing servlet description |
186 | | */ |
187 | | @Override |
188 | | public String getServletInfo() { |
189 | | return "Short description"; |
190 | | }// </editor-fold> |
191 | | |