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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:com.hangum.tadpole.db.metadata.MakeContentAssistUtil.java

/**
 * List of assist table name //from w  w w  . j a  va 2  s  .co m
 * 
 * @return
 */
public String getAssistTableList(final UserDBDAO userDB) {
    StringBuffer strTablelist = new StringBuffer();

    try {
        List<TableDAO> showTables = new ArrayList<TableDAO>();
        if (userDB.getListTable().isEmpty())
            showTables = getTableListOnlyTableName(userDB);
        else
            showTables = userDB.getListTable();

        for (TableDAO tableDao : showTables) {
            strTablelist.append(makeObjectPattern(tableDao.getSchema_name(), tableDao.getSysName(), "Table")); //$NON-NLS-1$
        }
    } catch (Exception e) {
        logger.error("getTable list", e); //$NON-NLS-1$
    }
    userDB.setTableListSeparator(StringUtils.removeEnd(strTablelist.toString(), _PRE_GROUP)); //$NON-NLS-1$

    return userDB.getTableListSeparator();
}

From source file:com.hangum.tadpole.engine.sql.util.SQLUtil.java

/**
 *  jdbc?    .//w w w  . j  a  v  a2  s. co  m
 * 
 * @param userDB
 * @param exeSQL
 * @return
 */
public static String makeExecutableSQL(UserDBDAO userDB, String exeSQL) {

    //      tmpStrSelText = UnicodeUtils.getUnicode(tmpStrSelText);

    //         https://github.com/hangum/TadpoleForDBTools/issues/140  .
    //         TO DO  ? ??  ??..DB?    ?   . 

    //  ? // ? ? ?? ? .
    /*
     *  mysql?  ?? , --  ? ? --   ? ??   ?. --comment ? ? ?? .( (mssql, oralce, pgsql)? ? ??)
     *   ,  ?? ??   ?? ??   . - 2013.11.11- (hangum)
     */

    exeSQL = StringUtils.trimToEmpty(exeSQL);

    // ?.
    // oracle, tibero, altibase?  ? ?  ??  .
    if (userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT | userDB.getDBDefine() == DBDefine.TIBERO_DEFAULT
            | userDB.getDBDefine() == DBDefine.ALTIBASE_DEFAULT) {
        // ignore code
    } else {
        exeSQL = removeComment(exeSQL);
    }
    exeSQL = StringUtils.trimToEmpty(exeSQL);
    exeSQL = StringUtils.removeEnd(exeSQL, "/");
    exeSQL = StringUtils.trimToEmpty(exeSQL);
    //TO DO ?? ? ?  (;)  .  ?  .
    exeSQL = StringUtils.removeEnd(exeSQL, PublicTadpoleDefine.SQL_DELIMITER);

    return exeSQL;
}

From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.JerseyOAuth2Filter.java

private boolean validScope(AppUserSession appUserSession, String uri) throws IOException, ServletException {
    uri = StringUtils.removeStart(StringUtils.removeEnd(uri, "/"), "/");
    AuthScope scope = FenixJerseyAPIConfig.getScope(uri);
    if (scope != null) {
        if (appUserSession.getAppUserAuthorization().getApplication().getScopesSet().contains(scope)) {
            return true;
        }/* w  ww .ja  v a  2  s  .c om*/
    }
    return false;
}

From source file:com.enonic.cms.business.portal.processor.ContentRequestProcessor.java

private boolean redirectPathIsEqualToRequestedPath(String newLocalPath, String requestedPath) {
    newLocalPath = StringUtils.removeStart(newLocalPath, "/");
    requestedPath = StringUtils.removeStart(requestedPath, "/");

    newLocalPath = StringUtils.removeEnd(newLocalPath, "/");
    requestedPath = StringUtils.removeEnd(requestedPath, "/");

    return newLocalPath.equalsIgnoreCase(requestedPath);
}

From source file:com.cloudbees.simplediskusage.QuickDiskUsagePlugin.java

