Example usage for org.apache.commons.lang StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:com.autentia.tnt.manager.commissioning.CommissioningManager.java

public CommissioningChange getChange(String field, String oldValue, String newValue,
        final Commissioning commissioning) {
    CommissioningChange change = null;/*from  w  w  w .jav  a2  s.c o  m*/
    if (!StringUtils.equals(oldValue, newValue)) {
        oldValue = StringUtils.defaultIfEmpty(oldValue, "");
        newValue = StringUtils.defaultIfEmpty(newValue, "");
        change = new CommissioningChange();
        change.setCommissioning(commissioning);
        change.setStatus(commissioning.getStatus());
        change.setField(field);
        change.setOldValue(oldValue);
        change.setNewValue(newValue);
        change.setInsertDate(new Date());
        change.setUser(AuthenticationManager.getDefault().getCurrentPrincipal().getUser());
    }
    return change;
}

From source file:com.gst.portfolio.client.data.ClientData.java

private ClientData(final String accountNo, final EnumOptionData status, final CodeValueData subStatus,
        final Long officeId, final String officeName, final Long transferToOfficeId,
        final String transferToOfficeName, final Long id, final String firstname, final String middlename,
        final String lastname, final String fullname, final String displayName, final String externalId,
        final String mobileNo, final LocalDate dateOfBirth, final CodeValueData gender,
        final LocalDate activationDate, final Long imageId, final Long staffId, final String staffName,
        final Collection<OfficeData> allowedOffices, final Collection<GroupGeneralData> groups,
        final Collection<StaffData> staffOptions, final Collection<CodeValueData> narrations,
        final Collection<CodeValueData> genderOptions, final ClientTimelineData timeline,
        final Collection<SavingsProductData> savingProductOptions, final Long savingsProductId,
        final String savingsProductName, final Long savingsAccountId,
        final Collection<SavingsAccountData> savingAccountOptions, final CodeValueData clientType,
        final CodeValueData clientClassification, final Collection<CodeValueData> clientTypeOptions,
        final Collection<CodeValueData> clientClassificationOptions,
        final Collection<CodeValueData> clientNonPersonConstitutionOptions,
        final Collection<CodeValueData> clientNonPersonMainBusinessLineOptions,
        final ClientNonPersonData clientNonPerson, final List<EnumOptionData> clientLegalFormOptions,
        final EnumOptionData legalForm, final AddressData address, final Boolean isAddressEnabled,
        final List<DatatableData> datatables) {
    this.accountNo = accountNo;
    this.status = status;
    if (status != null) {
        this.active = status.getId().equals(300L);
    } else {/*from  ww w  .  j a v a2  s  .  c o  m*/
        this.active = null;
    }
    this.subStatus = subStatus;
    this.officeId = officeId;
    this.officeName = officeName;
    this.transferToOfficeId = transferToOfficeId;
    this.transferToOfficeName = transferToOfficeName;
    this.id = id;
    this.firstname = StringUtils.defaultIfEmpty(firstname, null);
    this.middlename = StringUtils.defaultIfEmpty(middlename, null);
    this.lastname = StringUtils.defaultIfEmpty(lastname, null);
    this.fullname = StringUtils.defaultIfEmpty(fullname, null);
    this.displayName = StringUtils.defaultIfEmpty(displayName, null);
    this.externalId = StringUtils.defaultIfEmpty(externalId, null);
    this.mobileNo = StringUtils.defaultIfEmpty(mobileNo, null);
    this.activationDate = activationDate;
    this.dateOfBirth = dateOfBirth;
    this.gender = gender;
    this.clientClassification = clientClassification;
    this.clientType = clientType;
    this.imageId = imageId;
    if (imageId != null) {
        this.imagePresent = Boolean.TRUE;
    } else {
        this.imagePresent = null;
    }
    this.staffId = staffId;
    this.staffName = staffName;

    // associations
    this.groups = groups;

    // template
    this.officeOptions = allowedOffices;
    this.staffOptions = staffOptions;
    this.narrations = narrations;

    this.genderOptions = genderOptions;
    this.clientClassificationOptions = clientClassificationOptions;
    this.clientTypeOptions = clientTypeOptions;

    this.clientNonPersonConstitutionOptions = clientNonPersonConstitutionOptions;
    this.clientNonPersonMainBusinessLineOptions = clientNonPersonMainBusinessLineOptions;
    this.clientLegalFormOptions = clientLegalFormOptions;

    this.timeline = timeline;
    this.savingProductOptions = savingProductOptions;
    this.savingsProductId = savingsProductId;
    this.savingsProductName = savingsProductName;
    this.savingsAccountId = savingsAccountId;
    this.savingAccountOptions = savingAccountOptions;
    this.legalForm = legalForm;
    this.clientNonPersonDetails = clientNonPerson;

    this.address = address;
    this.isAddressEnabled = isAddressEnabled;
    this.datatables = datatables;

}

