Example usage for java.util StringTokenizer countTokens

List of usage examples for java.util StringTokenizer countTokens

Introduction

In this page you can find the example usage for java.util StringTokenizer countTokens.

Prototype

public int countTokens() 

Source Link

Document

Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

Usage

From source file:com.newatlanta.appengine.nio.file.GaePath.java

@Override
public Path subpath(int beginIndex, int endIndex) {
    StringTokenizer st = new StringTokenizer(path, PATH_DELIMS, true);
    int numEntries = st.countTokens();
    if ((beginIndex < 0) || (beginIndex >= numEntries) || (endIndex <= beginIndex) || (endIndex > numEntries)) {
        throw new IllegalArgumentException();
    }/*from w  w w . j  ava  2s  .c  o  m*/
    StringBuffer sb = new StringBuffer();
    for (int i = beginIndex; i < endIndex; i++) {
        sb.append(st.nextToken());
    }
    return new GaePath(fileSystem, sb.toString());
}

From source file:view.App.java

private void initGUI() {
    try {// w  w  w  .  ja v a2s.com
        {
            jPanel1 = new JPanel();
            BorderLayout jPanel1Layout = new BorderLayout();
            jPanel1.setLayout(jPanel1Layout);
            getContentPane().add(jPanel1, BorderLayout.CENTER);
            jPanel1.setPreferredSize(new java.awt.Dimension(901, 398));
            {
                jPanel2 = new JPanel();
                BoxLayout jPanel2Layout = new BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS);
                jPanel2.setLayout(jPanel2Layout);
                jPanel1.add(jPanel2, BorderLayout.WEST);
                jPanel2.setPreferredSize(new java.awt.Dimension(292, 446));
                {
                    jPanel5 = new JPanel();
                    jPanel2.add(jPanel5);
                    jPanel5.setPreferredSize(new java.awt.Dimension(292, 109));
                    {
                        {
                            jTextArea1 = new JTextArea();
                            jTextArea1.setWrapStyleWord(true);
                            jTextArea1.setLineWrap(true);
                            DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret();
                            caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

                            jTextArea1.addFocusListener(new FocusAdapter() {
                                public void focusGained(FocusEvent evt) {

                                    if (jTable1.getModel().getRowCount() == 0 && !jButton1.isEnabled()) {
                                        jButton1.setEnabled(true);
                                        jTextArea1.setText("");
                                    }

                                }
                            });
                            JScrollPane sp = new JScrollPane();
                            sp.setPreferredSize(new java.awt.Dimension(281, 97));
                            sp.setViewportView(jTextArea1);

                            jPanel5.add(sp, BorderLayout.CENTER);
                        }
                    }

                }
                {
                    jPanel4 = new JPanel();
                    jPanel2.add(jPanel4);
                    FlowLayout jPanel4Layout = new FlowLayout();
                    jPanel4Layout.setAlignment(FlowLayout.RIGHT);
                    jPanel4.setPreferredSize(new java.awt.Dimension(292, 45));
                    jPanel4.setSize(102, 51);
                    jPanel4.setLayout(jPanel4Layout);
                    {
                        jButton1 = new JButton();
                        jPanel4.add(jButton1);
                        jButton1.setText("Get Quotes");
                        jButton1.setSize(100, 50);
                        jButton1.setPreferredSize(new java.awt.Dimension(100, 26));
                        jButton1.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                //   
                                String tickerStr = jTextArea1.getText();
                                if (tickerStr.equals("") || tickerStr.equals(null)
                                        || tickerStr.equals(" ")) {
                                    jTextArea1.setText(" ");
                                    return;
                                }
                                StringTokenizer tokenizer = new StringTokenizer(tickerStr, " ");
                                String[] tickers = new String[tokenizer.countTokens()];
                                int i = 0;
                                while (tokenizer.hasMoreTokens()) {
                                    tickers[i] = tokenizer.nextToken();
                                    i++;
                                }
                                try {
                                    Controller.getQuotes(tickers);
                                } catch (CloneNotSupportedException e) {
                                    JOptionPane.showMessageDialog(jPanel1, "   ");
                                }
                                jButton1.setEnabled(false);
                            }
                        });
                    }
                }
                {
                    jPanel6 = new JPanel();
                    BorderLayout jPanel6Layout = new BorderLayout();
                    jPanel6.setLayout(jPanel6Layout);
                    jPanel2.add(jPanel6);
                    {
                        jScrollPane1 = new JScrollPane();
                        jPanel6.add(jScrollPane1, BorderLayout.CENTER);
                        jScrollPane1.setPreferredSize(new java.awt.Dimension(292, 341));
                        {
                            TableModel jTable1Model = new DefaultTableModel(null,
                                    new String[] { "", "MA Value", "", "MA Value" });
                            jTable1 = new JTable();

                            jScrollPane1.setViewportView(jTable1);
                            jTable1.setModel(jTable1Model);
                            jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

                        }
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jPanel1.add(jPanel3, BorderLayout.CENTER);
                {
                    //                  chart = ChartFactory.createLineChart(" ", "dates", "correlation ratio", null, 
                    //                        PlotOrientation.VERTICAL, true, true, false);
                    //                  ChartPanel chartPanel = new ChartPanel(chart);
                    //                  chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );
                    //                  jPanel3.add(chartPanel);
                }
                {

                }
            }
        }
        this.setSize(966, 531);
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu3 = new JMenu();
                jMenuBar1.add(jMenu3);
                jMenu3.setText("File");
                {
                    //                  newFileMenuItem = new JMenuItem();
                    //                  jMenu3.add(newFileMenuItem);
                    //                  newFileMenuItem.setText("New");
                    //                  newFileMenuItem.addActionListener(new ActionListener() {
                    //                     public void actionPerformed(ActionEvent evt) {
                    ////                        jTextArea1.setText("");
                    ////                        DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
                    ////                        model.setRowCount(0);
                    ////                        Controller.clearPortfolio();
                    //                     }
                    //                  });
                }
                {
                    jSeparator2 = new JSeparator();
                    jMenu3.add(jSeparator2);
                }
                {
                    exitMenuItem = new JMenuItem();
                    jMenu3.add(exitMenuItem);
                    exitMenuItem.setText("Exit");
                    exitMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            int action = JOptionPane.showConfirmDialog(jPanel1,
                                    "     ?", "Confirm Exit",
                                    JOptionPane.OK_CANCEL_OPTION);

                            if (action == JOptionPane.OK_OPTION)
                                System.exit(0);

                        }
                    });
                }
            }
            {
                jMenu4 = new JMenu();
                jMenuBar1.add(jMenu4);
                jMenu4.setText("Edit");
                {
                    cutMenuItem = new JMenuItem();
                    jMenu4.add(cutMenuItem);
                    cutMenuItem.setText("Cut");
                    cutMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            String txt = jTextArea1.getText();
                            StringSelection selection = new StringSelection(txt);
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            clp.setContents(selection, null);
                            jTextArea1.setText("");

                        }
                    });
                }
                {
                    copyMenuItem = new JMenuItem();
                    jMenu4.add(copyMenuItem);
                    copyMenuItem.setText("Copy");
                    copyMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                            String txt = jTextArea1.getText();
                            StringSelection selection = new StringSelection(txt);
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            clp.setContents(selection, null);

                        }
                    });
                }
                {
                    pasteMenuItem = new JMenuItem();
                    jMenu4.add(pasteMenuItem);
                    pasteMenuItem.setText("Paste");
                    pasteMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            try {
                                String data = (String) clp.getData(DataFlavor.stringFlavor);
                                jTextArea1.setText(data);
                            } catch (UnsupportedFlavorException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            } catch (IOException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
                        }
                    });
                }
            }
            {
                jMenu5 = new JMenu();
                jMenuBar1.add(jMenu5);
                jMenu5.setText("Help");
                {
                    helpMenuItem = new JMenuItem();
                    jMenu5.add(helpMenuItem);
                    helpMenuItem.setText("About");
                    helpMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                            JOptionPane.showMessageDialog(jPanel1,
                                    "    .    r.zhumagulov@gmail.com",
                                    "About", JOptionPane.PLAIN_MESSAGE);

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

From source file:de.tor.tribes.ui.views.DSWorkbenchTagFrame.java

private void transferSelectedTagsAsBBCodesToClipboard() {
    List<Tag> selection = getSelectedTags();
    if (selection.isEmpty()) {
        showInfo("Keine Gruppe ausgewhlt");
        return;/*from  w  ww .j ava2s .  c o  m*/
    }
    boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
            "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
            "Nein", "Ja") == JOptionPane.YES_OPTION);

    try {
        String formatted = new TagListFormatter().formatElements(selection, extended);
        StringTokenizer t = new StringTokenizer(formatted, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die ausgewhlten Gruppen bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(formatted), null);
        showSuccess("BB-Codes in die Zwischenablage kopiert");
    } catch (HeadlessException he) {
        logger.error("Failed to copy data to clipboard", he);
        showError("Fehler beim Kopieren in die Zwischenablage");
    }
}