private long computeDiskUsage(File path) throws IOException, InterruptedException {
    if (path == null || !path.exists() || !path.isDirectory())
        return -1;
    logger.fine("Estimating usage for: " + path.getAbsolutePath());
    // TODO switch to Jenkins.getActiveInstance() once 1.590+ is the baseline
    Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        throw new IllegalStateException("Jenkins has not been started, or was already shut down");
    }/*from   w  w w  . j  a  v a 2 s.  c  om*/

    // this write operation will lock the current thread if filesystem is frozen
    // otherwise reads could block freeze operation and slow down snapshotting
    FilePath jenkinsHome = jenkins.getRootPath();
    if (jenkinsHome != null) {
        jenkinsHome.touch(System.currentTimeMillis());
    } else {
        return -1;
    }

    Launcher.LocalLauncher launcher = new Launcher.LocalLauncher(TaskListener.NULL);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Proc proc = launcher.launch().cmds(StringUtils.split(DU_COMMAND)).pwd(path).stdout(out).start();

    // give up after 20 seconds and kill 'du' process to prevent reads to put disk down to its knees
    // before the next attempt, we might be blocked by the write operation above
    int status = proc.joinWithTimeout(20, TimeUnit.SECONDS, TaskListener.NULL);

    switch (status) {
    case 0:
        try {
            return Long.parseLong(StringUtils.removeEnd(out.toString("UTF-8"), "\t.\n"));
        } catch (NumberFormatException e) {
            return -1;
        }
    case 143:
        logger.warning("Time to compute the size of '" + path.getCanonicalPath()
                + "' is too long. 'du' process killed after 20 seconds of activity. You might be experiencing storage slowness.");
        return -1;
    }

    return -1;
}

From source file:edu.monash.merc.util.DMUtil.java

public static String normalizePath(String path) {
    if (StringUtils.isNotBlank(path)) {
        if (StringUtils.endsWith(path, "/")) {
            return StringUtils.removeEnd(path, "/");
        } else {//from ww w  . j a  v a 2 s . c  o  m
            return path;
        }
    }
    return path;
}

From source file:au.edu.monash.merc.capture.util.rights.CCSLicenseUtil.java

@SuppressWarnings("unchecked")
public CCLicense getCCLicense(String licenseParams) {
    Document licenseDoc = null;/*ww  w .j  a v a  2  s  .  c  o  m*/

    JDOMXPath xp_licenseName;
    JDOMXPath xp_licenseHtml;
    JDOMXPath xp_licenseLink;
    JDOMXPath xp_licenseHref;

    // create XPath expressions
    try {
        xp_licenseName = new JDOMXPath("//license-name");
        xp_licenseHtml = new JDOMXPath("//html");
        xp_licenseLink = new JDOMXPath("//license-uri");
        xp_licenseHref = new JDOMXPath("//a");

    } catch (JaxenException e) {
        throw new ConfigException(e);
    }
    try {
        if (serviceURL == null) {
            serviceURL = license_rest_url;
        }
        URL licenseUrl = new URL(serviceURL + "/get?" + licenseParams);
        licenseDoc = this.parser.build(licenseUrl);
    } catch (Exception e) {
        throw new ConfigException(e);
    }

    // extract the identifiers and labels using XPath
    try {
        String licenseName = ((Element) xp_licenseName.selectSingleNode(licenseDoc)).getText();
        String licenseLink = ((Element) xp_licenseLink.selectSingleNode(licenseDoc)).getText();
        String licenseHtml = ((Element) xp_licenseHtml.selectSingleNode(licenseDoc)).getText();
        List<Element> allHrefs = xp_licenseHref.selectNodes(licenseDoc);
        String aHrefText = null;
        for (Element e : allHrefs) {
            String hrefText = e.getText();
            if (StringUtils.isNotBlank(hrefText)) {
                aHrefText = hrefText;
            }
        }
        licenseHtml = StringUtils.removeEnd(licenseHtml, ".").trim();
        CCLicense license = new CCLicense(licenseName, licenseLink, licenseHtml, aHrefText);
        return license;
    } catch (JaxenException e) {
        throw new ConfigException(e);
    }
}

