Example usage for java.util Vector copyInto

List of usage examples for java.util Vector copyInto

Introduction

In this page you can find the example usage for java.util Vector copyInto.

Prototype

public synchronized void copyInto(Object[] anArray) 

Source Link

Document

Copies the components of this vector into the specified array.

Usage

From source file:com.sonicle.webtop.mail.Service.java

private Address[] removeDestination(Address a[], String email) throws MessagingException {
    email = email.toLowerCase();/*from  www. ja  va 2s .  c om*/
    Vector v = new Vector();
    for (int i = 0; i < a.length; ++i) {
        InternetAddress ia = (InternetAddress) a[i];
        if (!ia.getAddress().toLowerCase().equals(email)) {
            v.addElement(a[i]);
        }
    }
    Address na[] = new Address[v.size()];
    v.copyInto(na);
    return na;
}

From source file:org.openbravo.erpCommon.utility.reporting.printing.PrintController.java

void createEmailOptionsPage(HttpServletRequest request, HttpServletResponse response, VariablesSecureApp vars,
        DocumentType documentType, String strDocumentId, Map<String, Report> reports,
        HashMap<String, Boolean> checks, String fullDocumentIdentifier)
        throws IOException, ServletException, ReportingException {
    boolean hasMultipleEmailConfigurations = false;
    XmlDocument xmlDocument = null;//from   ww w.  ja  v  a 2 s  . c  o  m
    PocData[] pocData = getContactDetails(documentType, strDocumentId);
    @SuppressWarnings("unchecked")
    Vector<java.lang.Object> vector = (Vector<java.lang.Object>) request.getSession().getAttribute("files");

    final String[] hiddenTags = getHiddenTags(pocData, vector, vars, checks);
    if (hiddenTags != null) {
        xmlDocument = xmlEngine
                .readXmlTemplate("org/openbravo/erpCommon/utility/reporting/printing/EmailOptions", hiddenTags)
                .createXmlDocument();
    } else {
        xmlDocument = xmlEngine
                .readXmlTemplate("org/openbravo/erpCommon/utility/reporting/printing/EmailOptions")
                .createXmlDocument();
    }

    xmlDocument.setParameter("strDocumentId", strDocumentId);

    boolean isTheFirstEntry = false;
    if (vector == null) {
        vector = new Vector<java.lang.Object>(0);
        isTheFirstEntry = new Boolean(true);
    }

    if (vars.getMultiFile("inpFile") != null && !vars.getMultiFile("inpFile").getName().equals("")) {
        final AttachContent content = new AttachContent();
        final FileItem file1 = vars.getMultiFile("inpFile");
        content.setFileName(pocData[0].ourreference.replace('/', '_') + '-'
                + Utility.formatDate(new Date(), "yyyyMMdd-HHmmss") + '.' + file1.getName());
        content.setFileItem(file1);
        content.setId(Utility.formatDate(new Date(), "yyyyMMdd-HHmmss") + '.' + file1.getName());
        content.visible = "hidden";
        if (vars.getStringParameter("inpArchive") == "Y") {
            content.setSelected("true");
        }
        vector.addElement(content);
        request.getSession().setAttribute("files", vector);

    }

    if ("yes".equals(vars.getStringParameter("closed"))) {
        xmlDocument.setParameter("closed", "yes");
        request.getSession().removeAttribute("files");
    }

    xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\r\n");
    xmlDocument.setParameter("language", vars.getLanguage());
    xmlDocument.setParameter("theme", vars.getTheme());

    EmailDefinition emailDefinition = null;
    try {
        if (moreThanOneLanguageDefined(reports) && hasDifferentBpLanguages(reports)) {
            // set multiple email configurations
            List<EmailDefinition> emailDef = new ArrayList<EmailDefinition>();
            Map<String, EmailDefinition> emailDefinitions = reports.values().iterator().next()
                    .getEmailDefinitions();
            Iterator<Entry<String, EmailDefinition>> entries = emailDefinitions.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry<String, EmailDefinition> entry = entries.next();
                emailDef.add(entry.getValue());
            }
            emailDefinition = reports.values().iterator().next().getTemplateInfo().get_DefaultEmailDefinition();
            String emailDefinitionsComboHtml = getOptionsList(emailDef, emailDefinition.getId(), false);
            xmlDocument.setParameter("reportEmailConfig", emailDefinitionsComboHtml);
            hasMultipleEmailConfigurations = true;
        } else {
            emailDefinition = reports.values().iterator().next().getEmailDefinition();
            hasMultipleEmailConfigurations = false;
        }
    } catch (final OBException exception) {
        final OBError on = new OBError();
        on.setMessage(Utility.messageBD(this, "EmailConfiguration", vars.getLanguage()));
        on.setTitle(Utility.messageBD(this, "Info", vars.getLanguage()));
        on.setType("info");
        final String tabId = vars.getSessionValue("inpTabId");
        vars.getStringParameter("tab");
        vars.setMessage(tabId, on);
        vars.getRequestGlobalVariable("inpTabId", "AttributeSetInstance.tabId");
        printPageClosePopUpAndRefreshParent(response, vars);
    } catch (ReportingException e) {
        log4j.error(e);
    }

    String fromEmail = null;
    String fromEmailId = null;

    OBContext.setAdminMode(true);
    try {
        OBCriteria<EmailServerConfiguration> mailConfigCriteria = OBDal.getInstance()
                .createCriteria(EmailServerConfiguration.class);
        mailConfigCriteria.addOrderBy("client.id", false);
        final List<EmailServerConfiguration> mailConfigList = mailConfigCriteria.list();

        if (mailConfigList.size() == 0) {
            throw new ServletException("No Poc configuration found for this client.");
        }

        EmailServerConfiguration mailConfig = EmailUtils
                .getEmailConfiguration(OBDal.getInstance().get(Organization.class, vars.getOrg()));

        if (mailConfig == null) {
            throw new ServletException(
                    "No sender defined: Please go to client configuration to complete the email configuration.");
        }

        fromEmail = mailConfig.getSmtpServerSenderAddress();
        fromEmailId = mailConfig.getId();
    } finally {
        OBContext.restorePreviousMode();
    }

    // Get additional document information
    String draftDocumentIds = "";
    final AttachContent attachedContent = new AttachContent();
    final boolean onlyOneAttachedDoc = onlyOneAttachedDocs(reports);
    final Map<String, PocData> customerMap = new HashMap<String, PocData>();
    final Map<String, PocData> salesRepMap = new HashMap<String, PocData>();
    final Vector<Object> cloneVector = new Vector<Object>();
    boolean allTheDocsCompleted = true;
    for (final PocData documentData : pocData) {
        // Map used to count the different users

        final String customer = documentData.contactEmail;
        getEnvironentInformation(pocData, checks);
        if (checks.get("moreThanOneDoc")) {
            if (customer == null || customer.length() == 0) {
                final OBError on = new OBError();
                on.setMessage(Utility.messageBD(this, "NoContact", vars.getLanguage()).replace("@docNum@",
                        documentData.ourreference));

                on.setTitle(Utility.messageBD(this, "Info", vars.getLanguage()));
                on.setType("info");
                final String tabId = vars.getSessionValue("inpTabId");
                vars.getStringParameter("tab");
                vars.setMessage(tabId, on);
                vars.getRequestGlobalVariable("inpTabId", "AttributeSetInstance.tabId");
                printPageClosePopUpAndRefreshParent(response, vars);
            } else if (documentData.contactEmail == null || documentData.contactEmail.equals("")) {
                final OBError on = new OBError();
                on.setMessage(Utility.messageBD(this, "NoEmail", vars.getLanguage()).replace("@customer@",
                        documentData.contactName));
                on.setTitle(Utility.messageBD(this, "Info", vars.getLanguage()));
                on.setType("info");
                final String tabId = vars.getSessionValue("inpTabId");
                vars.getStringParameter("tab");
                vars.setMessage(tabId, on);
                vars.getRequestGlobalVariable("inpTabId", "AttributeSetInstance.tabId");
                printPageClosePopUpAndRefreshParent(response, vars);
            }
        }

        if (!customerMap.containsKey(customer)) {
            customerMap.put(customer, documentData);
        }

        final String salesRep = documentData.salesrepEmail;

        boolean moreThanOnesalesRep = checks.get("moreThanOnesalesRep").booleanValue();
        if (moreThanOnesalesRep) {
            if (salesRep == null || salesRep.length() == 0) {
                final OBError on = new OBError();
                on.setMessage(Utility.messageBD(this, "NoSenderDocument", vars.getLanguage()));
                on.setTitle(Utility.messageBD(this, "Info", vars.getLanguage()));
                on.setType("info");
                final String tabId = vars.getSessionValue("inpTabId");
                vars.getStringParameter("tab");
                vars.setMessage(tabId, on);
                vars.getRequestGlobalVariable("inpTabId", "AttributeSetInstance.tabId");
                printPageClosePopUpAndRefreshParent(response, vars);
            } else if (documentData.salesrepEmail == null || documentData.salesrepEmail.equals("")) {
                final OBError on = new OBError();
                on.setMessage(Utility.messageBD(this, "NoEmailSender", vars.getLanguage()).replace("@salesRep@",
                        documentData.salesrepName));
                on.setTitle(Utility.messageBD(this, "Info", vars.getLanguage()));
                on.setType("info");
                final String tabId = vars.getSessionValue("inpTabId");
                vars.getStringParameter("tab");
                vars.setMessage(tabId, on);
                vars.getRequestGlobalVariable("inpTabId", "AttributeSetInstance.tabId");
                printPageClosePopUpAndRefreshParent(response, vars);
            }
        }

        if (!salesRepMap.containsKey(salesRep)) {
            salesRepMap.put(salesRep, documentData);
        }

        final Report report = reports.get(documentData.documentId);
        // All ids of documents in draft are passed to the web client
        if (report.isDraft()) {
            if (draftDocumentIds.length() > 0)
                draftDocumentIds += ",";
            draftDocumentIds += report.getDocumentId();
            allTheDocsCompleted = false;
        }

        // Fill the report location
        final String reportFilename = report.getContextSubFolder() + report.getFilename();
        documentData.reportLocation = request.getContextPath() + "/" + reportFilename + "?documentId="
                + documentData.documentId;
        if (log4j.isDebugEnabled())
            log4j.debug(" Filling report location with: " + documentData.reportLocation);

        if (onlyOneAttachedDoc) {
            attachedContent.setDocName(report.getFilename());
            attachedContent.setVisible("checkbox");
            cloneVector.add(attachedContent);
        }

    }
    if (!allTheDocsCompleted) {
        final OBError on = new OBError();
        on.setMessage(Utility.messageBD(this, "ErrorIncompleteDocuments", vars.getLanguage()));
        on.setTitle(Utility.messageBD(this, "ErrorSendingEmail", vars.getLanguage()));
        on.setType("Error");
        final String tabId = vars.getSessionValue("inpTabId");
        vars.getStringParameter("tab");
        vars.setMessage(tabId, on);
        vars.getRequestGlobalVariable("inpTabId", "AttributeSetInstance.tabId");
        printPageClosePopUpAndRefreshParent(response, vars);
    }

    final int numberOfCustomers = customerMap.size();
    final int numberOfSalesReps = salesRepMap.size();

    if (!onlyOneAttachedDoc && isTheFirstEntry) {
        if (numberOfCustomers > 1) {
            attachedContent.setDocName(String.valueOf(
                    reports.size() + " Documents to " + String.valueOf(numberOfCustomers) + " Customers"));
            attachedContent.setVisible("checkbox");

        } else {
            attachedContent.setDocName(String.valueOf(reports.size() + " Documents"));
            attachedContent.setVisible("checkbox");

        }
        cloneVector.add(attachedContent);
    }

    final AttachContent[] data = new AttachContent[vector.size()];
    final AttachContent[] data2 = new AttachContent[cloneVector.size()];
    if (cloneVector.size() >= 1) { // Has more than 1 element
        vector.copyInto(data);
        cloneVector.copyInto(data2);
        xmlDocument.setData("structure2", data2);
        xmlDocument.setData("structure1", data);
    }
    if (pocData.length >= 1) {
        xmlDocument.setData("reportEmail", "liststructure", reports.get((pocData[0].documentId)).getTemplate());
    }

    if (log4j.isDebugEnabled())
        log4j.debug("Documents still in draft: " + draftDocumentIds);
    xmlDocument.setParameter("draftDocumentIds", draftDocumentIds);

    final PocData[] currentUserInfo = PocData.getContactDetailsForUser(this, vars.getUser());
    final String userName = currentUserInfo[0].userName;
    final String userEmail = currentUserInfo[0].userEmail;
    String bccEmail = "";
    String bccName = "";
    if (userEmail != null && userEmail.length() > 0) {
        bccEmail = userEmail;
        bccName = userName;
    }

    if (vars.commandIn("ADD") || vars.commandIn("DEL")) {
        xmlDocument.setParameter("fromEmailId", vars.getStringParameter("fromEmailId"));
        xmlDocument.setParameter("fromEmail", vars.getStringParameter("fromEmail"));
        xmlDocument.setParameter("toEmail", vars.getStringParameter("toEmail"));
        xmlDocument.setParameter("toEmailOrig", vars.getStringParameter("toEmailOrig"));
        xmlDocument.setParameter("ccEmail", vars.getStringParameter("ccEmail"));
        xmlDocument.setParameter("ccEmailOrig", vars.getStringParameter("ccEmailOrig"));
        xmlDocument.setParameter("bccEmail", vars.getStringParameter("bccEmail"));
        xmlDocument.setParameter("bccEmailOrig", vars.getStringParameter("bccEmailOrig"));
        xmlDocument.setParameter("replyToEmail", vars.getStringParameter("replyToEmail"));
        xmlDocument.setParameter("replyToEmailOrig", vars.getStringParameter("replyToEmailOrig"));
        xmlDocument.setParameter("emailSubject", vars.getStringParameter("emailSubject"));
        xmlDocument.setParameter("emailBody", vars.getStringParameter("emailBody"));
    } else {
        xmlDocument.setParameter("fromEmailId", fromEmailId);
        xmlDocument.setParameter("fromEmail", fromEmail);
        xmlDocument.setParameter("toEmail", pocData[0].contactEmail);
        xmlDocument.setParameter("toEmailOrig", pocData[0].contactEmail);
        xmlDocument.setParameter("ccEmail", "");
        xmlDocument.setParameter("ccEmailOrig", "");
        xmlDocument.setParameter("bccEmail", bccEmail);
        xmlDocument.setParameter("bccEmailOrig", bccEmail);
        xmlDocument.setParameter("replyToEmail", pocData[0].salesrepEmail);
        xmlDocument.setParameter("replyToEmailOrig", pocData[0].salesrepEmail);
        xmlDocument.setParameter("emailSubject", emailDefinition.getSubject());
        xmlDocument.setParameter("emailBody", emailDefinition.getBody());
    }
    xmlDocument.setParameter("inpArchive", vars.getStringParameter("inpArchive"));
    xmlDocument.setParameter("fromName", "");
    xmlDocument.setParameter("toName", pocData[0].contactName);
    xmlDocument.setParameter("ccName", "");
    xmlDocument.setParameter("bccName", bccName);
    xmlDocument.setParameter("replyToName", pocData[0].salesrepName);
    xmlDocument.setParameter("inpArchive", vars.getStringParameter("inpArchive"));
    xmlDocument.setParameter("multCusCount", String.valueOf(numberOfCustomers));
    xmlDocument.setParameter("multSalesRepCount", String.valueOf(numberOfSalesReps));
    if (!hasMultipleEmailConfigurations) {
        xmlDocument.setParameter("useDefault", "Y");
    }
    if (differentDocTypes.size() > 1) {
        xmlDocument.setParameter("multiDocType", "Y");
    }

    vars.setSessionObject("pocData" + fullDocumentIdentifier, pocData);
    response.setContentType("text/html; charset=UTF-8");
    final PrintWriter out = response.getWriter();
    out.println(xmlDocument.print());
    out.close();
}