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

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

Introduction

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

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:adalid.core.XS1.java

static boolean checkAccess() {
    String method;//w ww . j av a  2  s. c  om
    String caller = null;
    final StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    for (StackTraceElement element : stack) {
        method = element.getClassName() + "." + element.getMethodName();
        if (caller == null) {
            if (method.startsWith(ROOT_PACKAGE) && !method.startsWith(THIS_CLASS)) {
                caller = method;
            }
        } else if (method.startsWith(ROOT_PACKAGE)) {
            break;
        } else {
            String message = "illegal invocation of \"" + StringUtils.substringAfterLast(caller, ".") + "\"";
            message += " at " + method + "(" + element.getFileName() + ":" + element.getLineNumber() + ")";
            throw new IllegalAccessRuntimeException(message);
        }
    }
    return caller != null;
}

From source file:com.hangum.tadpole.rdb.core.dialog.db.UpdateDeleteConfirmDialog.java

/**
 * initialize data//from   ww  w  . j av  a2 s.c  om
 */
private void initData() {
    String strSQL = reqQuery.getSql();
    if (reqQuery.getSqlStatementType() == PublicTadpoleDefine.SQL_STATEMENT_TYPE.PREPARED_STATEMENT) {
        strSQL = reqQuery.getSqlAddParameter();
    }

    textQuery.setText(strSQL);
    try {
        QueryDMLInfoDTO dmlInfoDto = new QueryDMLInfoDTO();
        UpdateDeleteParser parser = new UpdateDeleteParser();
        parser.parseQuery(strSQL, dmlInfoDto);

        String strObjecName = dmlInfoDto.getObjectName();
        String strWhereAfter = StringUtils.substringAfterLast(strSQL.toLowerCase(), "where");

        if (logger.isDebugEnabled()) {
            logger.debug("=============================================================================");
            logger.debug("object name : " + strObjecName);
            logger.debug("where after query: " + strWhereAfter);
            logger.debug("=============================================================================");
        }

        String sqlSelect = "select * from " + strObjecName;
        if (!StringUtils.trimToEmpty(strWhereAfter).equals("")) {
            sqlSelect += " where " + strWhereAfter;

            isWhere = true;
        }

        if (isWhere) {
            QueryExecuteResultDTO rsDAO = QueryUtils.executeQuery(userDB, sqlSelect, 0,
                    GetPreferenceGeneral.getPageCount());
            createTableColumn(reqQuery, tvQueryResult, rsDAO, false);

            tvQueryResult.setLabelProvider(new SQLResultLabelProvider(reqQuery.getMode(), rsDAO));
            tvQueryResult.setContentProvider(new ArrayContentProvider());
            final TadpoleResultSet trs = rsDAO.getDataList();
            tvQueryResult.setInput(trs.getData());
            TableUtil.packTable(tvQueryResult.getTable());

            if (trs.getData().size() < GetPreferenceGeneral.getPageCount()) {
                labelSummaryText.setText(Messages.get().CheckDataAndRunQeury + " ("
                        + String.format(Messages.get().UpdateDeleteConfirmDialog_findData, trs.getData().size())
                        + ")");
            } else {
                labelSummaryText.setText(Messages.get().CheckDataAndRunQeury + " (" + String.format(
                        Messages.get().UpdateDeleteConfirmDialog_findDataOver, trs.getData().size()) + ")");
            }

            tvQueryResult.getTable().setToolTipText(sqlSelect);
        } else {
            if (logger.isDebugEnabled())
                logger.debug("mabe all data delete");
        }

        //  ui  .
        compositeData.setVisible(isWhere);
        compositeWhere.setVisible(!isWhere);
        compositeWhere.getParent().layout(true);

    } catch (Exception e) {
        logger.error("initialize sql", e);
    }
}

From source file:edu.ku.brc.af.core.expresssearch.QueryForIdResultsSQL.java

public String getSQL(final String searchTermArg, final Vector<Integer> ids) {
    if (StringUtils.isNotEmpty(overrideSQL)) {
        return overrideSQL;
    }//  w  w w  .j a va2 s .c o m

    Vector<Integer> tempIds = ids == null ? recIds : ids;
    // else
    StringBuilder idsStr = new StringBuilder(recIds.size() * 8);
    for (int i = 0; i < tempIds.size(); i++) {
        if (i > 0)
            idsStr.append(',');
        idsStr.append(tempIds.elementAt(i).toString());
    }

    String sqlStr;
    if (getJoinColTableId() != null) {
        String joinIdName = null;
        for (ERTIJoinColInfo jci : tableInfo.getJoins()) {
            if (joinColTableId == jci.getJoinTableIdAsInt()) {
                joinIdName = jci.getColName();
            }
        }

        String critiera = (tableInfo.isFieldNameOnlyForSQL() ? StringUtils.substringAfterLast(joinIdName, ".") //$NON-NLS-1$
                : joinIdName) + " in (" + idsStr.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$

        //System.out.println("["+critiera+"]");
        sqlStr = String.format(tableInfo.getViewSql(), new Object[] { joinIdName, critiera });
        //System.out.println("["+sqlStr+"]");
        sqlStr = QueryAdjusterForDomain.getInstance().adjustSQL(sqlStr);

    } else {
        String vsql = getTableInfo().getViewSql();
        sqlStr = idsStr.length() > 0 ? vsql.replace("%s", idsStr.toString()) : vsql; //$NON-NLS-1$
    }
    return sqlStr;
}

From source file:com.adobe.acs.commons.mcp.impl.processes.cfi.ContentFragmentImport.java

protected boolean createFolderNode(String path, String folderTitle, ResourceResolver r)
        throws RepositoryException, PersistenceException {
    if (path == null) {
        return false;
    }/*from  www  . j  av a2  s.  c  o  m*/
    if (dryRunMode) {
        return true;
    }
    String parentPath = StringUtils.substringBeforeLast(path, "/");
    boolean titleProvided;
    String folderName = StringUtils.substringAfterLast(path, "/");
    if (folderTitle == null) {
        folderTitle = folderName;
        titleProvided = false;
    } else {
        titleProvided = true;
    }
    Session s = r.adaptTo(Session.class);
    if (s.nodeExists(path) && titleProvided) {
        return updateFolderTitle(s, path, folderTitle, r);
    } else if (!s.nodeExists(path)) {
        if (!s.nodeExists(parentPath)) {
            createFolderNode(parentPath, null, r);
        }
        Node child = s.getNode(parentPath).addNode(folderName, DEFAULT_FOLDER_TYPE);
        trackDetailedActivity(path, "Create Folder", "Create folder", 0L);
        setFolderTitle(child, folderTitle);
        incrementCount(createdFolders, 1L);
        r.commit();
        r.refresh();
        return true;
    }
    return false;
}

From source file:info.magnolia.cms.servlets.PropertyInitializer.java

/**
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 *//*ww  w .ja  va  2s .co m*/
public void contextInitialized(ServletContextEvent sce) {
    final ServletContext context = sce.getServletContext();

    String propertiesLocationString = context.getInitParameter(MAGNOLIA_INITIALIZATION_FILE);

    if (log.isDebugEnabled()) {
        log.debug("{} value in web.xml is :[{}]", MAGNOLIA_INITIALIZATION_FILE, propertiesLocationString); //$NON-NLS-1$
    }
    if (StringUtils.isEmpty(propertiesLocationString)) {
        propertiesLocationString = DEFAULT_INITIALIZATION_PARAMETER;
    }

    String[] propertiesLocation = StringUtils.split(propertiesLocationString, ',');

    String servername = null;

    try {
        servername = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName());
    } catch (UnknownHostException e) {
        log.error(e.getMessage());
    }

    String rootPath = StringUtils.replace(context.getRealPath(StringUtils.EMPTY), "\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
    String webapp = StringUtils.substringAfterLast(rootPath, "/"); //$NON-NLS-1$

    File logs = new File(webapp + File.separator + "logs");
    File tmp = new File(webapp + File.separator + "tmp");
    if (!logs.exists()) {
        logs.mkdir();
        log.debug("Creating " + logs.getAbsoluteFile() + " folder");
    }

    if (!tmp.exists()) {
        tmp.mkdir();
        log.debug("Creating " + tmp.getAbsoluteFile() + " folder");
    }

    if (log.isDebugEnabled()) {
        log.debug("rootPath is {}, webapp is {}", rootPath, webapp); //$NON-NLS-1$ 
    }

    for (int j = 0; j < propertiesLocation.length; j++) {
        String location = StringUtils.trim(propertiesLocation[j]);
        location = StringUtils.replace(location, "${servername}", servername); //$NON-NLS-1$
        location = StringUtils.replace(location, "${webapp}", webapp); //$NON-NLS-1$

        File initFile = new File(rootPath, location);

        if (!initFile.exists() || initFile.isDirectory()) {
            if (log.isDebugEnabled()) {
                log.debug("Configuration file not found with path [{}]", //$NON-NLS-1$
                        initFile.getAbsolutePath());
            }
            continue;
        }

        InputStream fileStream;
        try {
            fileStream = new FileInputStream(initFile);
        } catch (FileNotFoundException e1) {
            log.debug("Configuration file not found with path [{}]", //$NON-NLS-1$
                    initFile.getAbsolutePath());
            return;
        }

        try {
            envProperties.load(fileStream);

            log.info("Loading configuration at {}", initFile.getAbsolutePath());//$NON-NLS-1$

            Log4jConfigurer.initLogging(context, envProperties);

            new ConfigLoader(context, envProperties);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(fileStream);
        }
        return;

    }

    log.error(MessageFormat.format(
            "No configuration found using location list {0}. [servername] is [{1}], [webapp] is [{2}] and base path is [{3}]", //$NON-NLS-1$
            new Object[] { ArrayUtils.toString(propertiesLocation), servername, webapp, rootPath }));

}

