List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:ru.runa.wf.logic.bot.webservice.WebServiceTaskHandlerXmlParser.java
License:Open Source License
/** * Read XML from specified stream and create * {@link WebServiceTaskHandlerSettings} instance according to XML. * /* w w w .j a va2 s. co m*/ * @param data * Stream with XML to read. * @return Instance of {@link WebServiceTaskHandlerSettings} created * according to XML. */ public static WebServiceTaskHandlerSettings read(String configuration) { Document document = XmlUtils.parseWithoutValidation(configuration); Element root = document.getRootElement(); String url = root.elementText(URL); String soapAction = root.elementText(SOAP_ACTION); ErrorResponseProcessingResult errorAction = readErrorAction(root); String authBase = root.elementText(AUTH_BASE); String requestMethod = root.elementText(REQUEST_METHOD); boolean isLoggingEnable = "true".equalsIgnoreCase(root.elementText(LOGGING)); List<Interaction> interactions = readInteractions(root.elements(INTERACTION)); return new WebServiceTaskHandlerSettings(url, soapAction, interactions, authBase, requestMethod, isLoggingEnable, errorAction); }
From source file:ru.runa.wf.logic.bot.webservice.WebServiceTaskHandlerXmlParser.java
License:Open Source License
/** * Read interactions from elements./*from ww w. ja v a 2 s . c o m*/ * * @param interactionsElements * List of XML elements, describing interactions. * @return List of readed interactions. */ private static List<Interaction> readInteractions(List<Element> interactionsElements) { List<Interaction> result = new ArrayList<Interaction>(); for (Element interaction : interactionsElements) { String requestXML = interaction.elementText(INTERACTION_REQUEST); String responseXSLT = interaction.elementText(INTERACTION_RESPONSE); String variableName = getElementAttribute(interaction, INTERACTION_RESPONSE, INTERACTION_VARIABLE); String maxLength = getElementAttribute(interaction, INTERACTION_RESPONSE, INTERACTION_RESPONSE_LENGTH); int maxResponseLength = maxLength == null ? 128 * 1024 : Integer.parseInt(maxLength); if (maxResponseLength < 0) { maxResponseLength = 128 * 1024; } ErrorResponseProcessingResult errorAction = readErrorAction(interaction); result.add(new Interaction(requestXML, responseXSLT, errorAction, maxResponseLength, variableName)); } return result; }
From source file:ru.runa.wfe.definition.logic.DefinitionLogic.java
License:Open Source License
public List<ProcessDefinitionChange> getChanges(Long definitionId) { List<ProcessDefinitionChange> result = new ArrayList<>(); String definitionName = deploymentDAO.get(definitionId).getName(); List<Deployment> listOfDeployments = deploymentDAO.findAllDeploymentVersions(definitionName); int previousCount = 0; for (int m = listOfDeployments.size() - 1; m >= 0; m--) { Deployment deployment = listOfDeployments.get(m); int currentVersion = deployment.getVersion().intValue(); String fileName = IFileDataProvider.COMMENTS_XML_FILE_NAME; ProcessArchive archiveData = new ProcessArchive(deployment); if (archiveData.getFileData().containsKey(fileName)) { byte[] definitionXml = archiveData.getFileData().get(fileName); Document document = XmlUtils.parseWithoutValidation(definitionXml); List<Element> versionList = document.getRootElement().elements(CommentsParser.VERSION); List<VersionInfo> versionInfos = Lists.newArrayList(); for (int j = previousCount; j < versionList.size(); j++) { Element versionInfoElement = versionList.get(j); VersionInfo versionInfo = new VersionInfo(); versionInfo.setDateTime(versionInfoElement.elementText(CommentsParser.VERSION_DATE)); versionInfo.setAuthor(versionInfoElement.elementText(CommentsParser.VERSION_AUTHOR)); versionInfo.setComment(versionInfoElement.elementText(CommentsParser.VERSION_COMMENT)); versionInfos.add(versionInfo); previousCount++;//from w ww . j ava 2 s . c o m } for (VersionInfo versionInfo : versionInfos) { result.add(new ProcessDefinitionChange(currentVersion, versionInfo)); } } } return result; }
From source file:ru.runa.wfe.definition.logic.DefinitionLogic.java
License:Open Source License
public List<ProcessDefinitionChange> findChanges(String definitionName, Long version1, Long version2) { List<ProcessDefinitionChange> result = new ArrayList<>(); List<Deployment> listOfDeployments = deploymentDAO.findAllDeploymentVersions(definitionName); int previousCount = 0; for (int m = listOfDeployments.size() - 1; m >= 0; m--) { Deployment deployment = listOfDeployments.get(m); int currentVersion = deployment.getVersion().intValue(); String fileName = IFileDataProvider.COMMENTS_XML_FILE_NAME; ProcessArchive archiveData = new ProcessArchive(deployment); if (archiveData.getFileData().containsKey(fileName)) { byte[] definitionXml = archiveData.getFileData().get(fileName); Document document = XmlUtils.parseWithoutValidation(definitionXml); List<Element> versionList = document.getRootElement().elements(CommentsParser.VERSION); List<VersionInfo> versionInfos = Lists.newArrayList(); for (int j = previousCount; j < versionList.size(); j++) { Element versionInfoElement = versionList.get(j); VersionInfo versionInfo = new VersionInfo(); versionInfo.setDateTime(versionInfoElement.elementText(CommentsParser.VERSION_DATE)); versionInfo.setAuthor(versionInfoElement.elementText(CommentsParser.VERSION_AUTHOR)); versionInfo.setComment(versionInfoElement.elementText(CommentsParser.VERSION_COMMENT)); versionInfos.add(versionInfo); previousCount++;//from w ww . j ava 2s .c om } if (currentVersion >= version1 && currentVersion <= version2) { for (VersionInfo versionInfo : versionInfos) { result.add(new ProcessDefinitionChange(currentVersion, versionInfo)); } } } } return result; }
From source file:ru.runa.wfe.definition.logic.DefinitionLogic.java
License:Open Source License
public List<ProcessDefinitionChange> findChanges(Date date1, Date date2) { List<ProcessDefinitionChange> result = new ArrayList<>(); List<Deployment> listOfDeployments = deploymentDAO.getAll(); int previousCount = 0; for (int m = listOfDeployments.size() - 1; m >= 0; m--) { Deployment deployment = listOfDeployments.get(m); int currentVersion = deployment.getVersion().intValue(); String fileName = IFileDataProvider.COMMENTS_XML_FILE_NAME; ProcessArchive archiveData = new ProcessArchive(deployment); if (archiveData.getFileData().containsKey(fileName)) { byte[] definitionXml = archiveData.getFileData().get(fileName); Document document = XmlUtils.parseWithoutValidation(definitionXml); List<Element> versionList = document.getRootElement().elements(CommentsParser.VERSION); List<VersionInfo> versionInfos = Lists.newArrayList(); for (int j = previousCount; j < versionList.size(); j++) { Element versionInfoElement = versionList.get(j); VersionInfo versionInfo = new VersionInfo(); versionInfo.setDateTime(versionInfoElement.elementText(CommentsParser.VERSION_DATE)); versionInfo.setAuthor(versionInfoElement.elementText(CommentsParser.VERSION_AUTHOR)); versionInfo.setComment(versionInfoElement.elementText(CommentsParser.VERSION_COMMENT)); versionInfos.add(versionInfo); previousCount++;//w w w. j av a 2s.co m } for (VersionInfo versionInfo : versionInfos) { if (versionInfo.getDate().compareTo(CalendarUtil.dateToCalendar(date1)) >= 0 && versionInfo.getDate().compareTo(CalendarUtil.dateToCalendar(date2)) <= 0) { result.add(new ProcessDefinitionChange(currentVersion, versionInfo)); } } } } return result; }
From source file:z.pn.xmpp.handler.IQAuthHandler.java
License:Open Source License
/** * Handles the received IQ packet./*from w w w .ja va2s. c o m*/ * * @param packet the packet * @return the response to send back * @throws UnauthorizedException if the user is not authorized */ public IQ handleIQ(IQ packet) { IQ reply = null; ClientSession session = sessionManager.getSession(packet.getFrom()); if (session == null) { log.error("Session not found for key " + packet.getFrom()); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.internal_server_error); return reply; } try { Element iq = packet.getElement(); Element query = iq.element("query"); Element queryResponse = probeResponse.createCopy(); if (IQ.Type.get == packet.getType()) { // get query String username = query.elementText("username"); if (username != null) { queryResponse.element("username").setText(username); } reply = IQ.createResultIQ(packet); reply.setChildElement(queryResponse); if (session.getStatus() != Session.STATUS_AUTHENTICATED) { reply.setTo((JID) null); } } else { // set query String resource = query.elementText("resource"); String username = query.elementText("username"); String password = query.elementText("password"); String digest = null; if (query.element("digest") != null) { digest = query.elementText("digest").toLowerCase(); } // Verify the resource if (resource != null) { try { resource = JID.resourceprep(resource); } catch (StringprepException e) { throw new UnauthorizedException("Invalid resource: " + resource, e); } } else { throw new IllegalArgumentException("Invalid resource (empty or null)."); } // Verify the username if (username == null || username.trim().length() == 0) { throw new UnauthorizedException("Invalid username (empty or null)."); } try { Stringprep.nodeprep(username); } catch (StringprepException e) { throw new UnauthorizedException("Invalid username: " + username, e); } username = username.toLowerCase(); // Verify that username and password are correct AuthToken token = null; if (password != null && AuthManager.isPlainSupported()) { token = AuthManager.authenticate(username, password); } else if (digest != null && AuthManager.isDigestSupported()) { token = AuthManager.authenticate(username, session.getStreamID().toString(), digest); } if (token == null) { throw new UnauthenticatedException(); } // Set the session authenticated successfully session.setAuthToken(token, resource); packet.setFrom(session.getAddress()); reply = IQ.createResultIQ(packet); } } catch (Exception ex) { log.error(ex); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); if (ex instanceof IllegalArgumentException) { reply.setError(PacketError.Condition.not_acceptable); } else if (ex instanceof UnauthorizedException) { reply.setError(PacketError.Condition.not_authorized); } else if (ex instanceof UnauthenticatedException) { reply.setError(PacketError.Condition.not_authorized); } else { reply.setError(PacketError.Condition.internal_server_error); } } // Send the response directly to the session if (reply != null) { session.process(reply); } return null; }
From source file:z.pn.xmpp.handler.IQRegisterHandler.java
License:Open Source License
/** * Handles the received IQ packet.//from w w w .ja v a 2s .com * ?IQ? * @param packet the packet * @return the response to send back * @throws UnauthorizedException if the user is not authorized */ public IQ handleIQ(IQ packet) throws UnauthorizedException { IQ reply = null; ClientSession session = sessionManager.getSession(packet.getFrom()); if (session == null) { log.error("Session not found for key " + packet.getFrom()); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.internal_server_error); return reply; } if (IQ.Type.get.equals(packet.getType())) { reply = IQ.createResultIQ(packet); if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { reply.setTo((JID) null); reply.setChildElement(probeResponse.createCopy()); } } else if (IQ.Type.set.equals(packet.getType())) { try { Element query = packet.getChildElement(); if (query.element("remove") != null) { if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { throw new UnauthorizedException(); } } else { String username = query.elementText("username"); String password = query.elementText("password"); String email = query.elementText("email"); String name = query.elementText("name"); // Verify the username if (username != null) { Stringprep.nodeprep(username); } // Deny registration of users with no password if (password == null || password.trim().length() == 0) { reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.not_acceptable); return reply; } if (email != null && email.matches("\\s*")) { email = null; } if (name != null && name.matches("\\s*")) { name = null; } User user; if (session.getStatus() == Session.STATUS_AUTHENTICATED) { user = userService.getUser(session.getUsername()); } else { user = new User(); } user.setUsername(username); user.setPassword(password); user.setEmail(email); user.setName(name); userService.saveUser(user);//?? reply = IQ.createResultIQ(packet); } } catch (Exception ex) { log.error(ex); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); if (ex instanceof UserExistsException) { reply.setError(PacketError.Condition.conflict); } else if (ex instanceof UserNotFoundException) { reply.setError(PacketError.Condition.bad_request); } else if (ex instanceof StringprepException) { reply.setError(PacketError.Condition.jid_malformed); } else if (ex instanceof IllegalArgumentException) { reply.setError(PacketError.Condition.not_acceptable); } else { reply.setError(PacketError.Condition.internal_server_error); } } } // Send the response directly to the session if (reply != null) { session.process(reply);//???? } return null; }