From source file:com.google.enterprise.connector.sharepoint.client.SiteDataHelper.java

/**
 * Gets the collection of all the lists on the sharepoint server which are of
 * a given type. E.g., DocumentLibrary//from   w w  w  .j  a va  2 s  . c o  m
 *
 * @param webstate The web from which the list/libraries are to be discovered
 * @return list of BaseList objects.
 */
public List<ListState> getNamedLists(final WebState webstate) {
    final ArrayList<ListState> listCollection = new ArrayList<ListState>();
    if (webstate == null) {
        LOGGER.warning("Unable to get the list collection because webstate is null");
        return listCollection;
    }

    final ArrayOf_sListHolder vLists = Util.makeWSRequest(sharepointClientContext, siteDataWS,
            new Util.RequestExecutor<ArrayOf_sListHolder>() {
                public ArrayOf_sListHolder onRequest(final BaseWS ws) throws Throwable {
                    return ((SiteDataWS) ws).getListCollection();
                }

                public void onError(final Throwable e) {
                    LOGGER.log(Level.WARNING, "Call to getListCollection failed.", e);
                }
            });
    if (vLists == null) {
        LOGGER.log(Level.WARNING, "Unable to get the list collection");
        return listCollection;
    }

    final Collator collator = Util.getCollator();

    try {
        final _sList[] sl = vLists.value;

        if (sl != null) {
            webstate.setExisting(true);
            for (_sList element : sl) {
                String url = null;
                String strBaseTemplate = null;

                if (element == null) {
                    continue;
                }

                final String baseType = element.getBaseType();
                LOGGER.log(Level.FINE, "Base Type returned by the Web Service : " + baseType);
                if (!collator.equals(baseType, (SPConstants.DISCUSSION_BOARD))
                        && !collator.equals(baseType, (SPConstants.DOC_LIB))
                        && !collator.equals(baseType, (SPConstants.GENERIC_LIST))
                        && !collator.equals(baseType, (SPConstants.ISSUE))
                        && !collator.equals(baseType, (SPConstants.SURVEYS))) {
                    LOGGER.log(Level.WARNING, "Skipping List [{0}] with unsupported base type [{1}]",
                            new Object[] { element.getTitle(), baseType });
                    continue;
                }
                MessageElement listMetadata = getListMetadata(element.getInternalName());
                if (listMetadata == null) {
                    LOGGER.log(Level.WARNING, "Unable to get metadata for List [{0}]. Skipping List",
                            element.getTitle());
                    continue;
                }
                String rootFolder = getMetadataAttributeForList(listMetadata, "RootFolder");
                if (Strings.isNullOrEmpty(rootFolder)) {
                    LOGGER.log(Level.WARNING, "Unable to get Root Folder for List [{0}]. Skipping List",
                            element.getTitle());
                    continue;
                }
                String defaultViewItemUrl = getMetadataAttributeForList(listMetadata, "DefaultViewItemUrl");
                if (Strings.isNullOrEmpty(defaultViewItemUrl)) {
                    LOGGER.log(Level.WARNING,
                            "Unable to get default View Item Url " + "for List [{0}]. Skipping List",
                            element.getTitle());
                    continue;
                }
                LOGGER.log(Level.FINE, "List [{0}] Root Folder [{1}] Default View Item URL [{2}]",
                        new Object[] { element.getTitle(), rootFolder, defaultViewItemUrl });
                String siteUrl = sharepointClientContext.getSiteURL();
                if (Strings.isNullOrEmpty(element.getDefaultViewUrl())) {
                    LOGGER.log(Level.WARNING,
                            "List [{0}] with empty default view URL." + " Using root folder for List URL.",
                            element.getTitle());
                    StringBuilder listUrl = new StringBuilder(siteUrl);
                    if (!siteUrl.endsWith("/")) {
                        listUrl.append("/");
                    }
                    listUrl.append(rootFolder);
                    url = listUrl.toString();
                } else {
                    url = Util.getWebApp(sharepointClientContext.getSiteURL()) + element.getDefaultViewUrl();
                }

                LOGGER.log(Level.INFO, "List url for List [{0}] is [{1}]",
                        new Object[] { element.getTitle(), url });

                strBaseTemplate = element.getBaseTemplate();
                if (strBaseTemplate == null) {
                    strBaseTemplate = SPConstants.NO_TEMPLATE;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SLIDELIBRARY)) {// for
                    // SlideLibrary
                    strBaseTemplate = SPConstants.BT_SLIDELIBRARY;
                } else if (collator.equals(strBaseTemplate,
                        SPConstants.ORIGINAL_BT_TRANSLATIONMANAGEMENTLIBRARY)) {// for
                    // TranslationManagementLibrary
                    strBaseTemplate = SPConstants.BT_TRANSLATIONMANAGEMENTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_TRANSLATOR)) {// for
                    // Translator
                    strBaseTemplate = SPConstants.BT_TRANSLATOR;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_REPORTLIBRARY)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_REPORTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_PROJECTTASK)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_PROJECTTASK;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SITESLIST)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_SITESLIST;
                } else {
                    // for FormLibrary
                    for (String formTemplate : sharepointClientContext.getInfoPathBaseTemplate()) {
                        if (collator.equals(strBaseTemplate, formTemplate)) {
                            strBaseTemplate = SPConstants.BT_FORMLIBRARY;
                            break;
                        }
                    }
                }

                LOGGER.config("List URL :" + url);

                // Children of all URLs are discovered
                ListState list = new ListState(element.getInternalName(), element.getTitle(),
                        element.getBaseType(), Util.siteDataStringToCalendar(element.getLastModified()),
                        strBaseTemplate, url, webstate);

                list.setInheritedSecurity(element.isInheritedSecurity());
                list.setApplyReadSecurity(element.getReadSecurity() == 2);

                String myNewListConst = "";
                LOGGER.log(Level.FINE, "getting listConst for list URL [{0}]", defaultViewItemUrl);
                if (defaultViewItemUrl != null) {
                    final StringTokenizer strTokList = new StringTokenizer(defaultViewItemUrl,
                            SPConstants.SLASH);
                    if (null != strTokList) {
                        while ((strTokList.hasMoreTokens()) && (strTokList.countTokens() > 1)) {
                            final String listToken = strTokList.nextToken();
                            if (list.isDocumentLibrary() && listToken.equals(SPConstants.FORMS_LIST_URL_SUFFIX)
                                    && (strTokList.countTokens() == 1)) {
                                break;
                            }
                            if (null != listToken) {
                                myNewListConst += listToken + SPConstants.SLASH;
                            }
                        }
                        list.setListConst(myNewListConst);
                        LOGGER.log(Level.CONFIG, "using listConst [ " + myNewListConst + " ] for list URL [ "
                                + defaultViewItemUrl + " ] ");

                        // Apply the URL filter here

                        // check if the entire list subtree is to excluded
                        // by comparing the prefix of the list URL with the
                        // patterns
                        if (sharepointClientContext
                                .isIncludedUrl(webstate.getWebUrl() + SPConstants.SLASH + myNewListConst)) {
                            // is included check if actual list url itself
                            // is to be excluded
                            if (sharepointClientContext.isIncludedUrl(url, LOGGER)) {
                                // if a List URL is included, it WILL be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(true);
                            } else {
                                // if a List URL is EXCLUDED, it will NOT be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(false);
                            }
                            // add the attribute(Metadata to the list )
                            list = getListWithAllAttributes(list, element);

                            listCollection.add(list);
                        } else {
                            // entire subtree is to be excluded
                            // do not construct list state
                            LOGGER.finest("Excluding " + url + " because entire subtree of " + myNewListConst
                                    + " is excluded");
                        }
                    }
                }

                // Sort the base list
                Collections.sort(listCollection);
            }
        }
    } catch (final Throwable e) {
        LOGGER.log(Level.FINER, e.getMessage(), e);
    }

    if (listCollection.size() > 0) {
        LOGGER.info("Discovered " + listCollection.size() + " lists/libraries under site [ " + webstate
                + " ] for crawling");
    } else {
        LOGGER.config("No lists/libraries to crawl under site [ " + webstate + " ]");
    }
    return listCollection;
}