From source file:edu.ku.brc.specify.utilapps.ERDTable.java

/**
 * @param font//w w  w .j  a  v  a  2s.c o  m
 */
public void build(final Font font) {
    int numRows = 7;
    switch (displayType) {
    case All:
        numRows = 7;
        break;
    case MainFields:
        numRows = 7;
        break;
    case Title:
        numRows = 1;
        break;
    case TitleAndRel:
        numRows = 4;
        break;

    }
    Font bold = new Font(font.getFamily(), Font.BOLD, font.getSize());
    Font italic = new Font(font.getFamily(), Font.ITALIC, font.getSize());
    PanelBuilder pb = new PanelBuilder(
            new FormLayout("f:p:g", UIHelper.createDuplicateJGoodiesDef("p", "2px", numRows)));
    CellConstraints cc = new CellConstraints();

    String className = StringUtils.substringAfterLast(table.getClassName(), ".");
    DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByShortClassName(className);
    if (tblInfo == null) {
        throw new RuntimeException("Couldn't find table for className[" + className + "]");
    }
    String tblName = tblInfo.getTitle();
    int y = 1;
    pb.add(ERDVisualizer.mkLabel(bold, tblName, SwingConstants.CENTER), cc.xy(1, y));
    y += 2;

    boolean doingAll = displayType == DisplayType.All;
    if (displayType == DisplayType.All || displayType == DisplayType.MainFields) {
        pb.addSeparator("", cc.xy(1, y));
        y += 2;

        pb.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_FIELDS"), SwingConstants.CENTER),
                cc.xy(1, y));
        y += 2;

        String colsDef = "p:g,4px,p:g,4px" + (doingAll ? ",p:g,4px,p:g,4px" : "") + ",f:p:g";
        PanelBuilder fieldsPB = new PanelBuilder(new FormLayout(colsDef,
                UIHelper.createDuplicateJGoodiesDef("p", "2px", table.getFields().size() + 2)));
        int yy = 1;

        fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_FIELD"), SwingConstants.LEFT),
                cc.xy(1, yy));
        fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_TYPE"), SwingConstants.CENTER),
                cc.xy(3, yy));
        fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_LENGTH"), SwingConstants.CENTER),
                cc.xy(5, yy));
        if (doingAll) {
            fieldsPB.add(
                    ERDVisualizer.mkLabel(italic, getResourceString("ERD_REQUIRED"), SwingConstants.CENTER),
                    cc.xy(7, yy));
            fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_UNIQUE"), SwingConstants.CENTER),
                    cc.xy(9, yy));
        }
        yy += 2;

        if (StringUtils.isNotEmpty(table.getIdColumnName())) {
            build(fieldsPB, table, font, yy, doingAll); // does ID
            yy += 2;
        }

        for (DBFieldInfo f : table.getFields()) {
            build(fieldsPB, f, font, yy, doingAll);
            yy += 2;
        }
        pb.add(fieldsPB.getPanel(), cc.xy(1, y));
        y += 2;

    }

    if ((displayType == DisplayType.All || displayType == DisplayType.TitleAndRel)
            && table.getRelationships().size() > 0) {
        pb.addSeparator("", cc.xy(1, y));
        y += 2;

        pb.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_RELATIONSHIPS"), SwingConstants.CENTER),
                cc.xy(1, y));
        y += 2;

        String colsDef = "p:g,4px,p:g,4px" + (doingAll ? ",p:g,4px" : "") + ",f:p:g";
        PanelBuilder relsPB = new PanelBuilder(new FormLayout(colsDef,
                UIHelper.createDuplicateJGoodiesDef("p", "2px", table.getRelationships().size() + 1)));
        int yy = 1;

        relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_TABLE"), SwingConstants.LEFT),
                cc.xy(1, yy));
        relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_NAME"), SwingConstants.CENTER),
                cc.xy(3, yy));
        relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_TYPE"), SwingConstants.CENTER),
                cc.xy(5, yy));
        if (doingAll) {
            relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_REQUIRED"), SwingConstants.CENTER),
                    cc.xy(7, yy));
        }
        yy += 2;

        Vector<DBRelationshipInfo> orderedList = new Vector<DBRelationshipInfo>(table.getRelationships());
        Collections.sort(orderedList, new Comparator<DBRelationshipInfo>() {
            public int compare(DBRelationshipInfo o1, DBRelationshipInfo o2) {
                String name1 = ((DBRelationshipInfo) o1).getClassName();
                if (name1.startsWith("Sp")) {
                    name1 = name1.substring(2, name1.length());
                }
                String name2 = ((DBRelationshipInfo) o2).getClassName();
                if (name2.startsWith("Sp")) {
                    name2 = name2.substring(2, name2.length());
                }
                return name1.compareTo(name2);
            }
        });

        for (DBRelationshipInfo r : orderedList) {
            //System.out.println(r.getName()+" "+r.getType());
            if (!r.getName().toLowerCase().endsWith("iface")) {
                JComponent p = build(relsPB, r, font, yy, doingAll);
                relUIHash.put(r, p);
                yy += 2;
            }
        }
        pb.add(relsPB.getPanel(), cc.xy(1, y));
        y += 2;

        //fieldsPB.getPanel().setBackground(Color.GREEN);
        //relsPB.getPanel().setBackground(Color.BLUE);
    }

    inner = pb.getPanel();
    //inner.setBorder(BorderFactory.createEmptyBorder(BRD_GAP, BRD_GAP, BRD_GAP, BRD_GAP));

    inner.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK),
            BorderFactory.createEmptyBorder(BRD_GAP, BRD_GAP, BRD_GAP, BRD_GAP)));

    setBackground(Color.WHITE);
    add(inner, BorderLayout.CENTER);
}