From source file:com.healthcit.cacure.model.admin.GeneratedModuleDataDetail.java

/**
 * Static method which generates the map key for any of the questionCombination maps
 * using the given map key parts//from w ww  .j  a  v a 2s.  c o  m
 */
public static String getTwoPartMapKey(String firstPart, String secondPart) {
    return StringUtils.defaultIfEmpty(firstPart, "") + MAP_KEY_SEPARATOR
            + StringUtils.defaultIfEmpty(secondPart, "");
}

From source file:com.openteach.qsync.service.declare.AssembleService.java

/**
 * ???/*from   w  w w.  j a  v  a 2 s. c  om*/
 * @param order
 * @return
 */
public XmlWaybillRequest getWaybillXmlRequest(Order order) {
    XmlWaybillRequest request = new XmlWaybillRequest();
    XmlWaybillRequestBody body = new XmlWaybillRequestBody();

    WayBill wayBill = new WayBill();

    WayBillImportDto dto = new WayBillImportDto();
    wayBill.setWayBillImportDto(dto);
    dto.setWayBillNo(order.getOrderTransportObject().getWaybillnumber());
    dto.setTotalWayBill(order.getOrderTransportObject().getWaybillnumber());
    dto.setPackageNo(order.getTotalGoodsCount());
    dto.setWeight(order.getTotalGoodsWeight());
    dto.setNetWeight(order.getTotalGoodsWeight());
    List<TransportCommodity> transportCommoditiyList = order.getOrderTransportObject()
            .getTransportCommodityList();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < transportCommoditiyList.size() && i <= 3; i++) {
        TransportCommodity tc = transportCommoditiyList.get(i);
        Commsku commsku = tc.getCommskuObject();
        sb.append(commsku.getName()).append("");
    }
    if (sb.length() > 0)
        sb.deleteCharAt(sb.length() - 1);
    dto.setGoodsName(sb.toString());
    Country addressorCountry = countryManager.getById(order.getOrderTransportObject().getAddressorCountry());
    if (addressorCountry == null) {
        throw new DataAssembleException(
                "order.orderTransportObject.addressorCountry.salesCountry may not be null");
    }
    if (StringUtils.isBlank(addressorCountry.getCountryCode())) {
        throw new DataAssembleException(
                "order.orderTransportObject.addressorCountry.salesCountry.countryCode may not be null");
    }
    dto.setSendArea(addressorCountry.getName() + order.getOrderTransportObject().getAddressorCity()); //cc_kata_kplus_order_transport.addressor_country + addressor_city
    dto.setConsigneeArea(order.getOrderTransportObject().getAddressorCity());
    dto.setConsigneeAddress(StringUtils.defaultIfEmpty(order.getOrderTransportObject().getAddress1(),
            order.getOrderTransportObject().getAddress2()));
    dto.setConsignee(order.getOrderTransportObject().getCongsignee());
    dto.setConsigneeTel(order.getOrderTransportObject().getPhonenumber());
    dto.setZipCode(order.getOrderTransportObject().getZipCode()); //cc_kata_kplus_order_transport.zip_code
    dto.setCustomsCode(configService.getDeclareCustomsCode());
    dto.setWorth(order.getTotalamout());
    dto.setImportDateString(order.getOrdertime());
    dto.setCurrCode(configService.getDeclareCurrency());

    JkfSign jkfSign = new JkfSign();
    jkfSign.setBusinessType(configService.getDeclareBusinessType());
    jkfSign.setCompanyCode(configService.getCompanyCode());
    jkfSign.setDeclareType(configService.getDeclareType());
    jkfSign.setBusinessNo(generateSequence());
    wayBill.setJkfSign(jkfSign);
    body.setWayBillList(Arrays.asList(wayBill));

    CommonXmlRequestHead head = new CommonXmlRequestHead();
    head.setBusinessType(CommonXmlRequestHead.IMPORTBILL);
    request.setHead(head);
    request.setBody(body);
    return request;
}

From source file:info.magnolia.link.LinkUtil.java

/**
 * Creates link based on provided parameters. Should the uuid be non existent or the fallback handle invalid, creates nonetheless an <em>"undefined"</em> {@link Link} object,
 * pointing to the non existing uuid so that broken link detection tools can find it.
 * @param uuid UUID of the content/*from  w  w w . j  ava 2  s . com*/
 * @param workspaceName Content repository name.
 * @param fallbackHandle Optional fallback content handle.
 * @param nodeDataName Content node data name for binary data.
 * @param extension Optional link extension.
 * @param anchor Optional link anchor.
 * @param parameters Optional link parameters.
 * @return Link pointing to the content denoted by uuid and repository. Link is created using all provided optional values if present.
 * @throws LinkException
 */
