Example usage for org.dom4j Element add

List of usage examples for org.dom4j Element add

Introduction

In this page you can find the example usage for org.dom4j Element add.

Prototype

void add(Namespace namespace);

Source Link

Document

Adds the given Namespace to this element.

Usage

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

License:Open Source License

private Element extractInfoContact(PSTContact contact) {
    Element root = XmlDom.factory.createElement("contact");
    String value = null;//from w w w  .jav a2s . c om

    value = contact.getAccount();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("AccountName").addText(value));
    }
    value = contact.getGivenName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("GivenName").addText(value));
    }
    value = contact.getSurname();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("SurName").addText(value));
    }
    value = contact.getSMTPAddress();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("SMTPAddress").addText(value));
    }
    value = contact.getEmail1AddressType();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Email1AddressType").addText(value));
    }
    value = contact.getEmail1EmailAddress();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Email1Address").addText(value));
    }
    value = contact.getCallbackTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("CallbackTelephoneNumber").addText(value));
    }
    value = contact.getGeneration();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Generation").addText(value));
    }
    value = contact.getGovernmentIdNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("GovernmentIDNumber").addText(value));
    }
    value = contact.getBusinessTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessTelephoneNumber").addText(value));
    }
    value = contact.getHomeTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeTelephoneNumber").addText(value));
    }
    value = contact.getInitials();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Initials").addText(value));
    }
    value = contact.getKeyword();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Keyword").addText(value));
    }
    value = contact.getLanguage();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Language").addText(value));
    }
    value = contact.getLocation();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Location").addText(value));
    }
    value = contact.getMhsCommonName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("MHSCommonName").addText(value));
    }
    value = contact.getOrganizationalIdNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OrganizationalIdnumber").addText(value));
    }
    value = contact.getOriginalDisplayName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OriginalDisplayName").addText(value));
    }
    value = contact.getPostalAddress();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PostalAddress").addText(value));
    }
    value = contact.getCompanyName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("CompanyName").addText(value));
    }
    value = contact.getTitle();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Title").addText(value));
    }
    value = contact.getDepartmentName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("DepartmentName").addText(value));
    }
    value = contact.getOfficeLocation();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OfficeLocation").addText(value));
    }
    value = contact.getPrimaryTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PrimaryTelephone").addText(value));
    }
    value = contact.getBusiness2TelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("SecondaryBusinessTelephoneNumber").addText(value));
    }
    value = contact.getMobileTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("MobileTelephoneNumber").addText(value));
    }
    value = contact.getRadioTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("RadioTelephoneNumber").addText(value));
    }
    value = contact.getCarTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("CarTelephoneNumber").addText(value));
    }
    value = contact.getOtherTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OtherTelephoneNumber").addText(value));
    }
    value = contact.getTransmittableDisplayName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("TransmittableDisplayName").addText(value));
    }
    value = contact.getPagerTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PagerTelephoneNumber").addText(value));
    }
    value = contact.getPrimaryFaxNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PrimaryFaxNumber").addText(value));
    }
    value = contact.getBusinessFaxNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessFaxNumber").addText(value));
    }
    value = contact.getHomeFaxNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeFaxNumber").addText(value));
    }
    value = contact.getBusinessAddressCountry();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessAddressCountry").addText(value));
    }
    value = contact.getBusinessAddressCity();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessAddressCity").addText(value));
    }
    value = contact.getBusinessAddressStateOrProvince();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessAddressState").addText(value));
    }
    value = contact.getBusinessAddressStreet();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessAddressStreet").addText(value));
    }
    value = contact.getBusinessPostalCode();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessPostalCode").addText(value));
    }
    value = contact.getBusinessPoBox();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessPOBox").addText(value));
    }
    value = contact.getTelexNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("TelexNumber").addText(value));
    }
    value = contact.getIsdnNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("ISDNNumber").addText(value));
    }
    value = contact.getAssistantTelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("AssistantTelephoneNumber").addText(value));
    }
    value = contact.getHome2TelephoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeTelephone2").addText(value));
    }
    value = contact.getAssistant();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Assistant").addText(value));
    }
    value = contact.getHobbies();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Hobbies").addText(value));
    }
    value = contact.getMiddleName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("MiddleName").addText(value));
    }
    value = contact.getDisplayNamePrefix();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("DisplayNamePrefix").addText(value));
    }
    value = contact.getProfession();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Profession").addText(value));
    }
    value = contact.getPreferredByName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PreferredByName").addText(value));
    }
    value = contact.getSpouseName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("SpouseName").addText(value));
    }
    value = contact.getComputerNetworkName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("ComputerNetworkName").addText(value));
    }
    value = contact.getCustomerId();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("CustomerID").addText(value));
    }
    value = contact.getTtytddPhoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("TTY_TDDPhone").addText(value));
    }
    value = contact.getFtpSite();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("FtpSite").addText(value));
    }
    value = contact.getManagerName();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("ManagerName").addText(value));
    }
    value = contact.getNickname();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Nickname").addText(value));
    }
    value = contact.getPersonalHomePage();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PersonalHomePage").addText(value));
    }
    value = contact.getBusinessHomePage();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("BusinessHomePage").addText(value));
    }
    value = contact.getCompanyMainPhoneNumber();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("CompanyMainPhone").addText(value));
    }
    value = contact.getChildrensNames();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("ChildrensNames").addText(value));
    }
    value = contact.getHomeAddressCity();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeAddressCity").addText(value));
    }
    value = contact.getHomeAddressCountry();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeAddressCountry").addText(value));
    }
    value = contact.getHomeAddressPostalCode();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeAddressPostalCode").addText(value));
    }
    value = contact.getHomeAddressStateOrProvince();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeAddressState").addText(value));
    }
    value = contact.getHomeAddressStreet();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeAddressStreet").addText(value));
    }
    value = contact.getHomeAddressPostOfficeBox();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("HomeAddressPostOfficeBox").addText(value));
    }
    value = contact.getOtherAddressCity();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OtherAddressCity").addText(value));
    }
    value = contact.getOtherAddressCountry();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OtherAddressCountry").addText(value));
    }
    value = contact.getOtherAddressPostalCode();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OtherAddressPostalCode").addText(value));
    }
    value = contact.getOtherAddressStateOrProvince();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OtherAddressState").addText(value));
    }
    value = contact.getOtherAddressStreet();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OtherAddressStreet").addText(value));
    }
    value = contact.getOtherAddressPostOfficeBox();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("OtherAddressPostOfficeBox").addText(value));
    }
    value = contact.getBody();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("contactBodyref").addText(value));
    }
    return root;
}

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