From source file:com.alibaba.otter.shared.arbitrate.setl.BaseStageTest.java

protected Long initProcess() {
    String path = zookeeper.create(processPath + "/", new byte[0], CreateMode.PERSISTENT_SEQUENTIAL);

    // ?/*from   w w w.  j  av  a  2  s.  c o m*/
    String processNode = StringUtils.substringAfterLast(path, "/");
    return StagePathUtils.getProcessId(processNode);// ?process
}

From source file:info.magnolia.importexport.DataTransporter.java

/**
 * Deprecated./* w  w  w . j  a v a 2s .c o  m*/
 * @param properties
 * @param repositoryName
 * @deprecated since 4.0 - use the PropertiesImportExport class instead.
 */
public static void importProperties(Properties properties, String repositoryName) {
    for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        String value = (String) properties.get(key);

        String name = StringUtils.substringAfterLast(key, ".");
        String path = StringUtils.substringBeforeLast(key, ".").replace('.', '/');
        Content node = ContentUtil.getContent(repositoryName, path);
        if (node != null) {
            try {
                NodeDataUtil.getOrCreate(node, name).setValue(value);
                node.save();
            } catch (RepositoryException e) {
                log.error("can't set property " + key, e);
            }
        }
    }

}

From source file:info.magnolia.cms.filters.InterceptFilter.java