From source file:hydrograph.ui.engine.ui.converter.impl.OutputMysqlUiConverter.java

/**
 * Appends primary keys using a comma/*from w  w  w.j a v  a2 s .  c o  m*/
 * @param newTable
 */
private String getLoadTypePrimaryKeyUIValue(TypePrimaryKeys newTable) {
    StringBuffer stringBuffer = new StringBuffer();
    if (newTable != null && newTable.getPrimaryKeys() != null) {
        TypeKeyFields typeKeyFields = newTable.getPrimaryKeys();
        for (TypeFieldName typeFieldName : typeKeyFields.getField()) {
            stringBuffer.append(typeFieldName.getName());
            stringBuffer.append(",");
        }
    }
    return StringUtils.removeEnd(stringBuffer.toString(), ",");
}

From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java

/**
 * Returns the 'Add child' action.//from w w  w.j  av a2 s.c o m
 *
 * @return the action
 */
@SuppressWarnings("serial")
private Action getAddChildAction() {
    if (addChildAction == null) {
        String actionCommand = bundle.getString(ADD_CHILD_NODE_KEY);
        String actionKey = bundle.getString(ADD_CHILD_NODE_KEY + ".action");
        addChildAction = new AbstractAction(actionCommand, Icons.ADD) {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("actionPerformed(): action = " + e.getActionCommand());
                if (checkAction()) {
                    model.addNode(StringUtils.removeEnd(nodes[0].getPath(), "/") + "/" + childName,
                            childText.getBytes());
                }
                childName = childText = "";
            }

            private boolean checkAction() {
                JDialog dlg = createAddChildDialog();

                dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                dlg.setSize(800, 600);
                dlg.setLocationRelativeTo(null);
                dlg.setVisible(true);

                boolean nameIsEmpty = childName == null || childName.isEmpty();
                boolean dataIsEmpty = childText == null;
                return !nameIsEmpty && !dataIsEmpty;
            }
        };
        addChildAction.putValue(Action.ACTION_COMMAND_KEY, actionKey);
    }
    return this.addChildAction;
}

From source file:edu.monash.merc.wsclient.licence.CCLClient.java

@SuppressWarnings("unchecked")
public CCLicense getCCLicense(String licenseParams) {
    Document licenseDoc = null;/*  w ww .j  a  v a  2  s  . c o  m*/

    JDOMXPath xp_licenseName;
    JDOMXPath xp_licenseHtml;
    JDOMXPath xp_licenseLink;
    JDOMXPath xp_licenseHref;

    // create XPath expressions
    try {
        xp_licenseName = new JDOMXPath("//license-name");
        xp_licenseHtml = new JDOMXPath("//html");
        xp_licenseLink = new JDOMXPath("//license-uri");
        xp_licenseHref = new JDOMXPath("//a");

    } catch (JaxenException e) {
        throw new WSException(e);
    }
    try {
        if (serviceURL == null) {
            serviceURL = license_rest_url;
        }
        URL licenseUrl = new URL(serviceURL + "/get?" + licenseParams);
        licenseDoc = this.parser.build(licenseUrl);
    } catch (Exception e) {
        throw new WSException(e);
    }

    // extract the identifiers and labels using XPath
    try {
        String licenseName = ((Element) xp_licenseName.selectSingleNode(licenseDoc)).getText();
        String licenseLink = ((Element) xp_licenseLink.selectSingleNode(licenseDoc)).getText();
        String licenseHtml = ((Element) xp_licenseHtml.selectSingleNode(licenseDoc)).getText();
        List<Element> allHrefs = xp_licenseHref.selectNodes(licenseDoc);
        String aHrefText = null;
        for (Element e : allHrefs) {
            String hrefText = e.getText();
            if (StringUtils.isNotBlank(hrefText)) {
                aHrefText = hrefText;
            }
        }
        licenseHtml = StringUtils.removeEnd(licenseHtml, ".").trim();
        CCLicense license = new CCLicense(licenseName, licenseLink, licenseHtml, aHrefText);
        return license;
    } catch (JaxenException e) {
        throw new WSException(e);
    }
}