From source file:com.google.enterprise.connector.sharepoint.wsclient.soap.SPSiteDataWS.java

/**
 * Gets the collection of all the lists on the sharepoint server which are of
 * a given type. E.g., DocumentLibrary// w  w  w . j av a  2  s.  c o m
 *
 * @param webstate The web from which the list/libraries are to be discovered
 * @return list of BaseList objects.
 */
public List<ListState> getNamedLists(final WebState webstate) throws SharepointException {
    final ArrayList<ListState> listCollection = new ArrayList<ListState>();
    if (stub == null) {
        LOGGER.warning("Unable to get the list collection because stub is null");
        return listCollection;
    }

    if (webstate == null) {
        LOGGER.warning("Unable to get the list collection because webstate is null");
        return listCollection;
    }

    final Collator collator = Util.getCollator();
    final ArrayOf_sListHolder vLists = new ArrayOf_sListHolder();
    final UnsignedIntHolder getListCollectionResult = new UnsignedIntHolder();

    try {
        stub.getListCollection(getListCollectionResult, vLists);
    } catch (final AxisFault af) { // Handling of username formats for
        // different authentication models.
        if ((SPConstants.UNAUTHORIZED.indexOf(af.getFaultString()) != -1)
                && (sharepointClientContext.getDomain() != null)) {
            final String username = Util.switchUserNameFormat(stub.getUsername());
            LOGGER.log(Level.CONFIG, "Web Service call failed for username [ " + stub.getUsername()
                    + " ]. Trying with " + username);
            stub.setUsername(username);
            try {
                stub.getListCollection(getListCollectionResult, vLists);
            } catch (final Exception e) {
                LOGGER.log(Level.WARNING, "Unable to get List Collection for stubURL[ "
                        + sharepointClientContext.getSiteURL() + " ].", e);
            }
        } else {
            LOGGER.log(Level.WARNING, "Unable to get List Collection for stubURL[ "
                    + sharepointClientContext.getSiteURL() + " ].", af);
        }
    } catch (final Throwable e) {
        LOGGER.log(Level.WARNING,
                "Unable to get List Collection for stubURL[ " + sharepointClientContext.getSiteURL() + " ].",
                e);
    }

    if (vLists == null) {
        LOGGER.log(Level.WARNING, "Unable to get the list collection");
        return listCollection;
    }

    try {
        final _sList[] sl = vLists.value;

        if (sl != null) {
            webstate.setExisting(true);
            for (_sList element : sl) {
                String url = null;
                String strBaseTemplate = null;

                if (element == null) {
                    continue;
                }

                final String baseType = element.getBaseType();
                LOGGER.log(Level.FINE, "Base Type returned by the Web Service : " + baseType);
                if (!collator.equals(baseType, (SPConstants.DISCUSSION_BOARD))
                        && !collator.equals(baseType, (SPConstants.DOC_LIB))
                        && !collator.equals(baseType, (SPConstants.GENERIC_LIST))
                        && !collator.equals(baseType, (SPConstants.ISSUE))
                        && !collator.equals(baseType, (SPConstants.SURVEYS))) {
                    continue;
                }

                url = Util.getWebApp(sharepointClientContext.getSiteURL()) + element.getDefaultViewUrl();

                strBaseTemplate = element.getBaseTemplate();
                if (strBaseTemplate == null) {
                    strBaseTemplate = SPConstants.NO_TEMPLATE;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SLIDELIBRARY)) {// for
                    // SlideLibrary
                    strBaseTemplate = SPConstants.BT_SLIDELIBRARY;
                } else if (collator.equals(strBaseTemplate,
                        SPConstants.ORIGINAL_BT_TRANSLATIONMANAGEMENTLIBRARY)) {// for
                    // TranslationManagementLibrary
                    strBaseTemplate = SPConstants.BT_TRANSLATIONMANAGEMENTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_TRANSLATOR)) {// for
                    // Translator
                    strBaseTemplate = SPConstants.BT_TRANSLATOR;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_REPORTLIBRARY)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_REPORTLIBRARY;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_PROJECTTASK)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_PROJECTTASK;
                } else if (collator.equals(strBaseTemplate, SPConstants.ORIGINAL_BT_SITESLIST)) {// for
                    // ReportLibrary
                    strBaseTemplate = SPConstants.BT_SITESLIST;
                } else {
                    // for FormLibrary
                    for (String formTemplate : sharepointClientContext.getInfoPathBaseTemplate()) {
                        if (collator.equals(strBaseTemplate, formTemplate)) {
                            strBaseTemplate = SPConstants.BT_FORMLIBRARY;
                            break;
                        }
                    }
                }

                LOGGER.config("List URL :" + url);

                // Children of all URLs are discovered
                ListState list = new ListState(element.getInternalName(), element.getTitle(),
                        element.getBaseType(), Util.siteDataStringToCalendar(element.getLastModified()),
                        strBaseTemplate, url, webstate);

                list.setInheritedSecurity(element.isInheritedSecurity());
                list.setApplyReadSecurity(element.getReadSecurity() == 2);

                String myNewListConst = "";
                final String listUrl = element.getDefaultViewUrl();// e.g.
                // /sites/abc/Lists/Announcements/AllItems.aspx
                LOGGER.log(Level.FINE, "getting listConst for list URL [ " + listUrl + " ] ");
                if ((listUrl != null) /* && (siteRelativeUrl!=null) */) {
                    final StringTokenizer strTokList = new StringTokenizer(listUrl, SPConstants.SLASH);
                    if (null != strTokList) {
                        while ((strTokList.hasMoreTokens()) && (strTokList.countTokens() > 1)) {
                            final String listToken = strTokList.nextToken();
                            if (list.isDocumentLibrary() && listToken.equals(SPConstants.FORMS_LIST_URL_SUFFIX)
                                    && (strTokList.countTokens() == 1)) {
                                break;
                            }
                            if (null != listToken) {
                                myNewListConst += listToken + SPConstants.SLASH;
                            }
                        }
                        list.setListConst(myNewListConst);
                        LOGGER.log(Level.CONFIG,
                                "using listConst [ " + myNewListConst + " ] for list URL [ " + listUrl + " ] ");

                        // Apply the URL filter here

                        // check if the entire list subtree is to excluded
                        // by comparing the prefix of the list URL with the
                        // patterns
                        if (sharepointClientContext
                                .isIncludedUrl(webstate.getWebUrl() + SPConstants.SLASH + myNewListConst)) {
                            // is included check if actual list url itself
                            // is to be excluded
                            if (sharepointClientContext.isIncludedUrl(url)) {
                                // if a List URL is included, it WILL be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(true);
                            } else {
                                // if a List URL is EXCLUDED, it will NOT be
                                // sent as a
                                // Document
                                list.setSendListAsDocument(false);
                                LOGGER.warning("excluding " + url.toString());
                            }
                            // add the attribute(Metadata to the list )
                            list = getListWithAllAttributes(list, element);

                            listCollection.add(list);
                        } else {
                            // entire subtree is to be excluded
                            // do not construct list state
                            LOGGER.warning("Excluding " + url + " because entire subtree of " + myNewListConst
                                    + " is excluded");
                        }
                    }
                }

                // Sort the base list
                Collections.sort(listCollection);
                // dumpcollection(listCollection);
            }
        }
    } catch (final Throwable e) {
        LOGGER.log(Level.FINER, e.getMessage(), e);
        return listCollection;
    }

    if (listCollection.size() > 0) {
        LOGGER.info("Discovered " + listCollection.size() + " lists/libraries under site [ " + webstate
                + " ] for crawling");
    } else {
        LOGGER.config("No lists/libraries to crawl under site [ " + webstate + " ]");
    }
    return listCollection;
}

