| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
package com.buckosoft.PicMan.dom; |
| 9 | |
|
| 10 | |
import java.util.Date; |
| 11 | |
import java.util.Iterator; |
| 12 | |
import java.util.LinkedList; |
| 13 | |
import java.util.List; |
| 14 | |
|
| 15 | |
import org.dom4j.Document; |
| 16 | |
import org.dom4j.DocumentHelper; |
| 17 | |
import org.dom4j.Element; |
| 18 | |
|
| 19 | |
import com.buckosoft.PicMan.business.PicManFacade; |
| 20 | |
import com.buckosoft.PicMan.domain.ContactParams; |
| 21 | |
import com.buckosoft.PicMan.domain.JobLogEntry; |
| 22 | |
import com.buckosoft.PicMan.domain.User; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 0 | public class HomeStatusDom { |
| 31 | |
static public Document createDocument(PicManFacade pmf, User user) { |
| 32 | 0 | Document document = DocumentHelper.createDocument(); |
| 33 | 0 | Element root = document.addElement("PicManStatus"); |
| 34 | 0 | getDateElement(root); |
| 35 | 0 | getEngineRunningElement(pmf, root); |
| 36 | 0 | getSyncStateElement(pmf, root); |
| 37 | 0 | root.addElement("jobLogCount").addText("" + pmf.getJobLog().size()); |
| 38 | 0 | Element ele = root.addElement("JobLog"); |
| 39 | 0 | getJobLogs(pmf, ele); |
| 40 | 0 | getErrorLog(pmf, root.addElement("ErrorLog")); |
| 41 | 0 | getEngineReportAttributes(pmf, root); |
| 42 | 0 | root.addElement("homeThumbWidth").addText("" + user.getHomePageThumbWidth()); |
| 43 | 0 | root.addElement("homeThumb").addText(pmf.getDB().getRandomHomePagePicName(user)); |
| 44 | 0 | root.addElement("homeThumbDelay").addText("" + user.getHomeThumbDelay()); |
| 45 | 0 | root.addElement("homeDebug").addText(user.isHomeDebug() ? "1" : "0"); |
| 46 | |
|
| 47 | 0 | return document; |
| 48 | |
} |
| 49 | |
|
| 50 | |
private static void getDateElement(Element ele) { |
| 51 | 0 | Date now = new Date(); |
| 52 | 0 | ele.addElement("date").addText(now.toString()); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
private static void getEngineRunningElement(PicManFacade pmf, Element ele) { |
| 56 | 0 | ele.addElement("engineRunningText").addText(pmf.engineRunningShortStatus()); |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
private static void getSyncStateElement(PicManFacade pmf, Element ele) { |
| 60 | 0 | ele.addElement("syncStateText").addText(pmf.getSyncManager().getSyncStateAsText()); |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
private static void getJobLogs(PicManFacade pmf, Element ele) { |
| 64 | 0 | List<JobLogEntry> jl = pmf.getJobLog(); |
| 65 | 0 | int i = 0; |
| 66 | 0 | Iterator<JobLogEntry> iter = jl.iterator(); |
| 67 | 0 | while (iter.hasNext()) { |
| 68 | 0 | if (i >= pmf.getJobLogMaxCount()) |
| 69 | 0 | break; |
| 70 | 0 | JobLogEntry jle = iter.next(); |
| 71 | 0 | ele.add(JobLogEntryDom.getDomElement(pmf, jle)); |
| 72 | 0 | i++; |
| 73 | 0 | } |
| 74 | 0 | } |
| 75 | |
|
| 76 | |
private static void getErrorLog(PicManFacade pmf, Element ele) { |
| 77 | 0 | List<Throwable> el = pmf.getErrorLog(); |
| 78 | 0 | Iterator<Throwable> iter = el.iterator(); |
| 79 | 0 | while (iter.hasNext()) { |
| 80 | 0 | Throwable t = iter.next(); |
| 81 | 0 | if (t.getLocalizedMessage() != null) |
| 82 | 0 | ele.addElement("Error").addText(t.getLocalizedMessage()); |
| 83 | 0 | else if (t.getMessage() != null) |
| 84 | 0 | ele.addElement("Error").addText(t.getMessage()); |
| 85 | |
else |
| 86 | 0 | ele.addElement("Error").addText("No t.getMessage()"); |
| 87 | 0 | } |
| 88 | 0 | } |
| 89 | |
|
| 90 | |
private static void getEngineReportAttributes(PicManFacade pmf, Element ele) { |
| 91 | 0 | LinkedList<ContactParams> contactParamsList = pmf.getBatchManager().getContactManager().determineContactsToMake(); |
| 92 | |
|
| 93 | 0 | List<String> otherJobs = pmf.getBatchManager().getOtherJobsQueued(); |
| 94 | 0 | int jobsToDo = contactParamsList.size() + otherJobs.size() + pmf.getMosaicMan().getMosaicQueueListString().size(); |
| 95 | 0 | ele.addElement("engineReportTodo").addText("" + jobsToDo); |
| 96 | 0 | ele.addElement("engineReportStatus").addText(pmf.engineRunningShortStatus()); |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
} |