public static Link createLinkInstance(String uuid, String workspaceName, String fallbackHandle,
        String nodeDataName, String extension, String anchor, String parameters) throws LinkException {
    final String defaultRepository = StringUtils.defaultIfEmpty(workspaceName, RepositoryConstants.WEBSITE);
    Link link;
    try {
        link = createLinkInstance(defaultRepository, uuid);
    } catch (LinkException e) {
        try {
            final Node node = MgnlContext.getJCRSession(defaultRepository)
                    .getNode(fallbackHandle != null ? fallbackHandle : "");
            link = createLinkInstance(node);
        } catch (PathNotFoundException pnfe) {
            log.warn("Can't find node with uuid {} or handle {} in repository {}",
                    new Object[] { uuid, fallbackHandle, defaultRepository });
            link = new Link();
            link.setUUID(uuid);
        } catch (RepositoryException re) {
            log.warn("Can't find node with uuid {} or handle {} in repository {}",
                    new Object[] { uuid, fallbackHandle, defaultRepository });
            link = new Link();
            link.setUUID(uuid);
        }
    }
    link.setFallbackPath(fallbackHandle);
    link.setPropertyName(nodeDataName);
    link.setExtension(extension);
    link.setAnchor(anchor);
    link.setParameters(parameters);

    return link;
}

From source file:gtu._work.etc._3DSMovieRenamer.java