From source file:com.funambol.foundation.admin.FileSystemSyncSourceConfigPanel.java

/**
 * Set syncSource properties with the values provided by the user.
 *///from  w w  w  .j  a  v  a2  s .  c o m
private void getValues() {
    FileSystemSyncSource syncSource = (FileSystemSyncSource) getSyncSource();

    StringTokenizer types = new StringTokenizer(infoTypesValue.getText(), ",");
    StringTokenizer versions = new StringTokenizer(infoVersionsValue.getText(), ",");

    syncSource.setSourceURI(sourceUriValue.getText().trim());
    syncSource.setName(nameValue.getText().trim());
    syncSource.setSourceDirectory(directoryValue.getText().trim());

    syncSource.setEncode(false);

    syncSource.setMultiUser(multiUserValue.isSelected());

    ContentType[] contentTypes = new ContentType[types.countTokens()];

    for (int i = 0; i < contentTypes.length; ++i) {
        contentTypes[i] = new ContentType(types.nextToken().trim(), versions.nextToken().trim());
    }

    syncSource.setInfo(new SyncSourceInfo(contentTypes, 0));
}

From source file:fr.univlr.cri.planning.factory.HugICalendarFactory.java

public boolean createFileICalendar(String res, String cheminEtNom) {
    boolean statut = false;

    CktlLog.trace("trying creating .ics file : [" + cheminEtNom + "]");

    // tester si chemin classic ou WebDav
    if (cheminEtNom != null) {
        if (!cheminEtNom.endsWith(LocalSPConstantes.ICS_FILE_NAME_EXTENSION))
            cheminEtNom += LocalSPConstantes.ICS_FILE_NAME_EXTENSION;

        String url = ((CktlWebApplication) CktlWebApplication.application()).config()
                .stringForKey(LocalSPConstantes.KEY_ICAL_CHEMIN);

        if (cheminEtNom.startsWith(url)) {
            // url webdav
            // pour trouver chemin
            String chemin = "http://";
            StringTokenizer st = new StringTokenizer(cheminEtNom.substring(7), "/");
            int nb = st.countTokens();
            for (int i = 0; i < nb - 1; i++) {
                chemin += st.nextToken() + "/";
            }// www .  j av a2  s . c  om

            String log = ((CktlWebApplication) CktlWebApplication.application()).config()
                    .stringForKey(LocalSPConstantes.KEY_ICAL_LOG);
            String pwd = ((CktlWebApplication) CktlWebApplication.application()).config()
                    .stringForKey(LocalSPConstantes.KEY_ICAL_PWD);

            try {
                WebdavResource webd = new WebdavResource(chemin, new UsernamePasswordCredentials(log, pwd));
                // cration et criture du fichier
                webd.putMethod(cheminEtNom, res);
                statut = true;
            } catch (Exception e) {
                CktlLog.trace("WebDAV encountered problems while creating .ics file ...");
            }

        } else if (cheminEtNom.startsWith("http")) {
            CktlLog.trace("problems creating .ics file [" + cheminEtNom
                    + "], path must be WebDAV server or local file.");
        } else {
            // chemin local
            File f = new File(cheminEtNom);
            try {
                FileOutputStream stream = new FileOutputStream(f);
                byte[] bits = res.getBytes();
                stream.write(bits);
                statut = true;
                stream.close();
            } catch (FileNotFoundException e) {
                CktlLog.trace("problem while creating local .ics file : FileNotFoundException");
            } catch (IOException io) {
                CktlLog.trace("problem while writing local .ics file : IOException");
            }
        }
    }

    if (statut)
        CktlLog.trace("creation successfull !");
    else
        CktlLog.trace("creation failed !");

    return statut;
}