License:Open Source License

private Element extractInfoTask(PSTTask task) {
    Element root = XmlDom.factory.createElement("task");

    String value = null;//  www .j  a va  2s  . c o m

    Integer ival = task.getTaskStatus();
    root.add(XmlDom.factory.createElement("TaskStatus").addText(ival.toString()));
    Double dval = task.getPercentComplete();
    root.add(XmlDom.factory.createElement("PercentComplete").addText(dval.toString()));
    Boolean bval = task.isTeamTask();
    root.add(XmlDom.factory.createElement("isTeamTask").addText(bval.toString()));
    Date date = task.getTaskStartDate();
    if (date != null) {
        root.add(XmlDom.factory.createElement("TaskStartDate").addText(date.toString()));
    }
    date = task.getTaskDueDate();
    if (date != null) {
        root.add(XmlDom.factory.createElement("TaskDueDate").addText(date.toString()));
    }
    date = task.getTaskDateCompleted();
    if (date != null) {
        root.add(XmlDom.factory.createElement("TaskDateCompleted").addText(date.toString()));
    }
    ival = task.getTaskActualEffort();
    root.add(XmlDom.factory.createElement("TaskActualEffort").addText(ival.toString()));
    ival = task.getTaskEstimatedEffort();
    root.add(XmlDom.factory.createElement("TaskEstimatedEffort").addText(ival.toString()));
    ival = task.getTaskVersion();
    root.add(XmlDom.factory.createElement("TaskVersion").addText(ival.toString()));
    bval = task.isTaskComplete();
    root.add(XmlDom.factory.createElement("isTaskComplete").addText(bval.toString()));
    value = task.getTaskOwner();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("TaskOwner").addText(value));
    }
    value = task.getTaskAssigner();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("TaskAssigner").addText(value));
    }
    value = task.getTaskLastUser();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("TaskLastUser").addText(value));
    }
    ival = task.getTaskOrdinal();
    root.add(XmlDom.factory.createElement("TaskOrdinal").addText(ival.toString()));
    bval = task.isTaskFRecurring();
    root.add(XmlDom.factory.createElement("isTaskFRecurring").addText(bval.toString()));
    value = task.getTaskRole();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("TaskRole").addText(value));
    }
    ival = task.getTaskOwnership();
    root.add(XmlDom.factory.createElement("TaskOwnership").addText(ival.toString()));
    ival = task.getAcceptanceState();
    root.add(XmlDom.factory.createElement("AcceptanceState").addText(ival.toString()));
    return root;
}

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

License:Open Source License

private Element extractInfoActivity(PSTActivity activity) {
    Element root = XmlDom.factory.createElement("activity");

    String value = null;//from ww w. jav  a  2 s.c  o m

    value = activity.getLogType();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("LogType").addText(value));
    }
    Date date = activity.getLogStart();
    if (date != null) {
        root.add(XmlDom.factory.createElement("LogStart").addText(date.toString()));
    }
    Integer ival = activity.getLogDuration();
    root.add(XmlDom.factory.createElement("LogDuration").addText(ival.toString()));
    date = activity.getLogEnd();
    if (date != null) {
        root.add(XmlDom.factory.createElement("LogEnd").addText(date.toString()));
    }
    ival = activity.getLogFlags();
    root.add(XmlDom.factory.createElement("LogFlags").addText(ival.toString()));
    Boolean bval = activity.isDocumentPrinted();
    root.add(XmlDom.factory.createElement("isDocumentPrinted").addText(bval.toString()));
    bval = activity.isDocumentSaved();
    root.add(XmlDom.factory.createElement("isDocumentSaved").addText(bval.toString()));
    bval = activity.isDocumentRouted();
    root.add(XmlDom.factory.createElement("isDocumentRouted").addText(bval.toString()));
    bval = activity.isDocumentPosted();
    root.add(XmlDom.factory.createElement("isDocumentPosted").addText(bval.toString()));
    value = activity.getLogTypeDesc();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("LogTypeDesc").addText(value));
    }
    return root;
}

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

License:Open Source License

private Element extractInfoRss(PSTRss rss) {
    Element root = XmlDom.factory.createElement("rss");

    String value = null;//from w  w  w.ja  v a  2  s . co m

    value = rss.getPostRssChannelLink();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PostRssChannelLink").addText(value));
    }
    value = rss.getPostRssItemLink();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PostRssItemLink").addText(value));
    }
    Integer ival = rss.getPostRssItemHash();
    root.add(XmlDom.factory.createElement("PostRssItemHash").addText(ival.toString()));
    value = rss.getPostRssItemGuid();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PostRssItemGuid").addText(value));
    }
    value = rss.getPostRssChannel();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PostRssChannel").addText(value));
    }
    value = rss.getPostRssItemXml();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PostRssItemXml").addText(value));
    }
    value = rss.getPostRssSubscription();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("PostRssSubscription").addText(value));
    }
    return root;
}

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