private void initGUI() {
    try {/*  www . jav a2s. c o  m*/
        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("3DS Rename");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("vid list", null, jPanel1, null);
                {
                    openDir = new JButton();
                    jPanel1.add(openDir, BorderLayout.NORTH);
                    openDir.setText("open dir");
                    openDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("openDir.actionPerformed", evt);
                        }
                    });
                }
                {
                    ListModel vidListModel = new DefaultListModel();
                    vidList = new JList();
                    jPanel1.add(vidList, BorderLayout.CENTER);
                    vidList.setModel(vidListModel);
                    vidList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            swingUtil.invokeAction("vidList.mouseClicked", evt);
                        }
                    });
                    vidList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            swingUtil.invokeAction("vidList.keyPressed", evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    jPanel1.add(jPanel3, BorderLayout.SOUTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(445, 34));
                    {
                        renameText = new JTextField();
                        jPanel3.add(renameText);
                        renameText.setPreferredSize(new java.awt.Dimension(187, 24));
                    }
                    {
                        renameBtn = new JButton();
                        jPanel3.add(renameBtn);
                        renameBtn.setText("rename");
                        renameBtn.setPreferredSize(new java.awt.Dimension(106, 24));
                        renameBtn.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("renameBtn.mouseClicked", evt);
                            }
                        });
                    }
                    {
                        forceChange = new JCheckBox();
                        jPanel3.add(forceChange);
                        forceChange.setText("force");
                        forceChange.setPreferredSize(new java.awt.Dimension(64, 21));
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("copy", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        ListModel copyToListModel = new DefaultListModel();
                        copyToList = new JList();
                        jScrollPane1.setViewportView(copyToList);
                        copyToList.setModel(copyToListModel);
                        copyToList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("copyToList.mouseClicked", evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("BT Movie", null, jPanel4, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel4.add(jScrollPane2, BorderLayout.WEST);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(254, 355));
                    {
                        btDirTree = new JTree();
                        jScrollPane2.setViewportView(btDirTree);
                        btDirTree.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        btDirTree.addPropertyChangeListener(new PropertyChangeListener() {
                            public void propertyChange(PropertyChangeEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        JTreeUtil.newInstance(btDirTree).fileSystem(DEFAULT_BT_DIR);
                    }
                }
                {
                    jPanel5 = new JPanel();
                    BorderLayout jPanel5Layout = new BorderLayout();
                    jPanel5.setLayout(jPanel5Layout);
                    jPanel4.add(jPanel5, BorderLayout.CENTER);
                    {
                        jScrollPane3 = new JScrollPane();
                        jPanel5.add(jScrollPane3, BorderLayout.CENTER);
                        jScrollPane3.setPreferredSize(new java.awt.Dimension(427, 355));
                        {
                            DefaultListModel btMovListModel = new DefaultListModel();
                            btMovList = new JList();
                            jScrollPane3.setViewportView(btMovList);
                            btMovList.setModel(btMovListModel);
                            btMovList.addMouseListener(new MouseAdapter() {
                                public void mouseClicked(MouseEvent evt) {
                                    swingUtil.invokeAction(evt);
                                }
                            });
                            btMovList.addKeyListener(new KeyAdapter() {
                                public void keyPressed(KeyEvent evt) {
                                    JListUtil.newInstance(btMovList).defaultJListKeyPressed(evt);
                                }
                            });
                        }
                    }
                }
            }
            {
                jPanel6 = new JPanel();
                FlowLayout jPanel6Layout = new FlowLayout();
                jTabbedPane1.addTab("common", null, jPanel6, null);
                jPanel6.setLayout(jPanel6Layout);
                {
                    execute3dsVidTransfer = new JButton();
                    jPanel6.add(execute3dsVidTransfer);
                    execute3dsVidTransfer.setText("execute 3ds video transfer");
                    execute3dsVidTransfer.setPreferredSize(new java.awt.Dimension(207, 42));
                    execute3dsVidTransfer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            String bat = "C:/apps/_movie/3DSVideov1.00/3DS Video.exe";
                            try {
                                Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", bat));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
                {
                    openMovieAppDir = new JButton();
                    jPanel6.add(openMovieAppDir);
                    openMovieAppDir.setText("open movie app dir");
                    openMovieAppDir.setPreferredSize(new java.awt.Dimension(207, 42));
                    openMovieAppDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                Desktop.getDesktop().open(new File("C:/apps/_movie"));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
            }
            {
                jPanel7 = new JPanel();
                BorderLayout jPanel7Layout = new BorderLayout();
                jTabbedPane1.addTab("fake rename", null, jPanel7, null);
                jPanel7.setLayout(jPanel7Layout);
                {
                    openFakeRenameDir = new JButton();
                    jPanel7.add(openFakeRenameDir, BorderLayout.NORTH);
                    openFakeRenameDir.setText("open dir");
                    openFakeRenameDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            if (file != null) {
                                DefaultListModel model = new DefaultListModel();
                                for (File f : file.listFiles()) {
                                    model.addElement(f);
                                }
                                openFakeRenameDirList.setModel(model);
                            }
                        }
                    });
                }
                {
                    DefaultListModel openFakeRenameDirListModel = new DefaultListModel();
                    openFakeRenameDirList = new JList();
                    jPanel7.add(openFakeRenameDirList, BorderLayout.CENTER);
                    openFakeRenameDirList.setModel(openFakeRenameDirListModel);
                    openFakeRenameDirList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            File file = (File) JListUtil.getLeadSelectionObject(openFakeRenameDirList);
                            try {
                                Process process = Runtime.getRuntime()
                                        .exec(String.format("cmd /c call \"%s\"", file));
                                InputStream ins = process.getInputStream();
                                while (ins.read() != -1) {
                                    //TODO
                                }
                                ins.close();
                                System.out.println("done...");
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    openFakeRenameDirList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            JListUtil.newInstance(openFakeRenameDirList).defaultJListKeyPressed(evt);
                        }
                    });
                }
                {
                    jPanel8 = new JPanel();
                    jPanel7.add(jPanel8, BorderLayout.SOUTH);
                    jPanel8.setPreferredSize(new java.awt.Dimension(681, 43));
                    {
                        openFakeRenameDir_newName = new JTextField();
                        jPanel8.add(openFakeRenameDir_newName);
                        openFakeRenameDir_newName.setPreferredSize(new java.awt.Dimension(287, 27));
                    }
                    {
                        fakeRenameExecute = new JButton();
                        jPanel8.add(fakeRenameExecute);
                        fakeRenameExecute.setText("execute");
                        fakeRenameExecute.setPreferredSize(new java.awt.Dimension(95, 27));
                        fakeRenameExecute.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                DefaultListModel model = (DefaultListModel) openFakeRenameDirList.getModel();
                                //TODO
                            }
                        });
                    }
                }
            }

            swingUtil.addAction("copyToList.mouseClicked", new Action() {
                public void action(EventObject evt) throws Exception {
                    try {
                        if (((MouseEvent) evt).getButton() == 3) {
                            JMenuItem reloadMenu = new JMenuItem();
                            reloadMenu.setText("reload SD card directory");
                            reloadMenu.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    DefaultListModel copyToListModel = new DefaultListModel();
                                    for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                                        public boolean accept(File paramFile, String paramString) {
                                            if (paramFile.isDirectory()
                                                    && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                                return true;
                                            }
                                            return false;
                                        }
                                    })) {
                                        copyToListModel.addElement(f);
                                    }
                                    copyToList.setModel(copyToListModel);
                                }
                            });
                            JMenuItem copyAllToMenu = new JMenuItem();
                            {
                                copyAllToMenu.setText(
                                        String.format("move %d vids to...", vidList.getModel().getSize()));
                                final File toDir = (File) JListUtil.getLeadSelectionObject(copyToList);
                                if (toDir == null || !toDir.exists() || !toDir.isDirectory()) {
                                    copyAllToMenu.setEnabled(false);
                                }
                                if (vidList.getModel().getSize() == 0) {
                                    copyAllToMenu.setText("copy no file...");
                                    copyAllToMenu.setEnabled(false);
                                }
                                copyAllToMenu.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        DefaultListModel model = JListUtil.newInstance(vidList).getModel();
                                        if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil
                                                .newInstance().iconWaringMessage().confirmButtonYesNo()
                                                .showConfirmDialog("are you sure copy files : "
                                                        + model.getSize() + "\n to dir : " + toDir,
                                                        "COPY VIDS")) {
                                            return;
                                        }
                                        for (int ii = 0; ii < model.getSize(); ii++) {
                                            File src = (File) model.getElementAt(ii);
                                            src.renameTo(new File(toDir, src.getName()));
                                        }
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("copy completed!", "SUCCESS");
                                        loadDirVids();
                                    }
                                });
                            }

                            JPopupMenuUtil.newInstance(copyToList).applyEvent((MouseEvent) evt)
                                    .addJMenuItem(reloadMenu, copyAllToMenu).show();
                        }
                    } catch (Exception ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
            swingUtil.addAction("openDir.actionPerformed", new Action() {
                public void action(EventObject evt) throws Exception {
                    File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                            .getApproveSelectedFile();
                    if (file == null) {
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("dir not corrent!, set desktop", getTitle());
                        loadDir = FileUtil.DESKTOP_DIR;
                    } else {
                        loadDir = file;
                    }
                    loadDirVids();
                }
            });
            swingUtil.addAction("vidList.mouseClicked", new Action() {
                //                    final String player = "C:/Program Files (x86)/GRETECH/GomPlayer/GOM.EXE";

                public void action(EventObject evt) throws Exception {
                    int pos = -1;
                    if ((pos = vidList.getLeadSelectionIndex()) == -1) {
                        return;
                    }
                    MouseEvent mevt = (MouseEvent) evt;

                    final File selectItem = (File) vidList.getModel().getElementAt(pos);

                    List<JMenuItem> menuList = new ArrayList<JMenuItem>();
                    JMenuItem simpleRenamer = new JMenuItem();
                    final String simpleRenamePrefix = RandomUtil.upperCase(3);
                    simpleRenamer.setText("Rename : " + simpleRenamePrefix);
                    simpleRenamer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent paramActionEvent) {
                            String value = StringUtils.defaultString(JOptionPaneUtil.newInstance()
                                    .showInputDialog("3 char prefix?", "AVI PREFIX"), simpleRenamePrefix);
                            if (value != null && value.matches("[a-zA-Z]{3}")) {
                                selectItem.renameTo(getNewFile(selectItem.getParentFile(), value));
                                loadDirVids();
                            } else {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("prefix is not correct!", "ERROR");
                            }
                        }
                    });
                    menuList.add(simpleRenamer);
                    if (load3DSDir == null) {
                        reload3DSDir();
                        if (load3DSDir == null) {
                            JMenuItem disable = new JMenuItem();
                            disable.setText("MOVE : SD card is not set!");
                            disable.setEnabled(false);
                            menuList.add(disable);
                        }
                    } else {
                        for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                            public boolean accept(File paramFile, String paramString) {
                                if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                    return true;
                                }
                                return false;
                            }
                        })) {
                            JMenuItem copyTo = new JMenuItem();
                            copyTo.setText("MOVE : " + f.getName());
                            copyTo.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil
                                            .newInstance().iconQuestionMessage().confirmButtonYesNo()
                                            .showConfirmDialog(//
                                                    "are you sure move file\n" + //
                                    selectItem + "\n" + //
                                    "to\n" + //
                                    "dir : " + f + "  ??"//
                                    , "COPY FILE")) {

                                        File copyToNewDirFile = new File(f, selectItem.getName());
                                        if (copyToNewDirFile.exists()) {
                                            JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                                    "target dir file already exist!, need rename!",
                                                    "FILE ALREADY EXIST");
                                            return;
                                        }
                                        selectItem.renameTo(copyToNewDirFile);
                                        loadDirVids();

                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("move completed!", "MOVE FILE");
                                    }
                                }
                            });
                            menuList.add(copyTo);
                        }
                    }
                    JPopupMenuUtil.newInstance(vidList).applyEvent(mevt)
                            .addJMenuItem(menuList.toArray(new JMenuItem[menuList.size()])).show();

                    if (mevt.getClickCount() != 2) {
                        return;
                    }
                    String clkItemPath = selectItem.getAbsolutePath();
                    String command = "cmd /c call \"" + clkItemPath + "\"";
                    System.out.println(command);
                    Runtime.getRuntime().exec(command);
                }
            });
            swingUtil.addAction("vidList.keyPressed", new Action() {
                public void action(EventObject evt) throws Exception {
                    JListUtil.newInstance(vidList).defaultJListKeyPressed(evt);
                }
            });
            swingUtil.addAction("renameBtn.mouseClicked", new Action() {

                Pattern aviNamePattern = Pattern.compile("^([a-zA-Z]{3})_\\d{4}\\.[aA][vV][iI]$");

                public void action(EventObject evt) throws Exception {
                    String name = StringUtils.defaultIfEmpty(renameText.getText(), RandomUtil.upperCase(3));
                    System.out.println("name = " + name + ", force : " + forceChange.isSelected());
                    if (!name.matches("[a-zA-Z]{3}")) {
                        renameText.setText("");
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("rename must eng 3 char!", "ERROR");
                        return;
                    }
                    DefaultListModel model = (DefaultListModel) vidList.getModel();
                    boolean matchOk = false;
                    if (model.size() != 0) {
                        File oldFile = null;
                        Matcher matcher = null;
                        for (int ii = 0; ii < model.getSize(); ii++) {
                            oldFile = (File) model.getElementAt(ii);

                            if (!oldFile.exists()) {
                                JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                        "file not exeist : \n" + oldFile.getAbsolutePath(), getTitle());
                                return;
                            }
                            matcher = aviNamePattern.matcher(oldFile.getName());
                            matchOk = matcher.find();
                            System.out.println("matchOk = " + matchOk);
                            if (matchOk && !forceChange.isSelected()) {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), matcher.group(1)));
                            } else {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), name));
                            }
                        }
                        JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog("success!",
                                getTitle());
                    }
                    loadDirVids();
                }
            });

            ToolTipManager.sharedInstance().setInitialDelay(0);
            swingUtil.addAction(btMovList, MouseEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    final File file = (File) JListUtil.getLeadSelectionObject(btMovList);
                    if (JMouseEventUtil.buttonLeftClick(1, evt)) {
                        btMovList.setToolTipText(
                                DateFormatUtils.format(file.lastModified(), "yyyy/MM/dd HH:mm:ss") + " length:"
                                        + (file.length() / 1024) + "k");
                    }

                    final Object[] objects = btMovList.getSelectedValues();
                    JPopupMenuUtil.newInstance(btMovList).applyEvent(evt)//
                            .addJMenuItem("move out", (objects != null && objects.length > 0),
                                    new ActionListener() {
                                        public void actionPerformed(ActionEvent paramActionEvent) {
                                            List<File> list = new ArrayList<File>();
                                            for (Object val : objects) {
                                                list.add((File) val);
                                            }
                                            if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure move file from\n" + list.toString().replace(',', '\n')
                                                            + "\nto\n" + DEFAULT_BT_DIR,
                                                    "MOVE")) {
                                                return;
                                            }
                                            StringBuilder sb = new StringBuilder();
                                            File moveTo = null;
                                            for (File file : list) {
                                                sb.append((file.renameTo(
                                                        moveTo = new File(DEFAULT_BT_DIR, file.getName()))
                                                        && moveTo.exists()) ? "" : file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() == 0 ? "move success!" : "move failed!\n" + sb);
                                        }
                                    })
                            .addJMenuItem("delete this", file.exists(), new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                            "sure delete file \n" + file, "DELETE")) {
                                        return;
                                    }
                                    boolean result = file.delete();
                                    System.out.println("!!!!!" + result + "..." + file.exists());
                                    JCommonUtil._jOptionPane_showMessageDialog_info(
                                            result ? "delete success!" : "delete failed!");
                                }
                            }).show();

                    if (JMouseEventUtil.buttonLeftClick(2, evt)) {
                        Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", file));
                    }
                }
            });
            swingUtil.addAction(btDirTree, MouseEvent.class, new Action() {

                File getSingleFile() {
                    return ((JFile) JTreeUtil.newInstance(btDirTree).getSelectItem().getUserObject()).getFile();
                }

                public void action(EventObject evt) throws Exception {
                    int selectCount = btDirTree.getSelectionModel().getSelectionCount();
                    if (selectCount == 1) {
                        final File file = getSingleFile();
                        JPopupMenuUtil.newInstance(btDirTree).applyEvent(evt).addJMenuItem("delete this",
                                selectCount == 1 && file.exists(), new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        if (file.isFile()) {
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete FILE : \n" + file, "WARNING")) {
                                                file.delete();
                                                JCommonUtil._jOptionPane_showMessageDialog_info(
                                                        (file.exists() ? "delete failed!" : "delete success!"));
                                            }
                                        }
                                        if (file.isDirectory()) {
                                            StringBuilder sb = new StringBuilder();
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete DIR : \n" + file, "WARNING")) {
                                                List<Boolean> delL = new ArrayList<Boolean>();
                                                for (File f : file.listFiles()) {
                                                    if (fileExtensionPattern.matcher(f.getName()).find()
                                                            || f.length() > 1000000L) {
                                                        if (!JCommonUtil
                                                                ._JOptionPane_showConfirmDialog_yesNoOption(
                                                                        "delete this : \n" + f,
                                                                        "CHECK AGAIN")) {
                                                            continue;
                                                        }
                                                        delL.add(f.delete());
                                                    }
                                                    delL.add(f.delete());
                                                }
                                                for (File f : file.listFiles()) {
                                                    if (f.exists()) {
                                                        sb.append(f + "\n");
                                                    }
                                                }
                                                System.out.println("delL.contains(false)==================>"
                                                        + delL.contains(false));
                                            }
                                            if (!file.delete()) {
                                                sb.append(file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() > 0 ? "delete failed!\nlist:\n" + sb
                                                            : "delete success!");
                                            if (sb.length() == 0) {
                                                DefaultMutableTreeNode node = JTreeUtil.newInstance(btDirTree)
                                                        .getSelectItem();
                                                System.out.println(
                                                        JTreeUtil.newInstance(btDirTree).removeNode(node));
                                            }
                                        }
                                    }
                                }).addJMenuItem("open dir", new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        File openTarget = file;
                                        if (file.isFile()) {
                                            openTarget = file.getParentFile();
                                        }
                                        try {
                                            Desktop.getDesktop().open(openTarget);
                                        } catch (IOException e) {
                                            JCommonUtil.handleException(e);
                                        }
                                    }
                                }).show();
                    }
                }
            });
            swingUtil.addAction(btDirTree, PropertyChangeEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    List<File> list = new ArrayList<File>();
                    for (DefaultMutableTreeNode node : JTreeUtil.newInstance(btDirTree).getSelectItems()) {
                        JFile jfile = (JFile) node.getUserObject();
                        if (jfile.getFile().isDirectory()) {
                            for (File f : jfile.getFile().listFiles(new FilenameFilter() {
                                public boolean accept(File paramFile, String paramString) {
                                    return fileExtensionPattern.matcher(paramString).find();
                                }
                            })) {
                                System.out.println(f.getName() + "...." + f.length());
                                list.add(f);
                            }
                        }
                    }
                    Collections.sort(list, new Comparator<File>() {
                        public int compare(File paramT1, File paramT2) {
                            return paramT1.lastModified() > paramT2.lastModified() ? -1 : 1;
                        }
                    });
                    btMovList.setModel(JListUtil.createModel(list.iterator()));
                }
            });
        }
        this.setSize(702, 422);

        loadDirVids();
        reload3DSDir();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:gtu._work.ui.JSFMakerUI.java

