Example usage for org.apache.commons.lang3 StringUtils join

List of usage examples for org.apache.commons.lang3 StringUtils join

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils join.

Prototype

public static String join(final Iterable<?> iterable, final String separator) 

Source Link

Document

Joins the elements of the provided Iterable into a single String containing the provided elements.

No delimiter is added before or after the list.

Usage

From source file:annis.gui.servlets.ResourceServlet.java

@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    OutputStream outStream = response.getOutputStream();

    String completePath = request.getPathInfo();

    if (completePath == null) {
        response.sendError(404, "must provide a valid and existing path with a vistype");
        return;//ww w.  j  av a2s  .  co  m
    }

    // remove trailing /
    completePath = completePath.substring(1);

    String[] pathComponents = completePath.split("/");

    String vistype = pathComponents[0];

    if (pathComponents.length < 2) {
        response.sendError(404, "must provide a valid and existing path");
        return;
    }

    String path = StringUtils.join(Arrays.copyOfRange(pathComponents, 1, pathComponents.length), "/");

    // get the visualizer for this vistype
    ResourcePlugin vis = resourceRegistry.get(vistype);
    if (vis == null) {
        response.sendError(500, "There is no resource with the short name " + vistype);
    } else if (path.endsWith(".class")) {
        response.sendError(403, "illegal class path access");
    } else {
        URL resource = vis.getClass().getResource(path);
        if (resource == null) {
            response.sendError(404, path + " not found");
        } else {
            // check if it is new
            URLConnection resourceConnection = resource.openConnection();
            long resourceLastModified = resourceConnection.getLastModified();
            long requestLastModified = request.getDateHeader("If-Modified-Since");
            if (requestLastModified != -1 && resourceLastModified <= requestLastModified) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            } else {
                response.addDateHeader("Last-Modified", resourceLastModified);
                if ("localhost".equals(request.getServerName())) {
                    // does always expire right now
                    response.addDateHeader("Expires", new Date().getTime());
                } else {
                    // expires in one minute per default
                    response.addDateHeader("Expires", new Date().getTime() + 60000);
                }
                // not in cache, stream out
                String mimeType = getServletContext().getMimeType(path);
                response.setContentType(mimeType);
                if (mimeType.startsWith("text/")) {
                    response.setCharacterEncoding("UTF-8");
                }
                OutputStream bufferedOut = new BufferedOutputStream(outStream);
                InputStream resourceInStream = new BufferedInputStream(resource.openStream());

                try {
                    int v = -1;
                    while ((v = resourceInStream.read()) != -1) {
                        bufferedOut.write(v);
                    }
                } finally {
                    resourceInStream.close();
                    bufferedOut.flush();
                    outStream.flush();
                }
            }
        }
    }

}

From source file:de.uni.bremen.monty.moco.codegeneration.types.LLVMFunctionType.java

@Override
public String toString() {
    return returnType.toString() + " ( " + StringUtils.join(parameter, ",") + " )";
}

From source file:io.bibleget.BibleGetSelection.java

public void getQuoteFromSelection() {
    List<String> preferredVersions = new ArrayList<>();
    Object retVal = biblegetDB.getOption("PREFERREDVERSIONS");
    if (null == retVal) {
    } else {//from   w ww  .ja  va 2  s  .  c om
        String[] favoriteVersions = StringUtils.split((String) retVal, ',');
        preferredVersions = Arrays.asList(favoriteVersions);
    }

    if (preferredVersions.isEmpty()) {
        preferredVersions.add("NVBSE");
    }

    String versions = StringUtils.join(preferredVersions.toArray(), ',');

    Object m_xCurSel;
    try {
        m_xCurSel = m_xTextDocument.getCurrentSelection();
        if (m_xCurSel != null) {
            //there is a selection, we can do something with it
            XIndexAccess xIndex = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, m_xCurSel);
            Object Sel0;
            try {
                Sel0 = xIndex.getByIndex(0);
                XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, Sel0);
                String myInputContent = xTextRange.getString();
                myInputContent = StringUtils.deleteWhitespace(myInputContent);
                //System.out.println("You typed : "+myInputContent);
                if (myInputContent.isEmpty() == false) {

                    HTTPCaller myHTTPCaller = new HTTPCaller();
                    String myResponse;
                    try {
                        Boolean querycheck = myHTTPCaller.integrityCheck(myInputContent, preferredVersions);
                        if (querycheck) {
                            //JOptionPane.showMessageDialog(null, "All is proceeding nicely", "progress info", JOptionPane.INFORMATION_MESSAGE);
                            myResponse = myHTTPCaller.sendGet(myInputContent, versions);
                            if (myResponse != null) {
                                xTextRange.setString("");
                                BibleGetJSON myJSON = new BibleGetJSON(m_xController);
                                myJSON.JSONParse(myResponse);
                            } else {
                                JOptionPane.showMessageDialog(null, __(
                                        "There was a problem communicating with the BibleGet server. Please try again."),
                                        "ERROR >> SERVER CONNECTIVITY ISSUE", JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            String[] errorMessages = myHTTPCaller.getErrorMessages();
                            String errorDialog = StringUtils.join(errorMessages, "\n\n");
                            JOptionPane.showMessageDialog(null, errorDialog, "ERROR >> MALFORMED QUERYSTRING",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    } catch (HeadlessException | ClassNotFoundException | UnknownPropertyException
                            | PropertyVetoException | com.sun.star.lang.IllegalArgumentException
                            | WrappedTargetException ex) {
                        Logger.getLogger(BibleGetFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    JOptionPane.showMessageDialog(null, __("You cannot send an empty query."),
                            "ERROR >> EMPTY SELECTION", JOptionPane.ERROR_MESSAGE);
                }

            } catch (IndexOutOfBoundsException | WrappedTargetException ex) {
                Logger.getLogger(BibleGetSelection.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(BibleGetSelection.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:exm.stc.ic.ICUtil.java

/**
 * Print multiple as one list/*  ww  w  .j  a  v a 2 s  .  co  m*/
 * @param sb
 * @param values
 */
@SuppressWarnings("rawtypes")
public static void prettyPrintLists(StringBuilder sb, Collection<? extends Collection> values) {
    sb.append(StringUtils.join(values, ", "));
}

From source file:com.vrem.wifianalyzer.wifi.channelavailable.ChannelAvailableAdapter.java

@NonNull
@Override/* ww  w .j a  v  a2  s .  c  o  m*/
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater layoutInflater = MainContext.INSTANCE.getMainActivity().getLayoutInflater();
        view = layoutInflater.inflate(R.layout.channel_available_details, parent, false);
    }

    WiFiChannelCountry wiFiChannelCountry = getItem(position);
    ((TextView) view.findViewById(R.id.channel_available_country))
            .setText(wiFiChannelCountry.getCountryCode() + " - " + wiFiChannelCountry.getCountryName());
    ((TextView) view.findViewById(R.id.channel_available_title_ghz_2)).setText(String.format(Locale.ENGLISH,
            "%s : ", view.getResources().getString(WiFiBand.GHZ2.getTextResource())));
    ((TextView) view.findViewById(R.id.channel_available_ghz_2))
            .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ2().toArray(), ","));
    ((TextView) view.findViewById(R.id.channel_available_title_ghz_5)).setText(String.format(Locale.ENGLISH,
            "%s : ", view.getResources().getString(WiFiBand.GHZ5.getTextResource())));
    ((TextView) view.findViewById(R.id.channel_available_ghz_5))
            .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ5().toArray(), ","));
    return view;
}

From source file:demo.jaxrs.search.server.Server.java

protected Server() throws Exception {
    org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000);

    // Configuring all static web resource
    final ServletHolder staticHolder = new ServletHolder(new DefaultServlet());
    // Register and map the dispatcher servlet
    final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addServlet(staticHolder, "/static/*");
    context.addServlet(servletHolder, "/*");
    context.setResourceBase(getClass().getResource("/browser").toURI().toString());

    servletHolder.setInitParameter("redirects-list",
            "/ /index.html /js/fileinput.min.js /css/fileinput.min.css");
    servletHolder.setInitParameter("redirect-servlet-name", staticHolder.getName());
    servletHolder.setInitParameter("redirect-attributes", "javax.servlet.include.request_uri");
    servletHolder.setInitParameter("jaxrs.serviceClasses", Catalog.class.getName());
    servletHolder.setInitParameter("jaxrs.properties", StringUtils.join(new String[] {
            "search.query.parameter.name=$filter", SearchUtils.DATE_FORMAT_PROPERTY + "=yyyy/MM/dd" }, " "));
    servletHolder.setInitParameter("jaxrs.providers",
            StringUtils.join(new String[] { MultipartProvider.class.getName(),
                    SearchContextProvider.class.getName(), JsrJsonpProvider.class.getName(),
                    CrossOriginResourceSharingFilter.class.getName() }, ","));

    server.setHandler(context);/*from  w  w w.  j a  va  2 s  .c o  m*/
    server.start();
    server.join();
}

From source file:com.thoughtworks.go.util.command.ConsoleResult.java

public String outputForDisplayAsString() {
    return StringUtils.join(outputForDisplay(), "\n");
}

From source file:com.norconex.commons.wicket.markup.html.chart.jqplot.PlotPanel.java

public PlotPanel(String id, PlotData plotData, boolean minified) {
    super(id);//from  www.java 2 s.c  o m
    setOutputMarkupId(true);

    WebMarkupContainer plotDiv = new WebMarkupContainer("plot");
    plotDiv.setOutputMarkupId(true);
    add(plotDiv);
    String plotId = plotDiv.getMarkupId();

    //XXX hack to get minified version should be done better
    if (minified) {
        AxisOptions xaxis = plotData.getOptions().getAxes().getXaxis();
        Integer val = xaxis.getNumberTicks();
        int numberTicks = 0;
        if (val != null) {
            numberTicks = val;
        }
        if (numberTicks > 0) {
            numberTicks = (int) Math.ceil((float) numberTicks / 2f);
        }
        xaxis.setNumberTicks(numberTicks);
    }

    String code = "";
    if (plotData != null) {
        //--- Options ---
        String options = "{}";
        if (plotData.getOptions() != null) {
            options = plotData.getOptions().toString();
        }
        //--- Series ---
        String series = "[]";
        if (plotData.getSeries() != null) {
            series = "[" + StringUtils.join(plotData.getSeries(), ", ") + "]";
        }
        //--- pre/post JS ---
        String preJs = plotData.getPreJavascript();
        if (preJs == null) {
            preJs = StringUtils.EMPTY;
        }
        String postJs = plotData.getPostJavascript();
        if (postJs == null) {
            postJs = StringUtils.EMPTY;
        }

        //--- Plot Code ---
        code = "$(document).ready(function(){" + preJs + "  $.jqplot.config.enablePlugins = true;"
                + "  var plot = $.jqplot('" + plotId + "', " + series + ", " + options + ");"
                + "  $(window).resize(function() {" + "    if (plot) { "
                + "      $.each(plot.series, function(index, series) {" + "        series.barWidth = undefined;"
                + "      });" + "      plot.replot();" + "    }" + "  });" + postJs + "});";
    }
    Label script = new Label("script", code);
    script.setEscapeModelStrings(false);
    addOrReplace(script);
}

From source file:com.synopsys.integration.test.tool.TestLogger.java

public String getErrorOutputString() {
    if (errorList == null || errorList.isEmpty()) {
        return "";
    }//w w w.  j  a v a  2 s  .c  o  m

    final List<String> stackTraces = new ArrayList<>();
    for (final Throwable e : errorList) {
        final StringWriter stringWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(stringWriter));
        stackTraces.add(stringWriter.toString());
    }

    return StringUtils.join(stackTraces, System.lineSeparator());
}