License:Open Source License

private Element extractInfoAppointment(PSTAppointment appointment) {
    Element root = XmlDom.factory.createElement("appointment");

    String value = null;//from w w  w. j  a  v a 2  s.  c  om

    value = appointment.getLocation();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("Location").addText(value));
    }
    Date date = appointment.getStartTime();
    if (date != null) {
        root.add(XmlDom.factory.createElement("StartTime").addText(date.toString()));
    }
    PSTTimeZone zone = appointment.getStartTimeZone();
    if (zone != null) {
        root.add(XmlDom.factory.createElement("StartTimeZone").addText(TZString(zone)));
    }
    date = appointment.getEndTime();
    if (date != null) {
        root.add(XmlDom.factory.createElement("EndTime").addText(date.toString()));
    }
    zone = appointment.getEndTimeZone();
    if (zone != null) {
        root.add(XmlDom.factory.createElement("EndTimeZone").addText(TZString(zone)));
    }
    zone = appointment.getRecurrenceTimeZone();
    if (zone != null) {
        root.add(XmlDom.factory.createElement("RecurrenceTimeZone").addText(TZString(zone)));
    }
    Integer ival = appointment.getDuration();
    root.add(XmlDom.factory.createElement("Duration").addText(ival.toString()));
    ival = appointment.getMeetingStatus();
    root.add(XmlDom.factory.createElement("MeetingStatus").addText(ival.toString()));
    ival = appointment.getResponseStatus();
    root.add(XmlDom.factory.createElement("ResponseStatus").addText(ival.toString()));
    Boolean bval = appointment.isRecurring();
    root.add(XmlDom.factory.createElement("isRecurring").addText(bval.toString()));
    date = appointment.getRecurrenceBase();
    if (date != null) {
        root.add(XmlDom.factory.createElement("RecurrenceBase").addText(date.toString()));
    }
    ival = appointment.getRecurrenceType();
    root.add(XmlDom.factory.createElement("RecurrenceType").addText(ival.toString()));
    value = appointment.getRecurrencePattern();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("RecurrencePattern").addText(value));
    }
    value = appointment.getAllAttendees();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("AllAttendees").addText(value));
    }
    value = appointment.getToAttendees();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("ToAttendees").addText(value));
    }
    value = appointment.getCCAttendees();
    if (value != null && !value.isEmpty()) {
        root.add(XmlDom.factory.createElement("CCAttendees").addText(value));
    }
    ival = appointment.getAppointmentSequence();
    root.add(XmlDom.factory.createElement("AppointmentSequence").addText(ival.toString()));

    // online meeting properties
    bval = appointment.isOnlineMeeting();
    if (bval) {
        root.add(XmlDom.factory.createElement("isOnlineMeeting").addText(bval.toString()));
        ival = appointment.getNetMeetingType();
        root.add(XmlDom.factory.createElement("NetMeetingType").addText(ival.toString()));
        value = appointment.getNetMeetingServer();
        if (value != null && !value.isEmpty()) {
            root.add(XmlDom.factory.createElement("NetMeetingServer").addText(value));
        }
        value = appointment.getNetMeetingOrganizerAlias();
        if (value != null && !value.isEmpty()) {
            root.add(XmlDom.factory.createElement("NetMeetingOrganizerAlias").addText(value));
        }
        bval = appointment.getNetMeetingAutostart();
        root.add(XmlDom.factory.createElement("NetMeetingAutostart").addText(bval.toString()));
        bval = appointment.getConferenceServerAllowExternal();
        root.add(XmlDom.factory.createElement("ConferenceServerAllowExternal").addText(bval.toString()));
        value = appointment.getNetMeetingDocumentPathName();
        if (value != null && !value.isEmpty()) {
            root.add(XmlDom.factory.createElement("NetMeetingDocumentPathName").addText(value));
        }
        value = appointment.getNetShowURL();
        if (value != null && !value.isEmpty()) {
            root.add(XmlDom.factory.createElement("NetShowURL").addText(value));
        }
        date = appointment.getAttendeeCriticalChange();
        if (date != null) {
            root.add(XmlDom.factory.createElement("AttendeeCriticalChange").addText(date.toString()));
        }
        date = appointment.getOwnerCriticalChange();
        if (date != null) {
            root.add(XmlDom.factory.createElement("OwnerCriticalChange").addText(date.toString()));
        }
        value = appointment.getConferenceServerPassword();
        if (value != null && !value.isEmpty()) {
            root.add(XmlDom.factory.createElement("ConferenceServerPassword").addText(value));
        }
        bval = appointment.getAppointmentCounterProposal();
        root.add(XmlDom.factory.createElement("AppointmentCounterProposal").addText(bval.toString()));
        bval = appointment.isSilent();
        root.add(XmlDom.factory.createElement("isSilent").addText(bval.toString()));
        value = appointment.getRequiredAttendees();
        if (value != null && !value.isEmpty()) {
            root.add(XmlDom.factory.createElement("RequiredAttendees").addText(value));
        }
    }
    return root;
}

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

License:Open Source License

