use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class UserProperties method populateResponseFields.
private void populateResponseFields(DataForm form, List<String> accounts) {
FormField jidField = form.addField();
jidField.setVariable("accountjids");
FormField emailField = form.addField();
emailField.setVariable("email");
FormField nameField = form.addField();
nameField.setVariable("name");
UserManager manager = UserManager.getInstance();
for (String account : accounts) {
User user;
try {
JID jid = new JID(account);
user = manager.getUser(jid.getNode());
} catch (Exception ex) {
continue;
}
jidField.addValue(account);
emailField.addValue(user.getEmail());
nameField.addValue(user.getName());
}
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class WebManager method getPageProperty.
public int getPageProperty(String pageName, String property, int defaultValue) {
User user = getUser();
if (user != null) {
String values = user.getProperties().get(property);
if (values != null) {
StringTokenizer tokens = new StringTokenizer(values, ",=");
while (tokens.hasMoreTokens()) {
String page = tokens.nextToken().trim();
String rows = tokens.nextToken().trim();
if (pageName.equals(page)) {
try {
return Integer.parseInt(rows);
} catch (NumberFormatException e) {
return defaultValue;
}
}
}
}
}
return defaultValue;
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class IQvCardHandler method handleIQ.
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
IQ result = IQ.createResultIQ(packet);
IQ.Type type = packet.getType();
if (type.equals(IQ.Type.set)) {
try {
User user = userManager.getUser(packet.getFrom().getNode());
Element vcard = packet.getChildElement();
if (vcard != null) {
VCardManager.getInstance().setVCard(user.getUsername(), vcard);
}
} catch (UserNotFoundException e) {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
} catch (Exception e) {
Log.error(e.getMessage(), e);
result.setError(PacketError.Condition.internal_server_error);
}
} else if (type.equals(IQ.Type.get)) {
JID recipient = packet.getTo();
// If no TO was specified then get the vCard of the sender of the packet
if (recipient == null) {
recipient = packet.getFrom();
}
// By default return an empty vCard
result.setChildElement("vCard", "vcard-temp");
// Only try to get the vCard values of non-anonymous users
if (recipient != null) {
if (recipient.getNode() != null && server.isLocal(recipient)) {
VCardManager vManager = VCardManager.getInstance();
Element userVCard = vManager.getVCard(recipient.getNode());
if (userVCard != null) {
// Check if the requester wants to ignore some vCard's fields
Element filter = packet.getChildElement().element(QName.get("filter", "vcard-temp-filter"));
if (filter != null) {
// Create a copy so we don't modify the original vCard
userVCard = userVCard.createCopy();
// Ignore fields requested by the user
for (Iterator toFilter = filter.elementIterator(); toFilter.hasNext(); ) {
Element field = (Element) toFilter.next();
Element fieldToRemove = userVCard.element(field.getName());
if (fieldToRemove != null) {
fieldToRemove.detach();
}
}
}
result.setChildElement(userVCard);
}
} else {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
}
} else {
result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
}
} else {
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.not_acceptable);
}
return result;
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class EmailTranscriptEvent method chatSupportFinished.
public void chatSupportFinished(Workgroup workgroup, String sessionID) {
Log.debug("Chat Support Finished, sending transcripts");
final EmailService emailService = EmailService.getInstance();
String property = JiveGlobals.getProperty("mail.configured");
if (!ModelUtil.hasLength(property)) {
Log.debug("Mail settings are not configured, transcripts will not be sent.");
return;
}
final ChatSession chatSession = ChatTranscriptManager.getChatSession(sessionID);
if (chatSession == null || chatSession.getFirstSession() == null) {
return;
}
final StringBuilder builder = new StringBuilder();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyy hh:mm a");
// Get duration of conversation
Date date = new Date(chatSession.getFirstSession().getStartTime());
int duration = getChatDuration(date, chatSession);
TreeMap<String, List<String>> map = new TreeMap<String, List<String>>(chatSession.getMetadata());
String body = JiveGlobals.getProperty("chat.transcript.body");
if (ModelUtil.hasLength(body)) {
builder.append(body).append("\n\n");
}
builder.append("formname=chat transcript\n");
extractAndDisplay(builder, "question", map);
display(builder, "fullname", chatSession.getCustomerName());
extractAndDisplay(builder, "email", map);
extractAndDisplay(builder, "Location", map);
extractAndDisplay(builder, "userID", map);
extractAndDisplay(builder, "username", map);
extractAndDisplay(builder, "workgroup", map);
display(builder, "chatduration", String.valueOf(duration));
display(builder, "chatdate", formatter.format(date));
if (chatSession.getFirstSession() != null && chatSession.getFirstSession().getAgentJID() != null) {
try {
display(builder, "agent", new JID(chatSession.getFirstSession().getAgentJID()).toBareJID());
} catch (Exception e) {
Log.debug("Could not display agent in transcript.", e);
}
}
for (Iterator<Map.Entry<String, List<String>>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, List<String>> entry = iterator.next();
display(builder, entry.getKey(), getListItem(entry.getValue()));
}
builder.append("ctranscript=\n");
builder.append(ChatTranscriptManager.getTextTranscriptFromSessionID(sessionID));
String subject = JiveGlobals.getProperty("chat.transcript.subject");
String from = JiveGlobals.getProperty("chat.transcript.from");
String to = JiveGlobals.getProperty("chat.transcript.to");
if (!ModelUtil.hasLength(subject) || !ModelUtil.hasLength(from)) {
Log.debug("Transcript settings (chat.transcript.subject, chat.transcript.from) are not configured, " + "transcripts will not be sent.");
return;
}
if (ModelUtil.hasLength(to)) {
emailService.sendMessage("Chat Transcript", to, "Chat Transcript", from, subject, builder.toString(), null);
Log.debug("Transcript sent to " + to);
}
// NOTE: Do not sent to the customer. They will receive a prompt for a seperate chat transcript
// that does not contain agent information.
// Send to Agents
UserManager um = UserManager.getInstance();
for (Iterator<AgentChatSession> iterator = chatSession.getAgents(); iterator.hasNext(); ) {
AgentChatSession agentSession = iterator.next();
try {
User user = um.getUser(new JID(agentSession.getAgentJID()).getNode());
emailService.sendMessage("Chat Transcript", user.getEmail(), "Chat Transcript", from, subject, builder.toString(), null);
Log.debug("Transcript sent to agent " + agentSession.getAgentJID());
} catch (UserNotFoundException e) {
Log.error("Email Transcript Not Sent:" + "Could not load agent user object for jid " + agentSession.getAgentJID());
}
}
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class BookmarkInterceptor method addBookmarkElement.
/**
* Adds a Bookmark to the users defined list of bookmarks.
*
* @param jid the users jid.
* @param bookmark the bookmark to be added.
* @param element the storage element to append to.
*/
private void addBookmarkElement(JID jid, Bookmark bookmark, Element element) {
final UserManager userManager = UserManager.getInstance();
try {
userManager.getUser(jid.getNode());
} catch (UserNotFoundException e) {
return;
}
// do not add duplicate bookmarks.
if (bookmark.getType() == Bookmark.Type.url) {
Element urlBookmarkElement = urlExists(element, bookmark.getValue());
if (urlBookmarkElement == null) {
urlBookmarkElement = element.addElement("url");
urlBookmarkElement.addAttribute("name", bookmark.getName());
urlBookmarkElement.addAttribute("url", bookmark.getValue());
// Add an RSS attribute to the bookmark if it's defined. RSS isn't an
// official part of the Bookmark JEP, but we define it as a logical
// extension.
boolean rss = Boolean.valueOf(bookmark.getProperty("rss"));
if (rss) {
urlBookmarkElement.addAttribute("rss", Boolean.toString(rss));
}
}
appendSharedElement(urlBookmarkElement);
} else // Otherwise it's a conference bookmark.
{
try {
Element conferenceElement = conferenceExists(element, bookmark.getValue());
// reply.
if (conferenceElement == null) {
conferenceElement = element.addElement("conference");
conferenceElement.addAttribute("name", bookmark.getName());
boolean autojoin = Boolean.valueOf(bookmark.getProperty("autojoin"));
conferenceElement.addAttribute("autojoin", Boolean.toString(autojoin));
conferenceElement.addAttribute("jid", bookmark.getValue());
boolean nameasnick = Boolean.valueOf(bookmark.getProperty("nameasnick"));
if (nameasnick) {
User currentUser = userManager.getUser(jid.getNode());
Element nick = conferenceElement.addElement("nick");
nick.addText(currentUser.getName());
}
}
appendSharedElement(conferenceElement);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
}
Aggregations