/**
 * Request and Response here is same as received by the original page so it includes all post/get data. Sub action
 * could be called from here once this action finishes, it will continue loading the requested page.
 * @throws RepositoryException/*from  w w  w.  ja va2  s  .  com*/
 * @throws LoginException
 */
public void intercept(HttpServletRequest request, HttpServletResponse response)
        throws LoginException, RepositoryException {
    final AggregationState aggregationState = MgnlContext.getAggregationState();
    String action = request.getParameter(INTERCEPT);
    String repository = request.getParameter(PARAM_REPOSITORY);
    String nodePath = request.getParameter(PARAM_PATH);
    String handle = aggregationState.getHandle();
    String channel = aggregationState.getChannel().getName();

    if (repository == null) {
        repository = aggregationState.getRepository();
    }

    if (repository == null) {
        repository = RepositoryConstants.WEBSITE;
    }

    final Session session = MgnlContext.getJCRSession(repository);

    if (ACTION_PREVIEW.equals(action)) {
        // preview mode (button in main bar)
        String preview = request.getParameter(MGNL_PREVIEW_ATTRIBUTE);
        log.debug("preview request parameter value is {} ", preview);
        if (preview != null) {
            if (Boolean.parseBoolean(preview)) {
                MgnlContext.setAttribute(MGNL_PREVIEW_ATTRIBUTE, Boolean.TRUE, Context.SESSION_SCOPE);
                MgnlContext.setAttribute(MultiChannelFilter.ENFORCE_CHANNEL_PARAMETER, channel,
                        Context.SESSION_SCOPE);
            } else {
                MgnlContext.removeAttribute(MGNL_PREVIEW_ATTRIBUTE, Context.SESSION_SCOPE);
                MgnlContext.removeAttribute(MultiChannelFilter.ENFORCE_CHANNEL_PARAMETER,
                        Context.SESSION_SCOPE);
            }
        } else {
            MgnlContext.removeAttribute(MGNL_PREVIEW_ATTRIBUTE, Context.SESSION_SCOPE);
            MgnlContext.removeAttribute(MultiChannelFilter.ENFORCE_CHANNEL_PARAMETER, Context.SESSION_SCOPE);
        }
    } else if (ACTION_NODE_DELETE.equals(action)) {
        // delete paragraph
        try {
            Node page = session.getNode(handle);
            session.removeItem(nodePath);
            MetaDataUtil.updateMetaData(page);
            session.save();
        } catch (RepositoryException e) {
            log.error("Exception caught: {}", e.getMessage(), e);
        }
    } else if (ACTION_NODE_SORT.equals(action)) {
        // sort paragraphs
        try {
            String pathSelected = request.getParameter(PARAM_PATH_SELECTED);
            String pathTarget = request.getParameter(PARAM_PATH_TARGET);
            String pathParent = StringUtils.substringBeforeLast(pathSelected, "/");
            String srcName = StringUtils.substringAfterLast(pathSelected, "/");
            String destName = StringUtils.substringAfterLast(pathTarget, "/");
            String order = StringUtils.defaultIfEmpty(request.getParameter("order"), "before");
            if (StringUtils.equalsIgnoreCase(destName, "mgnlNew")) {
                destName = null;
            }
            Node parent = session.getNode(pathParent + srcName);

            if ("before".equals(order)) {
                NodeUtil.orderBefore(parent, destName);
            } else {
                NodeUtil.orderAfter(parent, destName);
            }

            Node page = session.getNode(handle);
            MetaDataUtil.updateMetaData(page);
            session.save();
        } catch (RepositoryException e) {
            log.error("Exception caught: {}", e.getMessage(), e);
        }
    } else {
        log.warn("Unknown action {}", action);
    }
}

From source file:edu.monash.merc.system.scheduling.impl.RifcsProcessor.java

private String getRootRelPath(String fullPath) {
    String path = StringUtils.removeEnd(fullPath, "/");
    String relPpath = StringUtils.substringAfterLast(path, "/");
    if (StringUtils.isBlank(relPpath)) {
        throw new DMConfigException("The root relative path is null");
    }/*w  w  w .j a  va  2  s  .co  m*/
    return relPpath;
}