private String extractInfoMessage(PSTMessage email) {
    if (email instanceof PSTContact) {
        Element node = extractInfoContact((PSTContact) email);
        config.addRankId(node);//from  ww  w .  j  ava2 s.  c om
        //node.addAttribute(EMAIL_FIELDS.rankId.name, id);
        Element identifications = XmlDom.factory.createElement("identification");
        Element identity = XmlDom.factory.createElement("identity");
        identity.addAttribute("format", "Microsoft Outlook Address Book");
        identity.addAttribute("mime", "application/vnd.ms-outlook");
        identifications.add(identity);
        node.add(identifications);
        node.addAttribute(EMAIL_FIELDS.status.name, "ok");
        currentRoot.add(node);
        return "";
    } else if (email instanceof PSTTask) {
        Element node = extractInfoTask((PSTTask) email);
        config.addRankId(node);
        //node.addAttribute(EMAIL_FIELDS.rankId.name, id);
        Element identifications = XmlDom.factory.createElement("identification");
        Element identity = XmlDom.factory.createElement("identity");
        identity.addAttribute("format", "Microsoft Outlook Task");
        identity.addAttribute("mime", "application/vnd.ms-outlook");
        identifications.add(identity);
        node.add(identifications);
        node.addAttribute(EMAIL_FIELDS.status.name, "ok");
        currentRoot.add(node);
        return "";
    } else if (email instanceof PSTActivity) {
        Element node = extractInfoActivity((PSTActivity) email);
        config.addRankId(node);
        //node.addAttribute(EMAIL_FIELDS.rankId.name, id);
        Element identifications = XmlDom.factory.createElement("identification");
        Element identity = XmlDom.factory.createElement("identity");
        identity.addAttribute("format", "Microsoft Outlook Activity");
        identity.addAttribute("mime", "application/vnd.ms-outlook");
        identifications.add(identity);
        node.add(identifications);
        node.addAttribute(EMAIL_FIELDS.status.name, "ok");
        currentRoot.add(node);
        return "";
    } else if (email instanceof PSTRss) {
        Element node = extractInfoRss((PSTRss) email);
        config.addRankId(node);
        //node.addAttribute(EMAIL_FIELDS.rankId.name, id);
        Element identifications = XmlDom.factory.createElement("identification");
        Element identity = XmlDom.factory.createElement("identity");
        identity.addAttribute("format", "Microsoft Outlook Rss");
        identity.addAttribute("mime", "application/vnd.ms-outlook");
        identifications.add(identity);
        node.add(identifications);
        node.addAttribute(EMAIL_FIELDS.status.name, "ok");
        currentRoot.add(node);
        return "";
    } else if (email instanceof PSTAppointment) {
        Element node = extractInfoAppointment((PSTAppointment) email);
        config.addRankId(node);
        //node.addAttribute(EMAIL_FIELDS.rankId.name, id);
        Element identifications = XmlDom.factory.createElement("identification");
        Element identity = XmlDom.factory.createElement("identity");
        identity.addAttribute("format", "Microsoft Outlook Appointment");
        identity.addAttribute("mime", "application/vnd.ms-outlook");
        identifications.add(identity);
        node.add(identifications);
        node.addAttribute(EMAIL_FIELDS.status.name, "ok");
        currentRoot.add(node);
        return "";
    }
    Element root = XmlDom.factory.createElement(EMAIL_FIELDS.formatMSG.name);
    Element keywords = XmlDom.factory.createElement(EMAIL_FIELDS.keywords.name);
    Element metadata = XmlDom.factory.createElement(EMAIL_FIELDS.metadata.name);

    String id = config.addRankId(root);
    //root.addAttribute(EMAIL_FIELDS.rankId.name, id);
    Element identifications = XmlDom.factory.createElement("identification");
    Element identity = XmlDom.factory.createElement("identity");
    identity.addAttribute("format", "Microsoft Outlook Email Message");
    identity.addAttribute("mime", "application/vnd.ms-outlook");
    identity.addAttribute("puid", "x-fmt/430");
    identity.addAttribute("extensions", "msg");
    identifications.add(identity);
    root.add(identifications);

    Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.from.name);
    addAddress(sub, EMAIL_FIELDS.fromUnit.name, email.getSenderName(), email.getSenderEmailAddress());
    metadata.add(sub);
    int NumberOfRecipients = 0;
    Element toRecipients = XmlDom.factory.createElement(EMAIL_FIELDS.toRecipients.name);
    Element ccRecipients = XmlDom.factory.createElement(EMAIL_FIELDS.ccRecipients.name);
    Element bccRecipients = XmlDom.factory.createElement(EMAIL_FIELDS.bccRecipients.name);
    try {
        NumberOfRecipients = email.getNumberOfRecipients();
    } catch (PSTException e1) {
    } catch (IOException e1) {
    }
    for (int i = 0; i < NumberOfRecipients; i++) {
        try {
            PSTRecipient recipient = email.getRecipient(i);
            // MAPI_TO = 1; MAPI_CC = 2; MAPI_BCC = 3;
            Element choose = null;
            String type = "??";
            switch (recipient.getRecipientType()) {
            case PSTRecipient.MAPI_TO:
                type = EMAIL_FIELDS.toUnit.name;
                choose = toRecipients;
                break;
            case PSTRecipient.MAPI_CC:
                type = EMAIL_FIELDS.ccUnit.name;
                choose = ccRecipients;
                break;
            case PSTRecipient.MAPI_BCC:
                type = EMAIL_FIELDS.bccUnit.name;
                choose = bccRecipients;
                break;
            }
            if (choose != null) {
                addAddress(choose, type, recipient.getDisplayName(), recipient.getEmailAddress());
            }
        } catch (PSTException e) {
        } catch (IOException e) {
        }
    }
    if (toRecipients.hasContent()) {
        metadata.add(toRecipients);
    }
    if (ccRecipients.hasContent()) {
        metadata.add(ccRecipients);
    }
    if (bccRecipients.hasContent()) {
        metadata.add(bccRecipients);
    }
    // get the subject
    String Subject = email.getSubject();
    if (Subject != null) {
        sub = XmlDom.factory.createElement(EMAIL_FIELDS.subject.name);
        sub.setText(StringUtils.unescapeHTML(Subject, true, false));
        metadata.add(sub);
    }
    // Conversation topic This is basically the subject from which Fwd:, Re, etc.
    Subject = email.getConversationTopic();
    if (Subject != null) {
        sub = XmlDom.factory.createElement(EMAIL_FIELDS.conversationTopic.name);
        sub.setText(StringUtils.unescapeHTML(Subject, true, false));
        metadata.add(sub);
    }
    // get the client submit time (sent ?)
    Date ClientSubmitTime = email.getClientSubmitTime();
    if (ClientSubmitTime != null) {
        sub = XmlDom.factory.createElement(EMAIL_FIELDS.sentDate.name);
        sub.setText(ClientSubmitTime.toString());
        metadata.add(sub);
    }
    // Message delivery time
    Date MessageDeliveryTime = email.getMessageDeliveryTime();
    if (MessageDeliveryTime != null) {
        sub = XmlDom.factory.createElement(EMAIL_FIELDS.receivedDate.name);
        sub.setText(MessageDeliveryTime.toString());
        metadata.add(sub);
    }
    // Transport message headers ASCII or Unicode string These contain the SMTP e-mail headers.
    String TransportMessageHeaders = email.getTransportMessageHeaders();
    if (TransportMessageHeaders != null) {
        sub = XmlDom.factory.createElement(EMAIL_FIELDS.receptionTrace.name);
        sub.add(XmlDom.factory.createElement(EMAIL_FIELDS.trace.name)
                .addText(StringUtils.unescapeHTML(TransportMessageHeaders, true, false)));
        metadata.add(sub);
        if (TransportMessageHeaders.contains("X-RDF:")) {
            System.err.println("Found a X-RDF");
            int pos = TransportMessageHeaders.indexOf("X-RDF:") + "X-RDF:".length();
            while (pos < TransportMessageHeaders.length()) {
                char test = TransportMessageHeaders.charAt(pos);
                if (test != ' ' && test != '\r' && test != '\n') {
                    pos++;
                } else {
                    break;
                }
            }
            int pos2 = TransportMessageHeaders.indexOf(":", pos);
            while (pos2 > pos) {
                char test = TransportMessageHeaders.charAt(pos2);
                if (test != ' ' && test != '\r' && test != '\n') {
                    pos2--;
                } else {
                    break;
                }
            }
            String xrdf = TransportMessageHeaders.substring(pos, pos2);
            String rdf = null;
            try {
                byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(xrdf);
                //byte [] decoded = Base64.decode(xrdf);
                rdf = new String(decoded);
                System.err.println(rdf);
                try {
                    Document tempDocument = DocumentHelper.parseText(rdf);
                    Element erdf = sub.addElement("x-rdf");
                    erdf.add(tempDocument.getRootElement());
                } catch (Exception e) {
                    System.err.println("Cannot decode X-RDF: " + e.getMessage());
                    e.printStackTrace();
                    Element erdf = sub.addElement("x-rdf");
                    erdf.addText(rdf);
                }
            } catch (Exception e) {
                System.err.println("Cannot decode X-RDF: " + e.getMessage());
                System.err.println(xrdf);
                e.printStackTrace();
            }
        }
        TransportMessageHeaders = null;
    }
    long internalSize = email.getMessageSize();
    if (internalSize > 0) {
        sub = XmlDom.factory.createElement(EMAIL_FIELDS.emailSize.name);
        sub.setText(Long.toString(internalSize));
        metadata.add(sub);
    }
    // Message ID for this email as allocated per rfc2822
    String InternetMessageId = email.getInternetMessageId();
    if (InternetMessageId != null) {
        InternetMessageId = StringUtils.removeChevron(StringUtils.unescapeHTML(InternetMessageId, true, false))
                .trim();
        if (InternetMessageId.length() > 1) {
            sub = XmlDom.factory.createElement(EMAIL_FIELDS.messageId.name);
            sub.setText(InternetMessageId);
            metadata.add(sub);
        }
    }
    // In-Reply-To
    String InReplyToId = email.getInReplyToId();
    if (InReplyToId != null) {
        InReplyToId = StringUtils.removeChevron(StringUtils.unescapeHTML(InReplyToId, true, false)).trim();
        if (InReplyToId.length() > 1) {
            sub = XmlDom.factory.createElement(EMAIL_FIELDS.inReplyTo.name);
            sub.setText(InReplyToId);
            if (InternetMessageId != null && InternetMessageId.length() > 1) {
                String old = EmlExtract.filEmls.get(InReplyToId);
                if (old == null) {
                    old = InternetMessageId;
                } else {
                    old += "," + InternetMessageId;
                }
                EmlExtract.filEmls.put(InReplyToId, old);
            }
            metadata.add(sub);
        }
        InReplyToId = null;
        InternetMessageId = null;
    }
    sub = XmlDom.factory.createElement(EMAIL_FIELDS.properties.name);
    // is the action flag for this item "forward"?
    boolean Forwarded = email.hasForwarded();
    sub.addAttribute(EMAIL_FIELDS.propForwarded.name, Boolean.toString(Forwarded));
    // is the action flag for this item "replied"?
    boolean Replied = email.hasReplied();
    sub.addAttribute(EMAIL_FIELDS.propReplied.name, Boolean.toString(Replied));
    //
    boolean Read = email.isRead();
    sub.addAttribute(EMAIL_FIELDS.propRead.name, Boolean.toString(Read));
    //
    boolean Unsent = email.isUnsent();
    sub.addAttribute(EMAIL_FIELDS.propUnsent.name, Boolean.toString(Unsent));
    // Recipient Reassignment Prohibited Boolean 0 = false 0 != true
    boolean RecipientReassignmentProhibited = email.getRecipientReassignmentProhibited();
    sub.addAttribute(EMAIL_FIELDS.propRecipientReassignmentProhibited.name,
            Boolean.toString(RecipientReassignmentProhibited));
    // get the importance of the email
    // PSTMessage.IMPORTANCE_LOW + PSTMessage.IMPORTANCE_NORMAL + PSTMessage.IMPORTANCE_HIGH
    int Importance = email.getImportance();
    String imp = "??";
    switch (Importance) {
    case PSTMessage.IMPORTANCE_LOW:
        imp = "LOW";
        break;
    case PSTMessage.IMPORTANCE_NORMAL:
        imp = "NORMAL";
        break;
    case PSTMessage.IMPORTANCE_HIGH:
        imp = "HIGH";
        break;
    }
    sub.addAttribute(EMAIL_FIELDS.importance.name, imp);
    // Priority Integer 32-bit signed -1 = NonUrgent 0 = Normal 1 = Urgent
    int Priority = email.getPriority();
    switch (Priority) {
    case -1:
        imp = "LOW";
        break;
    case 0:
        imp = "NORMAL";
        break;
    case 1:
        imp = "HIGH";
        break;
    default:
        imp = "LEV" + Priority;
    }
    sub.addAttribute(EMAIL_FIELDS.priority.name, imp);
    // Sensitivity Integer 32-bit signed sender's opinion of the sensitivity of an email 0 =
    // None 1 = Personal 2 = Private 3 = Company Confidential
    int Sensitivity = email.getSensitivity();
    String sens = "??";
    switch (Sensitivity) {
    case 0:
        sens = "None";
        break;
    case 1:
        sens = "Personal";
        break;
    case 2:
        sens = "Private";
        break;
    case 3:
        sens = "Confidential";
        break;
    }
    sub.addAttribute(EMAIL_FIELDS.sensitivity.name, sens);

    //
    boolean Attachments = email.hasAttachments();
    sub.addAttribute(EMAIL_FIELDS.hasAttachment.name, Boolean.toString(Attachments));
    metadata.add(sub);

    String result = "";
    Element identification = null;
    if (Attachments) {
        File oldPath = curPath;
        if (config.extractFile) {
            File newDir = new File(curPath, id);
            newDir.mkdirs();
            curPath = newDir;
            argument.currentOutputDir = curPath;
        }
        identification = XmlDom.factory.createElement(EMAIL_FIELDS.attachments.name);
        // get the number of attachments for this message
        int NumberOfAttachments = email.getNumberOfAttachments();
        identification.addAttribute(EMAIL_FIELDS.attNumber.name, Integer.toString(NumberOfAttachments));
        // get a specific attachment from this email.
        for (int attachmentNumber = 0; attachmentNumber < NumberOfAttachments; attachmentNumber++) {
            try {
                PSTAttachment attachment = email.getAttachment(attachmentNumber);
                if (argument.extractKeyword) {
                    result += " " + extractInfoAttachment(attachment, identification);
                } else {
                    extractInfoAttachment(attachment, identification);
                }
            } catch (PSTException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        curPath = oldPath;
        argument.currentOutputDir = curPath;
    }
    // Plain text e-mail body
    String body = "";
    if (argument.extractKeyword || config.extractFile) {
        body = email.getBody();
        boolean isTxt = true;
        boolean isHttp = false;
        if (body == null || body.isEmpty()) {
            isTxt = false;
            body = email.getBodyHTML();
            isHttp = true;
            if (body == null || body.isEmpty()) {
                isHttp = false;
                try {
                    body = email.getRTFBody();
                } catch (PSTException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        if (body != null && !body.isEmpty()) {
            if (config.extractFile) {
                // XXX FIXME could saved email from HTML Body (clearer) if possible
                // use curRank in name, and attachment will be under directory named
                // add currank in field
                File newDir = new File(curPath, id);
                newDir.mkdirs();
                File oldPath = curPath;
                curPath = newDir;
                argument.currentOutputDir = curPath;
                String filenamebody = InternetMessageId;
                if (filenamebody == null || !filenamebody.isEmpty()) {
                    filenamebody = id;
                }
                String html = null;
                if (isHttp) {
                    html = body;
                }
                String rtf = null;
                if (!isTxt && !isHttp) {
                    rtf = body;
                }
                if (isTxt) {
                    FileOutputStream output = null;
                    try {
                        output = new FileOutputStream(new File(newDir, filenamebody + ".txt"));
                        byte[] bb = body.getBytes();
                        output.write(bb, 0, bb.length);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        if (output != null) {
                            try {
                                output.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                    html = email.getBodyHTML();
                }
                if (html != null && !html.isEmpty()) {
                    FileOutputStream output = null;
                    try {
                        output = new FileOutputStream(new File(newDir, filenamebody + ".html"));
                        byte[] bb = html.getBytes();
                        output.write(bb, 0, bb.length);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        if (output != null) {
                            try {
                                output.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                    html = null;
                }
                if (isTxt || isHttp) {
                    try {
                        rtf = email.getRTFBody();
                    } catch (PSTException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (rtf != null && !rtf.isEmpty()) {
                    FileOutputStream output = null;
                    try {
                        output = new FileOutputStream(new File(newDir, filenamebody + ".rtf"));
                        byte[] bb = rtf.getBytes();
                        output.write(bb, 0, bb.length);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        if (output != null) {
                            try {
                                output.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                    rtf = null;
                }
                curPath = oldPath;
                argument.currentOutputDir = curPath;
            }
        }
    }
    if (metadata.hasContent()) {
        root.add(metadata);
    }
    if (identification != null && identification.hasContent()) {
        root.add(identification);
    }
    if (argument.extractKeyword) {
        result = body + " " + result;
        body = null;
        ExtractInfo.exportMetadata(keywords, result, "", config, null);
        if (keywords.hasContent()) {
            root.add(keywords);
        }
    }
    root.addAttribute(EMAIL_FIELDS.status.name, "ok");
    currentRoot.add(root);
    return result;
}

From source file:fr.gouv.culture.vitam.extract.ExtractInfo.java

License:Open Source License

/**
 * Recursive checking/*  w ww  .j av  a2s  . c o m*/
 * @param file root directory or file
 * @param basename basename that will be kept in the path
 * @param root element where the results will be added
 * @param config
 * @param writer could be null
 */
public static void recursive(File file, String basename, Element root, ConfigLoader config, XMLWriter writer) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (File file2 : files) {
                recursive(file2, basename, root, config, writer);
            }
        }
    } else {
        String name = file.getAbsolutePath();
        int index = name.indexOf(basename);
        if (index >= 0) {
            name = name.substring(index);
        }
        Element result = exportMetadata(file, name, config, writer, null);
        root.add(result);
    }
}

From source file:fr.gouv.culture.vitam.extract.ExtractInfo.java

License:Open Source License

/**
 * Export Metadata for one String/*from   www . j  a  v  a2  s.c  o  m*/
 * @param root
 * @param words
 * @param config
 * @param writer could be null
 * @return the base element as result
 */
public static Element exportMetadata(Element root, String words, String filename, ConfigLoader config,
        XMLWriter writer) {
    try {
        HashMap<String, Integer> references = getWordRank(words);
        Integer MaxRank = references.remove(MAXRANK);
        int maxRank = 0;
        if (MaxRank != null) {
            maxRank = MaxRank;
        }
        // Title of file will be considered as Main Keywords
        String[] wordLists = convertToSearchWords(filename).split(" ");
        for (String word : wordLists) {
            if (word.trim().length() > 0) {
                references.put(word, maxRank + 1);
            }
        }
        System.out.print(" Words found: " + references.size());
        HashMap<Integer, HashSet<String>> rankedValues = new HashMap<Integer, HashSet<String>>();
        TreeSet<Integer> sortRanks = new TreeSet<Integer>();
        for (String word : references.keySet()) {
            Integer rank = references.get(word);
            HashSet<String> wordset = rankedValues.get(rank);
            if (wordset == null) {
                wordset = new HashSet<String>();
            }
            wordset.add(word);
            rankedValues.put(rank, wordset);
            sortRanks.add(rank);
        }
        System.out.print(" Ranks found: " + rankedValues.size());
        Iterator<Integer> iterator = sortRanks.descendingIterator();
        int foundRank = 0;
        int limitword = 0;
        while (iterator.hasNext()) {
            Integer integer = iterator.next();
            // minimum 5 levels + rankLimit
            if (foundRank > 5 && config.rankLimit > integer) {
                break;
            }
            foundRank++;
            Element rankedElement = DocumentFactory.getInstance().createElement(EMAIL_FIELDS.keywordRank.name);
            rankedElement.addAttribute(EMAIL_FIELDS.keywordOccur.name, integer.toString());
            for (String word : rankedValues.get(integer)) {
                Element wordElement = DocumentFactory.getInstance()
                        .createElement(EMAIL_FIELDS.keywordWord.name);
                wordElement.addAttribute(EMAIL_FIELDS.keywordValue.name, word);
                rankedElement.add(wordElement);
                limitword++;
            }
            XmlDom.addElement(writer, config.argument, root, rankedElement);
            if (config.wordLimit > 0 && limitword > config.wordLimit) {
                break;
            }
        }
        System.out.println(" Word kept: " + limitword + " Ranks kept: " + foundRank);
        rankedValues.clear();
        sortRanks.clear();
        rankedValues = null;
        sortRanks = null;
    } catch (Exception e) {
        XmlDom.addDate(config.argument, config, root);
        System.err.println(StaticValues.LBL.error_error.get() + " Extract: " + e.toString());
        return root;
    }
    XmlDom.addDate(config.argument, config, root);
    return root;
}

From source file:fr.gouv.culture.vitam.gui.VitamGui.java

License:Open Source License

/**
 * Check one directory against the full format
 * /*from  www  .j  a  v  a 2s  . com*/
 * @param task
 */
private void oneDirOrFileShow(RunnerLongTask task) {
    List<File> files = filesToScan;
    filesToScan = null;
    try {
        config.initDroid();
        vitamResult = null;
    } catch (CommandExecutionException e) {
        System.err.println(StaticValues.LBL.error_initdroid.get() + e.toString());
        e.printStackTrace();
        vitamResult = null;
        return;
    }
    try {
        config.initFits();
    } catch (CommandExecutionException e) {
        System.err.println(StaticValues.LBL.error_initdroid.get() + e.toString());
        e.printStackTrace();
        vitamResult = null;
        return;
    }
    System.out.println("Show File Type");
    Element root = null;
    vitamResult = new VitamResult();
    if (config.argument.outputModel == VitamOutputModel.OneXML) {
        root = XmlDom.factory.createElement("checkfiles");
        root.addAttribute("source", config.lastScannedDirectory.getAbsolutePath());
        vitamResult.unique = XmlDom.factory.createDocument(root);
    } else {
        // force multiple
        vitamResult.multiples = new ArrayList<Document>();
    }
    int currank = 0;
    int warning = 0;
    EmlExtract.filEmls.clear();
    //System.out.println("oneDirOrFileShow: "+files.size());
    int nb = files.size();
    for (int i = 0; i < nb; i++) {
        //for (File file : files) {
        File file = files.get(i);
        currank++;
        //System.out.println("rank: "+currank+"/"+nb+":"+file.getName());
        String shortname;
        if (config.lastScannedDirectory.isDirectory()) {
            shortname = StaticValues.getSubPath(file, config.lastScannedDirectory);
        } else {
            shortname = config.lastScannedDirectory.getName();
        }
        Element result = Commands.showFormat(shortname, null, null, file, config, config.argument);
        if (result.selectSingleNode(".[@status='warning']") != null) {
            warning++;
        }
        XmlDom.addDate(config.argument, config, result);
        if (root != null) {
            root.add(result);
        } else {
            // multiple
            root = XmlDom.factory.createElement("checkfiles");
            root.addAttribute("source", config.lastScannedDirectory.getAbsolutePath());
            Document document = XmlDom.factory.createDocument(root);
            root.add(result);
            vitamResult.multiples.add(document);
            root = null;
        }
        if (task != null) {
            float value = ((float) currank) / (float) nb;
            value *= 100;
            task.setProgressExternal((int) value);
        }
    }
    if (root != null) {
        XmlDom.addDate(config.argument, config, root);
        if (!EmlExtract.filEmls.isEmpty()) {
            Element sortEml = XmlDom.factory.createElement("emlsort");
            for (String parent : EmlExtract.filEmls.keySet()) {
                Element eparent = XmlDom.factory.createElement("parent");
                String fil = EmlExtract.filEmls.get(parent);
                eparent.addAttribute("messageId", parent);
                String[] fils = fil.split(",");
                for (String mesg : fils) {
                    if (mesg != null && mesg.length() > 1) {
                        Element elt = XmlDom.factory.createElement("descendant");
                        elt.addAttribute("messageId", mesg);
                        eparent.add(elt);
                    }
                }
                sortEml.add(eparent);
            }
            root.add(sortEml);
        }
    }
    texteOut.insertIcon(new ImageIcon(getClass().getResource(RESOURCES_IMG_VALID_PNG)));
    System.out.println(StaticValues.LBL.action_outformat.get() + " [ " + currank
            + (warning > 0 ? " (" + StaticValues.LBL.error_warning.get() + warning + " ) " : "") + " ]");
}

From source file:fr.gouv.culture.vitam.gui.VitamGui.java

License:Open Source License

/**
 * Check a directory only against type/* w  w  w.j a va  2  s  . c o m*/
 * 
 * @param task
 */
private void oneDirOrFileCheck(RunnerLongTask task) {
    List<File> files = filesToScan;
    filesToScan = null;
    try {
        config.initDroid();
        vitamResult = null;
    } catch (CommandExecutionException e) {
        System.err.println(StaticValues.LBL.error_initdroid.get() + e.toString());
        vitamResult = null;
        return;
    }
    System.out.println("Check File Type");
    Element root = null;
    vitamResult = new VitamResult();
    if (config.argument.outputModel == VitamOutputModel.OneXML) {
        root = XmlDom.factory.createElement("checkfiles");
        root.addAttribute("source", config.lastScannedDirectory.getAbsolutePath());
        vitamResult.unique = XmlDom.factory.createDocument(root);
        Element newElt = XmlDom.factory.createElement("toolsversion");
        if (StaticValues.config.droidHandler != null) {
            newElt.addAttribute("pronom", StaticValues.config.droidHandler.getVersionSignature());
        }
        if (StaticValues.config.droidHandler != null) {
            newElt.addAttribute("droid", "6.1");
        }
        root.add(newElt);
    } else {
        // force multiple
        vitamResult.multiples = new ArrayList<Document>();
    }
    List<DroidFileFormat> list = null;
    int warning = 0;
    try {
        list = config.droidHandler.checkFilesFormat(files, config.argument, task);
        String pathBeforeArg = config.lastScannedDirectory.getCanonicalPath();
        pathBeforeArg = pathBeforeArg.substring(0,
                pathBeforeArg.indexOf(config.lastScannedDirectory.getName()));
        for (DroidFileFormat droidFileFormat : list) {
            boolean warn = false;
            Element fileformat = droidFileFormat.toElement(true);
            if (config.preventXfmt && droidFileFormat.getPUID().startsWith(StaticValues.FORMAT_XFMT)) {
                warning++;
                warn = true;
            }
            Attribute filename = fileformat.attribute("filename");
            if (filename != null) {
                String value = filename.getText();
                filename.setText(value.replace(pathBeforeArg, ""));
            }
            XmlDom.addDate(config.argument, config, fileformat);
            if (root != null) {
                root.add(fileformat);
            } else {
                // multiple
                root = XmlDom.factory.createElement("checkfiles");
                root.addAttribute("source", config.lastScannedDirectory.getAbsolutePath());
                Document document = XmlDom.factory.createDocument(root);
                root.add(fileformat);
                if (warn) {
                    root.addAttribute("status", "warning");
                } else {
                    root.addAttribute("status", "ok");
                }
                vitamResult.multiples.add(document);
                root = null;
            }
        }
    } catch (CommandExecutionException e) {
        System.err.println(StaticValues.LBL.error_analysis.get() + e);
        e.printStackTrace();
        vitamResult = null;
    } catch (IOException e) {
        System.err.println(StaticValues.LBL.error_analysis.get() + e);
        vitamResult = null;
    }
    if (root != null) {
        XmlDom.addDate(config.argument, config, root);
        if (warning > 0) {
            root.addAttribute("status", "warning");
        } else {
            root.addAttribute("status", "ok");
        }
    }
    if (list != null) {
        texteOut.insertIcon(new ImageIcon(getClass().getResource(RESOURCES_IMG_VALID_PNG)));
        System.out.println(StaticValues.LBL.action_format.get() + " [ " + list.size() + " / " + files.size()
                + (warning > 0 ? " (" + StaticValues.LBL.error_warning.get() + warning + " )" : "") + " ]");
    }
}