📄 conversationutils.java
字号:
" " +
coninfo.getDuration(),
FontFactory.getFont(FontFactory.HELVETICA, 12,
Font.BOLD));
document.add(duration);
Paragraph messageCount = new Paragraph(
LocaleUtils
.getLocalizedString("archive.search.pdf.messagecount", "monitoring") +
" " +
conversation.getMessageCount(),
FontFactory.getFont(FontFactory.HELVETICA, 12,
Font.BOLD));
document.add(messageCount);
document.add(Chunk.NEWLINE);
Paragraph messageParagraph;
for (ArchivedMessage message : conversation.getMessages()) {
String time = JiveGlobals.formatTime(message.getSentDate());
String from = message.getFromJID().getNode();
if (conversation.getRoom() != null) {
from = message.getToJID().getResource();
}
String body = message.getBody();
String prefix;
if (!message.isRoomEvent()) {
prefix = "[" + time + "] " + from + ": ";
Font font = colorMap.get(message.getFromJID().toString());
if (font == null) {
font = colorMap.get(message.getFromJID().toBareJID());
}
if (font == null) {
font = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, Color.BLACK);
}
messageParagraph = new Paragraph(new Chunk(prefix, font));
}
else {
prefix = "[" + time + "] ";
messageParagraph = new Paragraph(new Chunk(prefix, roomEvent));
}
messageParagraph.add(body);
messageParagraph.add(" ");
document.add(messageParagraph);
}
document.close();
return baos;
}
catch (DocumentException e) {
Log.error("error creating PDF document: " + e.getMessage(), e);
return null;
}
}
private ConversationInfo toConversationInfo(Conversation conversation,
boolean formatParticipants) {
final ConversationInfo info = new ConversationInfo();
// Set participants
Collection<JID> col = conversation.getParticipants();
if (conversation.getRoom() == null) {
JID user1 = (JID)col.toArray()[0];
info.setParticipant1(formatJID(formatParticipants, user1));
JID user2 = (JID)col.toArray()[1];
info.setParticipant2(formatJID(formatParticipants, user2));
}
else {
info.setConversationID(conversation.getConversationID());
JID[] occupants = col.toArray(new JID[col.size()]);
String[] jids = new String[col.size()];
for (int i = 0; i < occupants.length; i++) {
jids[i] = formatJID(formatParticipants, occupants[i]);
}
info.setAllParticipants(jids);
}
Map<String, String> cssLabels = new HashMap<String, String>();
int count = 0;
for (JID jid : col) {
if (!cssLabels.containsKey(jid.toString())) {
if (conversation.getRoom() == null) {
if (count % 2 == 0) {
cssLabels.put(jid.toBareJID(), "conversation-label2");
}
else {
cssLabels.put(jid.toBareJID(), "conversation-label1");
}
count++;
}
else {
cssLabels.put(jid.toString(), "conversation-label4");
}
}
}
// Set date
info.setDate(JiveGlobals.formatDateTime(conversation.getStartDate()));
info.setLastActivity(JiveGlobals.formatTime(conversation.getLastActivity()));
// Create body.
final StringBuilder builder = new StringBuilder();
builder.append("<table width=100%>");
for (ArchivedMessage message : conversation.getMessages()) {
String time = JiveGlobals.formatTime(message.getSentDate());
String from = message.getFromJID().getNode();
if (conversation.getRoom() != null) {
from = message.getToJID().getResource();
}
String cssLabel = cssLabels.get(message.getFromJID().toBareJID());
String body = message.getBody();
builder.append("<tr valign=top>");
if (!message.isRoomEvent()) {
builder.append("<td width=1% nowrap class=" + cssLabel + ">").append("[")
.append(time).append("]").append("</td>");
builder.append("<td width=1% class=" + cssLabel + ">").append(from).append(": ")
.append("</td>");
builder.append("<td class=conversation-body>").append(body).append("</td");
}
else {
builder.append("<td width=1% nowrap class=conversation-label3>").append("[")
.append(time).append("]").append("</td>");
builder.append("<td colspan=2 class=conversation-label3><i>").append(body)
.append("</i></td");
}
builder.append("</tr>");
}
if (conversation.getMessages().size() == 0) {
builder.append("<span class=small-description>" +
LocaleUtils.getLocalizedString("archive.search.results.archive_disabled",
"monitoring") +
"</a>");
}
info.setBody(builder.toString());
// Set message count
info.setMessageCount(conversation.getMessageCount());
long duration =
(conversation.getLastActivity().getTime() - conversation.getStartDate().getTime());
info.setDuration(duration);
return info;
}
private String formatJID(boolean html, JID jid) {
String formattedJID;
if (html) {
UserManager userManager = UserManager.getInstance();
if (XMPPServer.getInstance().isLocal(jid) &&
userManager.isRegisteredUser(jid.getNode())) {
formattedJID = "<a href='/user-properties.jsp?username=" +
jid.getNode() + "'>" + jid.toBareJID() + "</a>";
}
else {
formattedJID = jid.toBareJID();
}
}
else {
formattedJID = jid.toBareJID();
}
return formattedJID;
}
class PDFEventListener extends PdfPageEventHelper {
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
try {
cb.setColorStroke(new Color(156, 156, 156));
cb.setLineWidth(2);
cb.moveTo(document.leftMargin(), document.bottomMargin() - 5);
cb.lineTo(document.getPageSize().width() - document.rightMargin(),
document.bottomMargin() - 5);
cb.stroke();
ClassLoader classLoader = ConversationUtils.class.getClassLoader();
Enumeration<URL> providerEnum = classLoader.getResources("images/pdf_generatedbyof.gif");
while (providerEnum.hasMoreElements()) {
Image gif = Image.getInstance(providerEnum.nextElement());
cb.addImage(gif, 221, 0, 0, 28, (int)document.leftMargin(),
(int)document.bottomMargin() - 35);
}
}
catch (Exception e) {
Log.error("error drawing PDF footer: " + e.getMessage());
}
cb.saveState();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -