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

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

Introduction

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

Prototype

public static String substringBetween(final String str, final String open, final String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:com.thinkbiganalytics.util.PartitionKey.java

/**
 * if column in formula has a space, surround it with a tick mark
 *///from w w  w.  j a  v  a2  s . co m
private void surroundFormulaColumnWithTick() {
    int idx = formula.indexOf("(");
    String column = StringUtils.substringBetween(formula, "(", ")");
    if (StringUtils.isNotBlank(column) && column.charAt(0) != '`') {
        column = HiveUtils.quoteIdentifier(column);
        StringBuffer sb = new StringBuffer();
        sb.append(StringUtils.substringBefore(formula, "(")).append("(").append(column).append(")");
        formula = sb.toString();
    }

}

From source file:com.ln.gui.Notifylist.java

@SuppressWarnings("unchecked")
public Notifylist() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setResizable(false);//from  ww  w. ja  v  a 2 s  .c o m
    setIconImage(Toolkit.getDefaultToolkit().getImage(Configuration.mydir + "\\resources\\icons\\ln6464.png"));
    setTitle("Event list");
    DateFormat dd = new SimpleDateFormat("dd");
    DateFormat dh = new SimpleDateFormat("HH");
    DateFormat dm = new SimpleDateFormat("mm");
    Date day = new Date();
    Date hour = new Date();
    Date minute = new Date();
    int dayd = Integer.parseInt(dd.format(day));
    int hourh = Integer.parseInt(dh.format(hour));
    int minutem = Integer.parseInt(dm.format(minute));

    int daydiff = dayd - Main.dayd;
    int hourdiff = hourh - Main.hourh;
    int mindiff = minutem - Main.minutem;

    model.clear();
    Events = new String[Main.events];
    Events2 = new String[Main.events];
    //      Events = Main.Eventlist;
    for (int i = 0; i != Main.events; i++) {
        Events[i] = Main.Eventlist[i];
    }
    for (int i = 0; i != Main.events; i++) {
        Events2[i] = Main.Eventlist[i];
    }
    for (int i = 0; i != Events2.length; i++) {
        if (Events2[i] != null) {
            Events2[i] = Main.Eventlist[i];
            Events2[i] = Events2[i].replace(StringUtils.substringBetween(Events2[i], "in: ", " Days"), Integer
                    .toString(Integer.parseInt(StringUtils.substringBetween(Events2[i], "in: ", " Days"))));
            Events2[i] = Events2[i].replace(StringUtils.substringBetween(Events2[i], "Days ", " Hours"), Integer
                    .toString(Integer.parseInt(StringUtils.substringBetween(Events2[i], "Days ", " Hours"))));
            Events2[i] = Events2[i].replace(StringUtils.substringBetween(Events2[i], "Hours ", " Minutes"),
                    Integer.toString(
                            Integer.parseInt(StringUtils.substringBetween(Events2[i], "Hours ", " Minutes"))));

        }
        if (Events[i] != null) {
            Events[i] = Main.Eventlist[i];
            Events[i] = Events[i].replace(StringUtils.substringBetween(Events[i], "in: ", " Days"),
                    Integer.toString(Integer.parseInt(StringUtils.substringBetween(Events[i], "in: ", " Days"))
                            - daydiff));
            Events[i] = Events[i].replace(StringUtils.substringBetween(Events[i], "Days ", " Hours"),
                    Integer.toString(
                            Integer.parseInt(StringUtils.substringBetween(Events[i], "Days ", " Hours"))
                                    - hourdiff));
            Events[i] = Events[i].replace(StringUtils.substringBetween(Events[i], "Hours ", " Minutes"),
                    Integer.toString(
                            Integer.parseInt(StringUtils.substringBetween(Events[i], "Hours ", " Minutes"))
                                    - mindiff));
            //Arrays.sort(Events);
            model.add(i, Events[i]);

        }
    }
    setBounds(100, 100, 671, 331);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
    JButton Remove = new JButton("Remove selected");
    Remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (list.getSelectedIndices().length > 0) {
                int[] tmp = list.getSelectedIndices();
                Main.events = Main.events - tmp.length;
                int[] selectedIndices = list.getSelectedIndices();
                for (int i = tmp.length - 1; i >= 0; i--) {
                    selectedIndices = list.getSelectedIndices();
                    model.removeElementAt(selectedIndices[i]);
                    Events = ArrayUtils.remove(Events, selectedIndices[i]);
                    Events2 = ArrayUtils.remove(Events2, selectedIndices[i]);
                    Main.Eventlist = ArrayUtils.remove(Main.Eventlist, selectedIndices[i]);
                    //http://i.imgur.com/lN2Fe.jpg
                }
            }
        }
    });
    Remove.setBounds(382, 258, 130, 25);
    contentPane.add(Remove);
    JButton btnClose = new JButton("Close");
    btnClose.setBounds(522, 258, 130, 25);
    contentPane.add(btnClose);
    btnClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    try {
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(10, 11, 642, 236);
        contentPane.add(scrollPane);
        list.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
        list.setBounds(10, 11, 642, 46);
        scrollPane.setViewportView(list);

        scrollPane.getVerticalScrollBar().setValue(0);

    } catch (NullPointerException e) {
    }
}

