/** * @see it.webscience.kpeople.ega.adapter.sharepoint * .actionDataProcessor.actionDataInterface.ActionDataParserInterface * #parser(org.apache.axiom.om.OMElement, it.webscience.kpeople.domain.model.KpeopleAction). * @param action azione che è stata intercettata. * @param response indica il valore di ritorno della chiamata al webservice di sharepoint * contenente le informazioni sulle liste monitorate * @return hashmap da sostituire. * @throws Exception eccezione. */ public KpeopleSimpleEvent parser(final GetItemResponse response, final KpeopleAction action) throws Exception { KpeopleLogger.getInstance() .getService() .logInfo( KpeopleLabel.getSystemId(), this.getClass() + ".parser()" + KpeopleLabel.getLogStart()); manageActionInfo(action); String operation = action.getActionType().split("/")[1]; eventResult.setOperation(operation); manageEventInfo(response, operation); DataHandler stream = response.getStream(); manageDetails(response, stream); manageAttachments(action, stream); KpeopleLogger.getInstance() .getService() .logInfo( KpeopleLabel.getSystemId(), this.getClass() + ".parser()" + KpeopleLabel.getLogStop()); return eventResult; }
private void manageDetails(final GetItemResponse response, final DataHandler stream) { InputStream is = null; ContentHandler contenthandler = new BodyContentHandler(); Metadata metadata = new Metadata(); // metadata.set(Metadata.RESOURCE_NAME_KEY, f.getName()); Parser parser = new AutoDetectParser(); ParseContext context = new ParseContext(); try { is = stream.getInputStream(); parser.parse(is, contenthandler, metadata, context); is.close(); is.reset(); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (TikaException e) { e.printStackTrace(); } String contentAuthorValue = metadata.get(Metadata.AUTHOR); String contentAuthorKey = currentProperties.getProperty(KpeopleLabel.getCorePropertiesAuthor()); if (contentAuthorValue != null) { eventResult.setDetail(contentAuthorKey, contentAuthorValue); } String contentCreationDateValue = metadata.get(Metadata.CREATION_DATE); String contentCreationDateKey = currentProperties.getProperty(KpeopleLabel.getCorePropertiesCreationDate()); if (contentCreationDateValue != null) { eventResult.setDetail(contentCreationDateKey, contentCreationDateValue); } String contentKeywordsValue = metadata.get(Metadata.KEYWORDS); String contentKeywordsKey = currentProperties.getProperty(KpeopleLabel.getCorePropertiesKeywords()); if (contentKeywordsValue != null) { eventResult.setDetail(contentKeywordsKey, contentKeywordsValue); } String[] names = metadata.names(); /* * for (int i = 0; i < names.length; i++) { * System.out.println(names[i]); } */ }
private void manageAttachments(KpeopleAction action, DataHandler stream) throws IOException { InputStream is = null; String hashcode = null; try { is = stream.getInputStream(); hashcode = Hashcode.getHashcode(is, Hashcode.SHA512); } catch (IOException e) { e.printStackTrace(); throw e; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } String path = (String) currentProperties.get(KpeopleLabel.getEventXMLPath()); try { path = ActionDataProcessorUtil.checkEventXMLPath(path); } catch (Exception e1) { e1.printStackTrace(); } FileOutputStream outputStream = null; File tmpFilePath = null; try { path = path + action.getIdAction() + "-" + fileName; tmpFilePath = new File(path); outputStream = new FileOutputStream(tmpFilePath); stream.writeTo(outputStream); outputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // ActionDataProcessorUtil.deleteEventFile(tmpFilePath); String idAttachmentId = Long.toString(action.getIdAction()) + "-" + hashcode.substring(0, 6); KpeopleAttachment attachment = new KpeopleAttachment(); attachment.setAttachmentName(fileName); attachment.setAttachmentHashcode(hashcode); attachment.setAttachmentData(path); attachment.setIdAttachment(idAttachmentId); attachment.setAttachmentType(eventResult.getContentType()); eventResult.addAttachment(attachment); }