void resetPasteClipboardHtmlToJtable() {
    String content = ClipboardUtil.getInstance().getContents();
    Pattern tdStartPattern = Pattern.compile("<[tT][dDhH][^>]*>");
    Pattern tdEndPattern = Pattern.compile("</[tT][dDhH]>");
    Pattern innerPattern_HasTag = Pattern.compile("<[\\w:]+\\s[^>]*value=\"([^\"]*)\"[^>]*>",
            Pattern.MULTILINE);//from w  ww.  j a  va  2s.co  m
    Matcher innerMatcher = null;
    Scanner scan = new Scanner(content);
    Scanner tdScan = null;
    String currentContent = null;
    String tdContent = null;
    StringBuilder sb = new StringBuilder();
    scan.useDelimiter("<tr>");
    for (; scan.hasNext();) {
        boolean anyMatcher = false;

        tdScan = new Scanner(scan.next());
        tdScan.useDelimiter(tdStartPattern);
        while (tdScan.hasNext()) {
            tdScan.useDelimiter(tdEndPattern);
            if (tdScan.hasNext()) {
                tdContent = tdScan.next().replaceAll(tdStartPattern.pattern(), "");
                {
                    innerMatcher = innerPattern_HasTag.matcher(tdContent.toString());
                    if (innerMatcher.find()) {
                        currentContent = StringUtils.defaultIfEmpty(innerMatcher.group(1), "&nbsp;");
                        //                            System.out.format("1[%s]\n", currentContent);
                        sb.append(currentContent + "\t");
                        continue;
                    }
                    currentContent = tdContent.toString().replaceAll("<[\\w:=,.#;/'?\"\\s\\{\\}\\(\\)\\[\\]]+>",
                            "");
                    currentContent = currentContent.replaceAll("[\\s\t\n]", "");
                    currentContent = StringUtils.defaultIfEmpty(currentContent, "&nbsp;");
                    //                        System.out.format("2[%s]\n", currentContent);
                    sb.append(currentContent + "\t");
                    anyMatcher = true;
                }
            }
            tdScan.useDelimiter(tdStartPattern);
        }
        if (anyMatcher) {
            sb.append("\n");
        }
    }
    scan.close();
    ClipboardUtil.getInstance().setContents(sb);
    System.out.println("####################################");
    System.out.println(sb);
    System.out.println("####################################");
}

