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

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

Introduction

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

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptScanner.java

public List<ScriptResource> getScripts(ScriptType scriptType, @Nullable String moduleName) {
    try {//from  w w  w . j  ava 2  s.  c o  m
        ResourcePatternResolver resourceResolver = createAppropriateResourceResolver();
        String urlPattern = String.format("%s/%s/%s/%s/**/*%s.*", dbScriptsDirectoryForSearch(),
                moduleName != null ? moduleName : "**", scriptType, dbmsType,
                scriptType == ScriptType.INIT ? "create-db" : "");
        String urlPatternWithDbmsVersion = null;
        if (StringUtils.isNotBlank(dbmsVersion)) {
            urlPatternWithDbmsVersion = String.format("%s/%s/%s/%s-%s/**/*%s.*", dbScriptsDirectoryForSearch(),
                    moduleName != null ? moduleName : "**", scriptType, dbmsType, dbmsVersion,
                    scriptType == ScriptType.INIT ? "create-db" : "");
        }

        Map<String, ScriptResource> scriptResources = findResourcesByUrlPattern(resourceResolver, urlPattern);
        if (StringUtils.isNotBlank(urlPatternWithDbmsVersion)) {
            Map<String, ScriptResource> additionalResources = findResourcesByUrlPattern(resourceResolver,
                    urlPatternWithDbmsVersion);
            scriptResources.putAll(additionalResources);
        }

        List<ScriptResource> results = new ArrayList<>(scriptResources.values());
        Collections.sort(results, (ScriptResource r1, ScriptResource r2) -> {
            if (r1.getDir().equals(r2.getDir())) {
                return r1.getName().compareTo(r2.getName());
            } else {
                String dbmsTypeAndVersion = dbmsType + "-" + dbmsVersion;
                String separator1 = r1.getPath().contains(dbmsTypeAndVersion) ? dbmsTypeAndVersion : dbmsType;
                String separator2 = r2.getPath().contains(dbmsTypeAndVersion) ? dbmsTypeAndVersion : dbmsType;

                String pathAfterDbms1 = StringUtils.substringAfter(r1.getPath(), separator1);
                String pathBeforeDbms1 = StringUtils.substringBefore(r1.getPath(), separator1);

                String pathAfterDbms2 = StringUtils.substringAfter(r2.getPath(), separator2);
                String pathBeforeDbms2 = StringUtils.substringBefore(r2.getPath(), separator2);

                return pathBeforeDbms1.equals(pathBeforeDbms2) ? pathAfterDbms1.compareTo(pathAfterDbms2)
                        : pathBeforeDbms1.compareTo(pathBeforeDbms2);
            }
        });

        return results;
    } catch (IOException e) {
        throw new RuntimeException("An error occurred while loading scripts", e);
    }
}

From source file:com.amalto.core.history.accessor.AttributeAccessor.java

private QName getQName(Document domDocument) {
    QName qName;//  w  ww.j av  a  2 s.com
    String prefix = StringUtils.substringBefore(attributeName, ":"); //$NON-NLS-1$
    String name = StringUtils.substringAfter(attributeName, ":"); //$NON-NLS-1$
    if (name.isEmpty()) {
        // No prefix (so prefix is attribute name due to substring calls).
        String attributeNamespaceURI = domDocument.getDocumentURI();
        if (attributeNamespaceURI == null || attributeNamespaceURI.isEmpty()) {
            Node attributeNode = getAttributeNode(domDocument);
            if (attributeNode != null) {
                attributeNamespaceURI = attributeNode.getNamespaceURI();
            }
        }
        qName = new QName(attributeNamespaceURI, prefix);
    } else {
        String attributeNamespaceURI = domDocument.lookupNamespaceURI(prefix);
        if (attributeNamespaceURI == null || attributeNamespaceURI.isEmpty()) {
            Node attributeNode = getAttributeNode(domDocument);
            if (attributeNode != null) {
                attributeNamespaceURI = attributeNode.lookupNamespaceURI(prefix);
            }
        }
        qName = new QName(attributeNamespaceURI, name, prefix);
    }
    return qName;
}

From source file:com.google.gdt.eclipse.designer.uibinder.model.widgets.CellPanelInfo.java

/**
 * Contributes <code>"Cell"</code> complex property for each {@link WidgetInfo} child of this
 * {@link CellPanelInfo}.//from  www .jav a  2 s  . co  m
 */