From source file:com.joptimizer.util.MPSParser.java

public void parse(BufferedReader in) throws Exception {
    long t0 = System.currentTimeMillis();
    Map<String, Integer> rowsIndexMap = new HashMap<String, Integer>();//the name of the rows and its 1-based index (<0 for eq, >0 for ineq)
    Map<String, String> rowsTypeMap = new HashMap<String, String>();//the name of the rows and its type (objective|equals|less then|greater then)
    List<String> columnList = new ArrayList<String>();
    List<String> rhsList = new ArrayList<String>();
    List<String> boundsList = new ArrayList<String>();
    String previousColumnName = "NOT_YET_SET";
    columnsIndexMap = new LinkedHashMap<String, Integer>();//the name of the columns and its index

    //read the file and set the problem dimensions
    try {// w  w w  .  jav a  2s .com
        String line = new String();
        int lineNumber = 0;
        while ((line = in.readLine()) != null) {
            lineNumber++;
            line = line.trim();
            if (log.isDebugEnabled()) {
                //log.debug("line "+lineNumber+": "+line);
            }
            if (line.startsWith("#") || line.startsWith("*")) {
                //this is a commented line
                continue;
            }

            if ("".equals(line.trim())) {
                //this is an empty line
                continue;
            }

            if (line.startsWith(NAME)) {
                section = SECTION_NAME;
            } else if (line.startsWith(QSECTION)) {
                log.error("Quadratic problems parsing not supported");
                throw new RuntimeException("Quadratic problems parsing not supported");
            } else if (line.startsWith(ROWS)) {
                section = SECTION_ROWS;
                continue;
            } else if (line.startsWith(COLUMNS)) {
                section = SECTION_COLUMNS;
                continue;
            } else if (line.startsWith(RHS)) {
                if (section != SECTION_RHS) {
                    //the line of this section has again this starting string
                    section = SECTION_RHS;
                    continue;
                }
            } else if (line.startsWith(RANGES)) {
                log.error("Ranges are not supported");
                throw new RuntimeException("Ranges are not supported");
            } else if (line.startsWith(BOUNDS)) {
                section = SECTION_BOUNDS;
                continue;
            } else if (line.startsWith(ENDATA)) {
                break;
            }

            switch (section) {
            case SECTION_NAME:
                name = line.substring(4).trim();
                log.info("name: " + name);
                break;
            case SECTION_ROWS:
                String rowType = line.substring(0, 1);
                String rowName = line.substring(1).trim();
                if (rowType.equalsIgnoreCase(EQUAL)) {
                    meq++;
                    rowsIndexMap.put(rowName, -meq);
                    rowsTypeMap.put(rowName, EQUAL);
                } else if (rowType.equalsIgnoreCase(LESS_THEN)) {
                    mieq++;
                    rowsIndexMap.put(rowName, mieq);
                    rowsTypeMap.put(rowName, LESS_THEN);
                } else if (rowType.equalsIgnoreCase(GREATER_THEN)) {
                    mieq++;
                    rowsIndexMap.put(rowName, mieq);
                    rowsTypeMap.put(rowName, GREATER_THEN);
                } else if (rowType.equalsIgnoreCase(OBJECTIVE)) {
                    rowsTypeMap.put(rowName, OBJECTIVE);
                }

                break;
            case SECTION_COLUMNS:
                String columnName = line.substring(0, line.indexOf(" "));
                if (!previousColumnName.equalsIgnoreCase(columnName)) {
                    n++;
                    previousColumnName = columnName;
                }
                columnList.add(columnList.size(), line);
                break;
            case SECTION_RHS:
                rhsList.add(rhsList.size(), line);
                break;
            case SECTION_BOUNDS:
                boundsList.add(boundsList.size(), line);
                break;
            }

        }
        in.close();

        //define vectors and matrices
        c = F1.make(n);
        //A = new double[meq][n];
        A = (useSparsity) ? new SparseDoubleMatrix2D(meq, n) : F2.make(meq, n);
        b = F1.make(meq);
        //G = new double[mieq][n];
        G = (useSparsity) ? new SparseDoubleMatrix2D(mieq, n) : F2.make(mieq, n);
        h = F1.make(mieq);
        lb = F1.make(n, unspecifiedLBValue);
        ub = F1.make(n, unspecifiedUBValue);
        //Arrays.fill(lb, unspecifiedLBValue);
        //Arrays.fill(ub, unspecifiedUBValue);

        //look into the lines
        previousColumnName = "NOT_YET_SET";
        int colIndex = -1;
        for (int i = 0; i < columnList.size(); i++) {
            String myline = columnList.get(i);
            StringTokenizer cst = new StringTokenizer(myline, " ");
            int cmax = cst.countTokens();
            String rowType = null;
            for (int j = 0; j < cmax; j++) {
                String v = cst.nextToken().trim();
                switch (j) {
                case 0:
                    //v is the column (or variable) name
                    if (!previousColumnName.equalsIgnoreCase(v)) {
                        colIndex++;
                        columnsIndexMap.put(v, colIndex);
                        previousColumnName = v;
                    }
                    break;
                case 1:
                    //v is the constraint name
                    rowType = rowsTypeMap.get(v);
                    double d1 = new Double(cst.nextToken());
                    if (rowType.equalsIgnoreCase(EQUAL)) {
                        int rowIndex = -rowsIndexMap.get(v);
                        A.setQuick(rowIndex - 1, colIndex, d1);
                        nzA++;
                    } else if (rowType.equalsIgnoreCase(LESS_THEN)) {
                        int rowIndex = rowsIndexMap.get(v);
                        G.setQuick(rowIndex - 1, colIndex, d1);
                        nzG++;
                    } else if (rowType.equalsIgnoreCase(GREATER_THEN)) {
                        int rowIndex = rowsIndexMap.get(v);
                        G.setQuick(rowIndex - 1, colIndex, -d1);
                        nzG++;
                    } else if (rowType.equalsIgnoreCase(OBJECTIVE)) {
                        c.setQuick(colIndex, d1);
                    }
                    j++;
                    break;
                case 3:
                    //v is the constraint name
                    rowType = rowsTypeMap.get(v);
                    double d2 = new Double(cst.nextToken());
                    if (rowType.equalsIgnoreCase(EQUAL)) {
                        int rowIndex = -rowsIndexMap.get(v);
                        A.setQuick(rowIndex - 1, colIndex, d2);
                        nzA++;
                    } else if (rowType.equalsIgnoreCase(LESS_THEN)) {
                        int rowIndex = rowsIndexMap.get(v);
                        G.setQuick(rowIndex - 1, colIndex, d2);
                        nzG++;
                    } else if (rowType.equalsIgnoreCase(GREATER_THEN)) {
                        int rowIndex = rowsIndexMap.get(v);
                        G.setQuick(rowIndex - 1, colIndex, -d2);
                        nzG++;
                    } else if (rowType.equalsIgnoreCase(OBJECTIVE)) {
                        c.setQuick(colIndex, d2);
                    }
                    j++;
                    break;
                }
            }
        }
        for (int i = 0; i < rhsList.size(); i++) {
            String myline = rhsList.get(i);
            StringTokenizer rst = new StringTokenizer(myline, " ");
            int rmax = rst.countTokens();
            if (rmax == 5 || rmax == 3) {
                rst.nextToken();//it is the RHS name
                rmax--;
            }
            for (int j = 0; j < rmax; j++) {
                String v = rst.nextToken().trim();
                switch (j) {
                case 0:
                    //v is the constraint name
                    Double d1 = new Double(rst.nextToken());
                    Integer indexObj = rowsIndexMap.get(v);
                    if (indexObj == null) {
                        log.warn("unknown constraint " + v);
                        j = rmax;
                        break;
                    }
                    int rowIndex = indexObj.intValue();
                    String rowType = rowsTypeMap.get(v);
                    if (rowIndex < 0) {
                        //equality
                        b.setQuick(-rowIndex - 1, d1);
                    } else {
                        //inequality
                        if (LESS_THEN.equals(rowType)) {
                            h.setQuick(rowIndex - 1, d1);
                        } else if (GREATER_THEN.equals(rowType)) {
                            h.setQuick(rowIndex - 1, -d1);
                        }
                    }
                    j++;
                    break;
                case 2:
                    //v is the constraint name
                    double d2 = new Double(rst.nextToken());
                    int rowIndex2 = rowsIndexMap.get(v);
                    String rowType2 = rowsTypeMap.get(v);
                    if (rowIndex2 < 0) {
                        //equality
                        b.setQuick(-rowIndex2 - 1, d2);
                    } else {
                        //inequality
                        if (LESS_THEN.equals(rowType2)) {
                            h.setQuick(rowIndex2 - 1, d2);
                        } else if (GREATER_THEN.equals(rowType2)) {
                            h.setQuick(rowIndex2 - 1, -d2);
                        }

                    }
                    j++;
                    break;
                }
            }
        }
        for (int i = 0; i < boundsList.size(); i++) {
            String myline = boundsList.get(i);
            StringTokenizer bst = new StringTokenizer(myline, " ");
            int nOfTokens = bst.countTokens();
            String[] tokens = new String[nOfTokens];
            for (int j = 0; j < nOfTokens; j++) {
                tokens[j] = bst.nextToken().trim();
            }
            String type = tokens[0];
            if (LOWER_BOUND.equals(type)) {
                String columnName = (nOfTokens > 3) ? tokens[2] : tokens[1];
                int columnIndex = columnsIndexMap.get(columnName);
                lb.setQuick(columnIndex, new Double(tokens[nOfTokens - 1]).doubleValue());
            } else if (UPPER_BOUND.equals(type)) {
                String columnName = (nOfTokens > 3) ? tokens[2] : tokens[1];
                int columnIndex = columnsIndexMap.get(columnName);
                ub.setQuick(columnIndex, new Double(tokens[nOfTokens - 1]).doubleValue());
            } else if (FX_BOUND.equals(type)) {
                //not-ignorable bound:  b<x<b
                String columnName = (nOfTokens > 3) ? tokens[2] : tokens[1];
                int columnIndex = columnsIndexMap.get(columnName);
                lb.setQuick(columnIndex, new Double(tokens[nOfTokens - 1]).doubleValue());
                ub.setQuick(columnIndex, new Double(tokens[nOfTokens - 1]).doubleValue());
            } else if (FR_BOUND.equals(type)) {
                //ignorable bound:  -oo<x<+oo
                String columnName = tokens[2];
                int columnIndex = columnsIndexMap.get(columnName);
                lb.setQuick(columnIndex, unboundedLBValue);
                ub.setQuick(columnIndex, unboundedUBValue);
            } else if (MI_BOUND.equals(type)) {
                //infinite lower bound   -oo < x (<= 0)
                String columnName = tokens[2];
                int columnIndex = columnsIndexMap.get(columnName);
                lb.setQuick(columnIndex, unboundedLBValue);
                ub.setQuick(columnIndex, 0);
            } else if (PL_BOUND.equals(type)) {
                //infinite lower bound  (0 <=) x < +oo
                String columnName = tokens[2];
                int columnIndex = columnsIndexMap.get(columnName);
                lb.setQuick(columnIndex, 0);
                ub.setQuick(columnIndex, unboundedUBValue);
            } else {
                log.warn("unknown bound type: " + type);
            }
        }

        //log.debug("Variables: " + columnsIndexMap.keySet());

    } catch (Exception e) {
        log.error("Exception", e);
        throw e;
    }
    log.info("parsing time: " + (System.currentTimeMillis() - t0) + " ms");
}