From source file:hudson.plugins.clearcase.AbstractClearCaseScm.java

public String getViewPath(VariableResolver<String> variableResolver) {
    String normalized = null;/*from  w w w . j a va  2  s .  co  m*/
    String viewPath = StringUtils.defaultIfEmpty(getViewPath(), getViewName());
    if (viewPath != null) {
        normalized = Util.replaceMacro(viewPath, variableResolver).replaceAll("[\\s\\\\\\/:\\?\\*\\|]+", "_");
        setNormalizedViewPath(normalized);
    }
    return normalized;
}

From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java

protected List<AutoChildTemplate> getChildTemplatesBySubNode(RuleTemplate ruleTemplate, TypeInfo typeInfo,
        String propertyName, XmlSubNode xmlSubNode, TypeInfo propertyTypeInfo,
        InitializerContext initializerContext) throws Exception {
    List<AutoChildTemplate> childTemplates = new ArrayList<AutoChildTemplate>();

    boolean aggregated = xmlSubNode.aggregated();
    Class<?> propertyType = null;
    if (propertyTypeInfo != null) {
        propertyType = propertyTypeInfo.getType();
        aggregated = propertyTypeInfo.isAggregated();
    }/*w w  w .j a  v a2 s  . c o m*/

    Set<Class<?>> implTypes = ClassUtils.findClassTypes(xmlSubNode.implTypes(), propertyType);
    for (Class<?> implType : implTypes) {
        if (implType.equals(typeInfo.getType())) {
            continue;
        }

        boolean isPublic = true;
        XmlNode implXmlNode = implType.getAnnotation(XmlNode.class);
        if (implXmlNode != null && ArrayUtils.indexOf(implType.getDeclaredAnnotations(), implXmlNode) >= 0
                && !implXmlNode.isPublic()) {
            if (ArrayUtils.indexOf(xmlSubNode.implTypes(), implType.getName()) < 0) {
                continue;
            } else {
                isPublic = false;
            }
        }

        AutoChildTemplate childTemplate = getChildNodeByBeanType(null, xmlSubNode, aggregated, implType,
                "protected", initializerContext);
        if (childTemplate != null) {
            childTemplate.setPublic(isPublic);
            childTemplates.add(childTemplate);
        }
    }

    if (propertyType != null) {
        XmlNode implXmlNode = propertyType.getAnnotation(XmlNode.class);
        if (implXmlNode == null || implXmlNode.isPublic()) {
            AutoChildTemplate childTemplate = getChildNodeByBeanType(StringUtils.capitalize(propertyName),
                    xmlSubNode, aggregated, propertyType, null, initializerContext);
            if (childTemplate != null) {
                childTemplates.add(childTemplate);
            }
        }
    }

    XmlNodeWrapper wrapper = xmlSubNode.wrapper();
    String wrapperName = wrapper.nodeName();
    if (StringUtils.isNotEmpty(wrapperName)) {
        List<AutoChildTemplate> wrapperTemplates = new ArrayList<AutoChildTemplate>();
        AutoRuleTemplate wrapperRuleTemplate = new AutoRuleTemplate("Wrapper." + wrapper.nodeName());
        wrapperRuleTemplate.setLabel(StringUtils.defaultIfEmpty(wrapper.label(), wrapper.nodeName()));
        if (StringUtils.isNotEmpty(wrapper.icon())) {
            wrapperRuleTemplate.setIcon(wrapper.icon());
        }
        wrapperRuleTemplate.setNodeName(wrapper.nodeName());
        for (ChildTemplate childTemplate : childTemplates) {
            wrapperRuleTemplate.addChild(childTemplate);
        }

        AutoChildTemplate wrapperChildTemplate = new AutoChildTemplate(wrapperName, wrapperRuleTemplate,
                xmlSubNode);
        wrapperChildTemplate.setFixed(wrapper.fixed());
        wrapperTemplates.add(wrapperChildTemplate);
        return wrapperTemplates;
    } else {
        return childTemplates;
    }
}

From source file:com.medicaid.mmis.util.DataLoader.java

/**
 * <pre>//from w  w w  .  ja va  2 s  . c om
 * 001780    05  WS-000-EXT-OWN-INFO.                                          
 * 001790      10  WS-000-EXT-OWN-I-OWNER        PIC X(01) VALUE ' '.
 * </pre>
 * 
 * @throws PortalServiceException for any errors encountered.
 */
private void readWS000EXTOWNINFO(ByteArrayInputStream stream, ProviderProfile profile)
        throws PortalServiceException {
    String strWS_000_EXT_OWN_I_OWNER = readField(stream, ColumnDef.WS_000_EXT_OWN_I_OWNER);
    profile.setMaintainsOwnPrivatePractice(StringUtils.defaultIfEmpty(strWS_000_EXT_OWN_I_OWNER, "N"));
}