From source file:mfi.staticresources.ProcessResources.java

private String base64svg(String content) {

    content = replace(content, "image/svg+xml;charset=utf8,", "image/svg+xml;charset=utf8;base64,");
    try {//from   w  w w.j  a  v  a 2  s  . c  om
        boolean again = true;
        while (again) {
            String svg = StringUtils.substringBetween(content, "<svg", "</svg>");
            if (StringUtils.isBlank(svg)) {
                again = false;
            } else {
                svg = "<svg" + svg + "</svg>";
                byte[] svgBytes = svg.getBytes("UTF-8");
                String substringase64 = new String(Base64.encodeBase64(svgBytes), "UTF-8");
                content = StringUtils.replace(content, svg, substringase64);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return content;
}

From source file:com.jayway.restassured.path.json.JsonPathObjectDeserializationTest.java

@Test
public void json_path_supports_custom_deserializer_with_static_configuration() {
    // Given//from   w  w w.jav a  2s . co m
    final AtomicBoolean customDeserializerUsed = new AtomicBoolean(false);

    JsonPath.config = new JsonPathConfig().defaultObjectDeserializer(new JsonPathObjectDeserializer() {
        public <T> T deserialize(ObjectDeserializationContext ctx) {
            customDeserializerUsed.set(true);
            final String json = ctx.getDataToDeserialize().asString();
            final Greeting greeting = new Greeting();
            greeting.setFirstName(StringUtils.substringBetween(json, "\"firstName\":\"", "\""));
            greeting.setLastName(StringUtils.substringBetween(json, "\"lastName\":\"", "\""));
            return (T) greeting;
        }
    });

    final JsonPath jsonPath = new JsonPath(GREETING);

    // When
    try {
        final Greeting greeting = jsonPath.getObject("", Greeting.class);

        // Then
        assertThat(greeting.getFirstName(), equalTo("John"));
        assertThat(greeting.getLastName(), equalTo("Doe"));
        assertThat(customDeserializerUsed.get(), is(true));
    } finally {
        JsonPath.reset();
    }
}

From source file:com.sketchy.server.action.ManageNetworkSettings.java

private NetworkInfo readNetworkInfo() throws Exception {
    NetworkInfo networkInfo = new NetworkInfo();

    List<String> lines = FileUtils.readLines(WPA_SUPPLICANT_FILE);

    for (String line : lines) {
        String ssid = StringUtils.substringAfter(line, "ssid=");
        String psk = StringUtils.substringAfter(line, "psk=");
        if (StringUtils.isNotBlank(ssid)) {
            networkInfo.ssid = StringUtils.substringBetween(ssid, "\"", "\"");
        }/*from w ww.  j a  v  a 2s .c o m*/
        if (StringUtils.isNotBlank(psk)) {
            networkInfo.password = StringUtils.substringBetween(psk, "\"", "\"");
        }
    }
    return networkInfo;
}

From source file:com.joyent.manta.http.MantaHttpRequestExecutor.java

/**
 * Extracts the remote load balancer IP address from the toString() method
 * of a {@link HttpClientConnection}./*  w w  w  .j a  va 2s .c om*/
 *
 * @param conn connection to extract IP information from
 * @return IP address string or null if connection is null
 */
private static String extractLoadBalancerAddress(final HttpClientConnection conn) {
    if (conn == null) {
        return null;
    }

    return StringUtils.substringBetween(conn.toString(), "<->", ":");
}

From source file:com.netflix.dyno.connectionpool.impl.lb.TokenAwareSelection.java

/**
 * Identifying the proper pool for the operation. A couple of things that may affect the decision
 * (a) hashtags: In this case we will construct the key by decomposing from the hashtag
 * (b) type of key: string keys vs binary keys. 
 * In binary keys hashtags do not really matter.
 *///from   w w  w.j a va 2 s. c o m
@Override
public HostConnectionPool<CL> getPoolForOperation(BaseOperation<CL, ?> op, String hashtag)
        throws NoAvailableHostsException {

    String key = op.getStringKey();
    HostConnectionPool<CL> hostPool;
    HostToken hToken;

    if (key != null) {
        // If a hashtag is provided by Dynomite then we use that to create the key to hash.
        if (hashtag == null || hashtag.isEmpty()) {
            hToken = this.getTokenForKey(key);
        } else {
            String hashValue = StringUtils.substringBetween(key, Character.toString(hashtag.charAt(0)),
                    Character.toString(hashtag.charAt(1)));
            hToken = this.getTokenForKey(hashValue);
        }

        if (hToken == null) {
            throw new NoAvailableHostsException("Token not found for key " + key);
        }

        hostPool = tokenPools.get(hToken.getToken());
        ;
        if (hostPool == null) {
            throw new NoAvailableHostsException("Could not find host connection pool for key: " + key
                    + ", hash: " + tokenMapper.hash(key) + " Token:" + hToken.getToken());
        }
    } else {
        // the key is binary
        byte[] binaryKey = op.getBinaryKey();
        hToken = this.getTokenForKey(binaryKey);
        if (hToken == null) {
            throw new NoAvailableHostsException("Token not found for key " + binaryKey.toString());
        }

        hostPool = tokenPools.get(hToken.getToken());
        if (hostPool == null) {
            throw new NoAvailableHostsException(
                    "Could not find host connection pool for key: " + binaryKey.toString() + ", hash: "
                            + tokenMapper.hash(binaryKey) + " Token:" + getTokenForKey(binaryKey));
        }

    }
    return hostPool;

}

From source file:cn.mypandora.controller.MyUpload.java

/**
 * @param part ??null// w  w w.  ja  v a2s.c om
 * @return String
 * @Title: getFileName
 * @Description: PartHeader??????
 */
private String getFileName(Part part) {
    if (part == null) {
        return null;
    }
    // ?header?content-disposition??????
    String fileName = part.getHeader("content-disposition");
    if (StringUtils.isBlank(fileName)) {
        return null;
    }
    return StringUtils.substringBetween(fileName, "filename=\"", "\"");
}

From source file:com.norconex.collector.http.url.impl.GenericCanonicalLinkDetector.java

@Override
public String detectFromMetadata(String reference, HttpMetadata metadata) {
    String link = StringUtils.trimToNull(metadata.getString("Link"));
    if (link != null) {
        if (link.toLowerCase().matches(".*rel\\s*=\\s*[\"']canonical[\"'].*")) {
            link = StringUtils.substringBetween(link, "<", ">");
            return toAbsolute(reference, link);
        }//from  www.j a v  a2s. co  m
    }
    return null;
}

From source file:de.tor.tribes.util.parser.TroopsParser70.java

@Override
public boolean parse(String pData) {
    StringTokenizer lineTokenizer = new StringTokenizer(pData, "\n\r");
    List<String> lineList = new LinkedList<>();

    while (lineTokenizer.hasMoreElements()) {
        String line = lineTokenizer.nextToken();
        //"cheap snob rebuild linebreak"-hack
        if (line.trim().endsWith("+")) {
            line += lineTokenizer.nextToken();
        }/*w ww .j  a  v a2s.  c om*/
        debug("Push line to stack: " + line);
        lineList.add(line);
    }

    // used to update group on the fly, if not "all" selected
    String groupName = null;
    // groups could be multiple lines, detection is easiest for first line (starts with "Gruppen:")
    boolean groupLines = false;
    // store visited villages, so we can add em to selected group
    List<Village> villages = new LinkedList<>();

    int foundTroops = 0;
    TroopsManager.getSingleton().invalidate();
    while (!lineList.isEmpty()) {
        String currentLine = lineList.remove(0);
        Village v = null;
        try {
            v = VillageParser.parseSingleLine(currentLine);
        } catch (Exception e) {
            //no village in line
        }
        if (v != null) {
            if (processEntry(v, currentLine, lineList)) {
                foundTroops++;
                // add village to list of villages in selected group
                if (groupName != null)
                    villages.add(v);
                groupLines = false; //should already be false. set to false again, to avoid searching for group name in garbage if user copied nonsense
            }
        } else {
            // Check if current line is first group line. In case it is, store selected group
            if (currentLine.trim().startsWith(getVariable("overview.groups")))
                groupLines = true;
            // Check if current line contains active group. In case it does, store group name and stop searching
            if (groupLines && currentLine.matches(".*>.*?<.*")) {
                groupLines = false;
                groupName = StringUtils.substringBetween(currentLine, ">", "<"); // = line.replaceAll(".*>|<.*",""); if we stop using Apache Commons   
                debug("Found selected group in line '" + currentLine + "'");
                debug("Selected group '" + groupName + "'");
            } else
                debug("Dropping line '" + currentLine + "'");
        }
    }
    boolean retValue = (foundTroops != 0);
    if (retValue) {
        try {
            DSWorkbenchMainFrame.getSingleton()
                    .showSuccess("DS Workbench hat Truppeninformationen zu " + foundTroops
                            + ((foundTroops == 1) ? " Dorf " : " Drfern ")
                            + " in die Truppenbersicht eingetragen.");
        } catch (Exception e) {
            NotifierFrame.doNotification("DS Workbench hat Truppeninformationen zu " + foundTroops
                    + ((foundTroops == 1) ? " Dorf " : " Drfern ") + " in die Truppenbersicht eingetragen.",
                    NotifierFrame.NOTIFY_INFO);
        }
    }
    TroopsManager.getSingleton().revalidate(retValue);

    //update selected group, if any
    if (groupName != null && !groupName.equals(getVariable("groups.all"))) {
        HashMap<String, List<Village>> groupTable = new HashMap<>();
        groupTable.put(groupName, villages);
        DSWorkbenchMainFrame.getSingleton().fireGroupParserEvent(groupTable);
    }

    return retValue;
}