private void contributeCellProperties() {
    final CellPanelInfo panel = this;
    addBroadcastListener(new XmlObjectAddProperties() {
        public void invoke(XmlObjectInfo object, List<Property> properties) throws Exception {
            if (object instanceof WidgetInfo && object.getParent() == panel) {
                WidgetInfo widget = (WidgetInfo) object;
                // prepare "Cell" property
                Property cellProperty = (Property) widget.getArbitraryValue(this);
                if (cellProperty == null) {
                    cellProperty = getCellComplexProperty(widget);
                    widget.putArbitraryValue(this, cellProperty);
                }
                // add "Cell" property
                properties.add(cellProperty);
            }
        }

        private Property getCellComplexProperty(WidgetInfo widget) throws Exception {
            ClassLoader editorLoader = getContext().getClassLoader();
            String namespace = StringUtils.substringBefore(getElement().getTag(), ":") + ":";
            // "width"
            Property widthProperty;
            {
                ExpressionAccessor expressionAccessor = new CellExpressionAccessor(namespace, "width");
                GenericPropertyDescription propertyDescription = new GenericPropertyDescription(null, "width",
                        String.class, expressionAccessor);
                propertyDescription.setEditor(StringPropertyEditor.INSTANCE);
                propertyDescription.setConverter(StringConverter.INSTANCE);
                widthProperty = new GenericPropertyImpl(widget, propertyDescription);
            }
            // "height"
            Property heightProperty;
            {
                ExpressionAccessor expressionAccessor = new CellExpressionAccessor(namespace, "height");
                GenericPropertyDescription propertyDescription = new GenericPropertyDescription(null, "height",
                        String.class, expressionAccessor);
                propertyDescription.setEditor(StringPropertyEditor.INSTANCE);
                propertyDescription.setConverter(StringConverter.INSTANCE);
                heightProperty = new GenericPropertyImpl(widget, propertyDescription);
            }
            // "horizontalAlignment"
            Property horizontalAlignmentProperty;
            {
                StaticFieldPropertyEditor propertyEditor = new StaticFieldPropertyEditor();
                Class<?> hasHorizontalAlignmentClass = editorLoader
                        .loadClass("com.google.gwt.user.client.ui.HasHorizontalAlignment");
                propertyEditor.configure(hasHorizontalAlignmentClass,
                        new String[] { "ALIGN_LEFT", "ALIGN_CENTER", "ALIGN_RIGHT" });
                Object defaultValue = ReflectionUtils.getFieldObject(hasHorizontalAlignmentClass, "ALIGN_LEFT");
                // create property
                ExpressionAccessor expressionAccessor = new CellExpressionAccessor(namespace,
                        "horizontalAlignment");
                GenericPropertyDescription propertyDescription = new GenericPropertyDescription(null,
                        "horizontalAlignment", String.class, expressionAccessor);
                propertyDescription.setEditor(propertyEditor);
                propertyDescription.setDefaultValue(defaultValue);
                horizontalAlignmentProperty = new GenericPropertyImpl(widget, propertyDescription);
            }
            // "verticalAlignment"
            Property verticalAlignmentProperty;
            {
                StaticFieldPropertyEditor propertyEditor = new StaticFieldPropertyEditor();
                Class<?> hasVerticalAlignmentClass = editorLoader
                        .loadClass("com.google.gwt.user.client.ui.HasVerticalAlignment");
                propertyEditor.configure(hasVerticalAlignmentClass,
                        new String[] { "ALIGN_TOP", "ALIGN_MIDDLE", "ALIGN_BOTTOM" });
                Object defaultValue = ReflectionUtils.getFieldObject(hasVerticalAlignmentClass, "ALIGN_TOP");
                // create property
                ExpressionAccessor expressionAccessor = new CellExpressionAccessor(namespace,
                        "verticalAlignment");
                GenericPropertyDescription propertyDescription = new GenericPropertyDescription(null,
                        "verticalAlignment", String.class, expressionAccessor);
                propertyDescription.setEditor(propertyEditor);
                propertyDescription.setDefaultValue(defaultValue);
                verticalAlignmentProperty = new GenericPropertyImpl(widget, propertyDescription);
            }
            // create complex "Cell" property
            ComplexProperty cellProperty = new ComplexProperty("Cell", "(cell properties)");
            cellProperty.setCategory(PropertyCategory.system(7));
            cellProperty.setProperties(new Property[] { widthProperty, heightProperty,
                    horizontalAlignmentProperty, verticalAlignmentProperty });
            return cellProperty;
        }
    });
}

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