From source file:com.glaf.base.modules.sys.service.mybatis.SysTreeServiceImpl.java

public void loadSysTrees(List<SysTree> treeList, long parentId, int deep) {
    logger.debug("--------------loadSysTrees---------------");
    SysTree root = this.findById(parentId);
    if (root != null) {
        if (StringUtils.isNotEmpty(root.getTreeId())) {
            SysTreeQuery query = new SysTreeQuery();
            query.treeIdLike(root.getTreeId() + "%");
            query.setOrderBy(" E.TREEID asc ");
            List<SysTree> nodes = this.list(query);
            if (nodes != null && !nodes.isEmpty()) {
                this.initDepartments(nodes);
                this.initApplications(nodes);
                Iterator<SysTree> iter = nodes.iterator();
                while (iter.hasNext()) {
                    SysTree bean = iter.next();
                    if (bean.getId() != parentId) {
                        String treeId = bean.getTreeId();
                        String tmp = treeId.substring(root.getTreeId().length(), treeId.length());
                        StringTokenizer token = new StringTokenizer(tmp, "|");
                        bean.setDeep(token.countTokens());
                        treeList.add(bean);// 
                        logger.debug("dept level:" + bean.getDeep());
                    }//from  ww  w .  j a  v a 2 s  .  com
                }
            }
        } else {
            SysTreeQuery query = new SysTreeQuery();
            query.setParentId(Long.valueOf(parentId));
            List<SysTree> nodes = this.list(query);
            if (nodes != null && !nodes.isEmpty()) {
                this.initDepartments(nodes);
                this.initApplications(nodes);
                Iterator<SysTree> iter = nodes.iterator();
                while (iter.hasNext()) {
                    SysTree bean = iter.next();
                    bean.setDeep(deep + 1);
                    treeList.add(bean);// 
                    loadSysTrees(treeList, bean.getId(), bean.getDeep());// ??
                }
            }
        }
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchTagFrame.java

private void copyVillageAsBBCode() {
    List villageSelection = jVillageList.getSelectedValuesList();
    if (villageSelection == null || villageSelection.isEmpty()) {
        showInfo("Keine Drfer ausgewhlt");
        return;/*from   ww w  .ja  va2  s  .  c o m*/
    }
    try {
        List<Village> villages = new LinkedList<>();
        for (Object o : villageSelection) {
            villages.add((Village) o);
        }
        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
                "Nein", "Ja") == JOptionPane.YES_OPTION);

        StringBuilder buffer = new StringBuilder();
        if (extended) {
            buffer.append("[u][size=12]Dorfliste[/size][/u]\n\n");
        } else {
            buffer.append("[u]Dorfliste[/u]\n\n");
        }
        buffer.append(new VillageListFormatter().formatElements(villages, extended));

        if (extended) {
            buffer.append("\n[size=8]Erstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n");
        } else {
            buffer.append("\nErstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n");
        }

        String b = buffer.toString();
        StringTokenizer t = new StringTokenizer(b, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die ausgewhlten Drfer bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null);
        String result = "Drfer in Zwischenablage kopiert.";
        showSuccess(result);
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        String result = "Fehler beim Kopieren in die Zwischenablage.";
        showError(result);
    }
}