public static boolean isNumberType(String rdbType) {
    if (rdbType == null)
        return false;

    // ??  ?? ?  ?.. decimal(8) 
    if (StringUtils.contains(rdbType, "(")) {
        rdbType = StringUtils.substringBefore(rdbType, "(");
    }//from   ww w . java 2 s.c  o  m

    Integer intType = mapTypes.get(rdbType.toUpperCase());

    if (intType == null)
        return false;

    return isNumberType(intType);
}

From source file:info.magnolia.cms.beans.config.ModuleRegistration.java

/**
 * @param xmlUrl/*from  w  w w .  j  av a 2s .com*/
 * @return
 */
protected File getModuleRoot(URL xmlUrl) {
    String xmlString = xmlUrl.getFile();
    String protocol = xmlUrl.getProtocol();

    File moduleRoot = null;

    if ("jar".equals(protocol)) {
        xmlString = StringUtils.substringBefore(xmlString, ".jar!") + ".jar";
        try {
            moduleRoot = new File(new URI(xmlString));
        } catch (URISyntaxException e) {
            // should never happen
            log.error(e.getMessage(), e);
        }
    } else {
        try {
            File xmlFile = new File(new URI(xmlUrl.toString()));
            moduleRoot = xmlFile.getParentFile().getParentFile().getParentFile();
        } catch (URISyntaxException e) {
            // should never happen
            log.error(e.getMessage(), e);
        }
    }
    return moduleRoot;
}

From source file:net.mumie.coursecreator.xml.ELClassListWrapper.java

public Map getELClasses() {
    LinkedHashMap map = new LinkedHashMap();
    try {/*  w  w w  .  j  a  v  a  2 s . c  om*/
        babble("getELClasses(): constructing XPaths");
        XPath docPath = new DOMXPath("/mumie:pseudo_documents/mumie:class");
        docPath.addNamespace(StringUtils.substringBefore(XMLConstants.PREFIX_META, ":"), XMLConstants.NS_META);
        //         XPath idPath = new DOMXPath("./@id");
        //         XPath namePath = new DOMXPath("./name/*");
        XPath idPath = new DOMXPath("attribute::id");
        XPath pathPath = new DOMXPath("attribute::path");
        idPath.addNamespace(StringUtils.substringBefore(XMLConstants.PREFIX_META, ":"), XMLConstants.NS_META);
        XPath namePath = new DOMXPath("child::mumie:name/child::text()");
        namePath.addNamespace(StringUtils.substringBefore(XMLConstants.PREFIX_META, ":"), XMLConstants.NS_META);
        Element doc = classList.getDocumentElement();
        babble("getELClasses(): this is my document root: " + doc.toString());
        List li = docPath.selectNodes(doc);
        babble("getELClasses(): got back a list which "
                + (li == null ? "is null" : "has " + li.size() + " element(s)"));
        for (Iterator lit = li.iterator(); lit.hasNext();) {
            // FIXME(2): the loop body might use a minor code cleanup
            babble("getELClasses(): looping through nodes...");
            Object node = lit.next();
            //Object theID = idPath.selectSingleNode(node);
            Object thePath = pathPath.selectSingleNode(node);
            Object theName = namePath.selectSingleNode(node);
            String theNameStr = (theName instanceof Text ? ((Text) theName).getNodeValue() : "---");
            //Integer theNewId = (theID instanceof Attr ? Integer.valueOf(((Attr)theID).getValue()) : new Integer(XMLConstants.UNDEFINED_ID));
            String theNewPath = (thePath instanceof Attr ? ((Attr) thePath).getValue() : "/");
            babble("getELClasses(): Will put (" + theNewPath //theID.toString() 
                    + ",\"" + theNameStr + "\") into the map.");
            map.put(theNewPath, theNameStr);
            babble("getELClasses(): ...end of one loop");
        } // end of for (Iterator lit = li.iterator(); lit.hasNext();)       
    } catch (Exception ex) {
        CCController.dialogErrorOccured("ELClassListWrapper: Exception", "ELClassListWrapper: Exception: " + ex,
                JOptionPane.ERROR_MESSAGE);

        return null;
    } // end of try-catch
    return map;
}

From source file:com.opengamma.util.rest.RestUtils.java

private static void decode(MutableFudgeMsg msg, String key, String value) {
    if (key.contains(".")) {
        String key1 = StringUtils.substringBefore(key, ".");
        String key2 = StringUtils.substringAfter(key, ".");
        MutableFudgeMsg subMsg = msg.ensureSubMessage(key1, null);
        decode(subMsg, key2, value);//  w  w w.  j av  a  2 s .c o m
    } else {
        msg.add(key, value);
    }
}

From source file:com.netflix.explorers.AppConfigGlobalModelContext.java

@Inject
public AppConfigGlobalModelContext(@Named("explorerAppName") String appName) {
    final String propertiesFileName = appName + "-explorers-app.properties";

    try {/*from  w  w w  . j av a2  s.co  m*/
        ConfigurationManager.loadPropertiesFromResources(propertiesFileName);
    } catch (IOException e) {
        LOG.error(String.format(
                "Exception loading properties file - %s, Explorers application may not work correctly ",
                propertiesFileName));
    }

    AbstractConfiguration configuration = ConfigurationManager.getConfigInstance();

    environmentName = configuration.getString(PROPERTY_ENVIRONMENT_NAME);
    currentRegion = configuration.getString(PROPERTY_CURRENT_REGION);
    applicationVersion = (String) configuration.getProperty(PROPERTY_APPLICATION_VERSION);
    applicationName = (String) configuration.getProperty(PROPERTY_APPLICATION_NAME);
    isLocal = configuration.getBoolean(PROPERTY_IS_LOCAL, false);
    homePageUrl = configuration.getString(PROPERTY_HOME_PAGE);
    defaultPort = configuration.getShort(PROPERTY_DEFAULT_PORT, (short) 8080);
    dataCenter = configuration.getString(PROPERTY_DATA_CENTER);
    defaultExplorerName = configuration.getString(PROPERTY_DEFAULT_EXPLORER);

    try {
        Iterator<String> dcKeySet = configuration.getKeys(PROPERTIES_PREFIX + ".dc");
        while (dcKeySet.hasNext()) {
            String dcKey = dcKeySet.next();
            String key = StringUtils.substringBefore(dcKey, ".");
            String attr = StringUtils.substringAfter(dcKey, ".");

            CrossLink link = links.get(key);
            if (link == null) {
                link = new CrossLink();
                links.put(key, link);
            }

            BeanUtils.setProperty(link, attr, configuration.getProperty(dcKey));
        }
    } catch (Exception e) {
        LOG.error("Exception in constructing links map ", e);
        throw new RuntimeException(e);
    }
}

From source file:com.prowidesoftware.swift.model.field.Field38G.java

/**
 * Parses the parameter value into the internal components structure.
 * Used to update all components from a full new value, as an alternative
 * to setting individual components. Previous components value is overwritten.
 * @param value complete field value including separators and CRLF
 * @since 7.8//from   w w w  . ja va  2  s  .  com
 */
@Override
public void parse(final String value) {
    init(4);
    setComponent1(SwiftParseUtils.getNumericPrefix(StringUtils.substringBefore(value, "/")));
    setComponent2(SwiftParseUtils.getAlphaSuffix(StringUtils.substringBefore(value, "/")));
    String toparse = SwiftParseUtils.getTokenSecond(value, "/");
    setComponent3(SwiftParseUtils.getNumericPrefix(toparse));
    setComponent4(SwiftParseUtils.getAlphaSuffix(toparse));
}

From source file:com.hangum.tadpole.engine.query.sql.DBSystemSchema.java

/**
 * getViewColumn/*from w w  w.j a v a  2  s. c o  m*/
 * 
 * @param userDB
 * @param tableDao
 * @return 
 * @throws TadpoleSQLManagerException
 * @throws SQLException
 */
public static List<TableColumnDAO> getViewColumnList(final UserDBDAO userDB, final TableDAO tableDao)
        throws TadpoleSQLManagerException, SQLException {
    List<TableColumnDAO> showViewColumns = new ArrayList<TableColumnDAO>();

    Map<String, String> param = new HashMap<String, String>();
    if (userDB.getDBDefine() == DBDefine.ALTIBASE_DEFAULT) {
        param.put("user", StringUtils.substringBefore(tableDao.getName(), "."));
        param.put("table", StringUtils.substringAfter(tableDao.getName(), "."));
    } else {
        param.put("db", userDB.getDb()); //$NON-NLS-1$
        param.put("schema", tableDao.getSchema_name()); //$NON-NLS-1$
        param.put("table", tableDao.getName()); //$NON-NLS-1$
    }

    SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
    showViewColumns = sqlClient.queryForList("tableColumnList", param); //$NON-NLS-1$

    // if find the keyword is add system quote.
    for (TableColumnDAO td : showViewColumns) {
        td.setSysName(SQLUtil.makeIdentifierName(userDB, td.getField()));
    }

    return showViewColumns;
}