Java Code Examples for org.apache.commons.lang.StringUtils#substringBefore()

The following examples show how to use org.apache.commons.lang.StringUtils#substringBefore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IconUtils.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
public static Icons getImageIcon(ImageDto imageDto) {
    String iconName = StringUtils.substringBefore(imageDto.getImage().getImageName(), "_");
    Icons rtIcon = Icons.NONE;
    if (PCCConstant.IMAGE_NAME_APPLICATION.equals(iconName)) {
        rtIcon = Icons.PAAS;
    } else if (PCCConstant.IMAGE_NAME_PRJSERVER.equals(iconName)) {
        rtIcon = Icons.PRJSERVER;
    } else if (PCCConstant.IMAGE_NAME_WINDOWS.equals(iconName)) {
        rtIcon = Icons.WINDOWS_APP;
    } else if ("cloudstack".equals(iconName)) {
        rtIcon = Icons.CLOUD_STACK;
    } else {
        rtIcon = Icons.fromName(iconName);
    }
    return rtIcon;
}
 
Example 2
Source File: Support.java    From DBus with Apache License 2.0 6 votes vote down vote up
public static long[] getColumnLengthAndPrecision(Column column) {
    long[] ret = new long[2];
    String data = StringUtils.substringBetween(column.getMysqlType(), "(", ")");
    String length = StringUtils.substringBefore(data, ",");
    String precision = StringUtils.substringAfter(data, ",");
    String type = StringUtils.substringBefore(column.getMysqlType(), "(").toUpperCase();
    if ("SET".equals(type) || "ENUM".equals(type)) {
        ret[0] = 0;
        ret[1] = 0;
    } else {
        if (StringUtils.isEmpty(length)) {
            ret[0] = 0;
        } else {
            ret[0] = Long.parseLong(length);
        }
        if (StringUtils.isEmpty(precision)) {
            ret[1] = 0;
        } else {
            ret[1] = Long.parseLong(precision);
        }
    }
    return ret;
}
 
Example 3
Source File: HDanywhereGenericBindingProvider.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
private void parseAndAddBindingConfig(Item item, String bindingConfigs) throws BindingConfigParseException {

        String bindingConfig = StringUtils.substringBefore(bindingConfigs, ",");
        String bindingConfigTail = StringUtils.substringAfter(bindingConfigs, ",");

        HDanywhereBindingConfig newConfig = new HDanywhereBindingConfig();
        parseBindingConfig(newConfig, item, bindingConfig);
        addBindingConfig(item, newConfig);

        while (StringUtils.isNotBlank(bindingConfigTail)) {
            bindingConfig = StringUtils.substringBefore(bindingConfigTail, ",");
            bindingConfig = StringUtils.strip(bindingConfig);
            bindingConfigTail = StringUtils.substringAfter(bindingConfig, ",");
            parseBindingConfig(newConfig, item, bindingConfig);
            addBindingConfig(item, newConfig);
        }

    }
 
Example 4
Source File: IRtransGenericBindingProvider.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Parses the and add binding config.
 *
 * @param item the item
 * @param bindingConfigs the binding configs
 * @throws BindingConfigParseException the binding config parse exception
 */
private void parseAndAddBindingConfig(Item item, String bindingConfigs) throws BindingConfigParseException {

    String bindingConfig = StringUtils.substringBefore(bindingConfigs, ",");
    String bindingConfigTail = StringUtils.substringAfter(bindingConfigs, ",");

    IRtransBindingConfig newConfig = new IRtransBindingConfig();
    parseBindingConfig(newConfig, item, bindingConfig);
    addBindingConfig(item, newConfig);

    while (StringUtils.isNotBlank(bindingConfigTail)) {
        bindingConfig = StringUtils.substringBefore(bindingConfigTail, ",");
        bindingConfig = StringUtils.strip(bindingConfig);
        bindingConfigTail = StringUtils.substringAfter(bindingConfig, ",");
        parseBindingConfig(newConfig, item, bindingConfig);
        addBindingConfig(item, newConfig);
    }
}
 
Example 5
Source File: ApplicationArchive.java    From onos with Apache License 2.0 5 votes vote down vote up
private String compactDescription(String sentence) {
    if (StringUtils.isNotEmpty(sentence)) {
        if (StringUtils.contains(sentence, ".")) {
            return StringUtils.substringBefore(sentence, ".") + ".";
        } else {
            return sentence;
        }
    }
    return sentence;
}
 
Example 6
Source File: MaintenanceUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private static <E extends MaintainableItemDefinition> MaintainableCollectionDefinition findMaintainableCollectionDefinitionHelper(Collection<E> items, String[] collectionNameParts, int collectionNameIndex) {
    if (collectionNameParts.length <= collectionNameIndex) {
        // we've gone too far down the nesting without finding it
        return null;
    }

    // we only care about the coll name, and not the index, since the coll definitions do not include the indexing characters,
    // i.e. [ and ]
    String collectionToFind = StringUtils.substringBefore(collectionNameParts[collectionNameIndex], "[");
    for (MaintainableItemDefinition item : items) {
        if (item instanceof MaintainableCollectionDefinition) {
            MaintainableCollectionDefinition collection = (MaintainableCollectionDefinition) item;
            if (collection.getName().equals(collectionToFind)) {
                // we found an appropriate coll, now we have to see if we need to recurse even more (more nested collections),
                // or just return the one we found.
                if (collectionNameIndex == collectionNameParts.length - 1) {
                    // we're at the last part of the name, so we return
                    return collection;
                } else {
                    // go deeper
                    return findMaintainableCollectionDefinitionHelper(collection.getMaintainableCollections(), collectionNameParts, collectionNameIndex + 1);
                }
            }
        }
    }
    return null;
}
 
Example 7
Source File: FinancialSystemUserServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Deprecated
protected ChartOrgHolder getOrganizationForNonFinancialSystemUser(Person person) {
    // HACK ALERT!!!!! - This is to support the original universal user table setup where the home department
    // was encoded as CAMPUS-ORG (Where campus happened to match the chart) in the original FS_UNIVERSAL_USR_T table.
    // This **REALLY** needs a new implementation
    if (person != null && person.getPrimaryDepartmentCode().contains("-")) {
        return new ChartOrgHolderImpl(StringUtils.substringBefore(person.getPrimaryDepartmentCode(), "-"), StringUtils.substringAfter(person.getPrimaryDepartmentCode(), "-"));
    }
    return null;
}
 
Example 8
Source File: JpaUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a Path from Path using property path
 * @param path the base path
 * @param propertyPath property path String like "customer.order.price"
 * @return a new Path for property
 */
@SuppressWarnings("unchecked")
public static <T> Path<T> getPath(Path<?> path, String propertyPath) {
	if (StringUtils.isEmpty(propertyPath))
		return (Path<T>) path;
	
	String name = StringUtils.substringBefore(propertyPath, PropertyUtils.PROPERTY_SEPARATOR);
	Path<?> p = path.get(name); 
	
	return getPath(p, StringUtils.substringAfter(propertyPath, PropertyUtils.PROPERTY_SEPARATOR));
	
}
 
Example 9
Source File: Support.java    From DBus with Apache License 2.0 5 votes vote down vote up
public static String getColumnType(Column column) {
    String type = column.getMysqlType().toLowerCase();
    if (type.startsWith("int(") && type.endsWith("unsigned")) {
        return "int unsigned";
    }
    return StringUtils.substringBefore(column.getMysqlType(), "(");
}
 
Example 10
Source File: WemoHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public String getWemoURL(String actionService) {
    URL descriptorURL = service.getDescriptorURL(this);
    String wemoURL = null;
    if (descriptorURL != null) {
        String deviceURL = StringUtils.substringBefore(descriptorURL.toString(), "/setup.xml");
        wemoURL = deviceURL + "/upnp/control/" + actionService + "1";
        return wemoURL;
    }
    return null;
}
 
Example 11
Source File: MaintainableXMLConversionServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private String transformSection(String xml) {

        String maintenanceAction = StringUtils.substringBetween(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">", "</" + MAINTENANCE_ACTION_ELEMENT_NAME + ">");
        xml = StringUtils.substringBefore(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">");

        try {
            xml = upgradeBONotes(xml);
            if (classNameRuleMap == null) {
                setRuleMaps();
            }

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(new InputSource(new StringReader(xml)));

            removePersonObjects(document);

            for(Node childNode = document.getFirstChild(); childNode != null;) {
                Node nextChild = childNode.getNextSibling();
                transformClassNode(document, childNode);
                childNode = nextChild;
            }

            TransformerFactory transFactory = TransformerFactory.newInstance();
            Transformer trans = transFactory.newTransformer();
            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            trans.setOutputProperty(OutputKeys.INDENT, "yes");

            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            DOMSource source = new DOMSource(document);
            trans.transform(source, result);
            xml = writer.toString().replaceAll("(?m)^\\s+\\n", "");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return xml + "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">" + maintenanceAction + "</" + MAINTENANCE_ACTION_ELEMENT_NAME + ">";
    }
 
Example 12
Source File: WemoLightHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public String getWemoURL() {
    URL descriptorURL = service.getDescriptorURL(this);
    String wemoURL = null;
    if (descriptorURL != null) {
        String deviceURL = StringUtils.substringBefore(descriptorURL.toString(), "/setup.xml");
        wemoURL = deviceURL + "/upnp/control/bridge1";
        return wemoURL;
    }
    return null;
}
 
Example 13
Source File: WemoCoffeeHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public String getWemoURL(String actionService) {
    URL descriptorURL = service.getDescriptorURL(this);
    String wemoURL = null;
    if (descriptorURL != null) {
        String deviceURL = StringUtils.substringBefore(descriptorURL.toString(), "/setup.xml");
        wemoURL = deviceURL + "/upnp/control/" + actionService + "1";
        return wemoURL;
    }
    return null;
}
 
Example 14
Source File: DisbursementVoucherForm.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Sets the payeeIdNumber attribute value.
 *
 * @param payeeIdNumber The payeeIdNumber to set.
 */
public void setPayeeIdNumber(String payeeIdNumber) {
    String separator = "-";
    if (this.isVendor() && StringUtils.contains(payeeIdNumber, separator)) {
        this.vendorHeaderGeneratedIdentifier = StringUtils.substringBefore(payeeIdNumber, separator);
        this.vendorDetailAssignedIdentifier = StringUtils.substringAfter(payeeIdNumber, separator);
    }

    this.payeeIdNumber = payeeIdNumber;
}
 
Example 15
Source File: CloudControllerUtil.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public static String getAliasFromClusterId(String clusterId) {
    return StringUtils.substringBefore(StringUtils.substringAfter(clusterId, "."), ".");
}
 
Example 16
Source File: TravelActionBase.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase#refresh(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
@SuppressWarnings("rawtypes")
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    super.refresh(mapping, form, request, response);
    TravelFormBase travelForm = (TravelFormBase) form;

    Collection<PersistableBusinessObject> rawValues = null;
    Map<String, Set<String>> segmentedSelection = new HashMap<String, Set<String>>();

    // If multiple asset lookup was used to select the assets, then....
    if (StringUtils.equals(KFSConstants.MULTIPLE_VALUE, travelForm.getRefreshCaller())) {
        String lookupResultsSequenceNumber = travelForm.getLookupResultsSequenceNumber();

        if (StringUtils.isNotBlank(lookupResultsSequenceNumber)) {
            // actually returning from a multiple value lookup
            Set<String> selectedIds = SpringContext.getBean(SegmentedLookupResultsService.class).retrieveSetOfSelectedObjectIds(lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId());
            for (String selectedId : selectedIds) {
                String selectedObjId = StringUtils.substringBefore(selectedId, ".");
                String selectedMonthData = StringUtils.substringAfter(selectedId, ".");

                if (!segmentedSelection.containsKey(selectedObjId)) {
                    segmentedSelection.put(selectedObjId, new HashSet<String>());
                }
                segmentedSelection.get(selectedObjId).add(selectedMonthData);
            }
            // Retrieving selected data from table.
            LOG.debug("Asking segmentation service for object ids " + segmentedSelection.keySet());
            rawValues = SpringContext.getBean(SegmentedLookupResultsService.class).retrieveSelectedResultBOs(lookupResultsSequenceNumber, segmentedSelection.keySet(), HistoricalTravelExpense.class, GlobalVariables.getUserSession().getPerson().getPrincipalId());
            List<ImportedExpense> newImportedExpenses = ExpenseUtils.convertHistoricalToImportedExpense((List) rawValues, travelForm.getTravelDocument());
            AddImportedExpenseEvent event = new AddImportedExpenseEvent();
            for (ImportedExpense newImportedExpense : newImportedExpenses) {
                travelForm.setNewImportedExpenseLine(newImportedExpense);
                event.update(null, travelForm);
            }
            if (rawValues != null && rawValues.size() > 0) {
                this.save(mapping, travelForm, request, response);
                KNSGlobalVariables.getMessageList().add(TemKeyConstants.INFO_TEM_IMPORT_DOCUMENT_SAVE);
            }
        }
    }

    // set wire charge message in form
    ((TravelFormBase)form).setWireChargeMessage(retrieveWireChargeMessage());

    final String refreshCaller = ((KualiForm)form).getRefreshCaller();
    if (!StringUtils.isBlank(refreshCaller)) {
        final TravelDocument document = ((TravelFormBase)form).getTravelDocument();

        if (TemConstants.TRAVELER_PROFILE_DOC_LOOKUPABLE.equals(refreshCaller)) {
            performRequesterRefresh(document, (TravelFormBase)form, request);
        }
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
 
Example 17
Source File: DataObjectMetaDataServiceImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
protected DataObjectRelationship getDataObjectRelationship(RelationshipDefinition ddReference, Object dataObject,
        Class<?> dataObjectClass, String attributeName, String attributePrefix, boolean keysOnly,
        boolean supportsLookup, boolean supportsInquiry) {
    DataObjectRelationship relationship = null;

    // if it is nested then replace the data object and attributeName with the
    // sub-refs
    if (PropertyAccessorUtils.isNestedOrIndexedProperty(attributeName)) {
        if (ddReference != null) {
            if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) {
                relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference,
                        attributePrefix, keysOnly);

                return relationship;
            }
        }

        // recurse down to the next object to find the relationship
        String localPrefix = StringUtils.substringBefore(attributeName, ".");
        String localAttributeName = StringUtils.substringAfter(attributeName, ".");
        if (dataObject == null) {
            try {
                dataObject = KRADUtils.createNewObjectFromClass(dataObjectClass);
            } catch (RuntimeException e) {
                // found interface or abstract class, just swallow exception and return a null relationship
                return null;
            }
        }

        Object nestedObject = ObjectPropertyUtils.getPropertyValue(dataObject, localPrefix);
        Class<?> nestedClass = null;
        if (nestedObject == null) {
            nestedClass = ObjectPropertyUtils.getPropertyType(dataObject, localPrefix);
        } else {
            nestedClass = nestedObject.getClass();
        }

        String fullPrefix = localPrefix;
        if (StringUtils.isNotBlank(attributePrefix)) {
            fullPrefix = attributePrefix + "." + localPrefix;
        }

        relationship = getDataObjectRelationship(nestedObject, nestedClass, localAttributeName, fullPrefix,
                keysOnly, supportsLookup, supportsInquiry);

        return relationship;
    }

    // non-nested reference, get persistence relationships first
    int maxSize = Integer.MAX_VALUE;

    // try persistable reference first
    if (getPersistenceStructureService().isPersistable(dataObjectClass)) {
        Map<String, DataObjectRelationship> rels = getPersistenceStructureService().getRelationshipMetadata(
                dataObjectClass, attributeName, attributePrefix);
        if (rels.size() > 0) {
            for (DataObjectRelationship rel : rels.values()) {
                if (rel.getParentToChildReferences().size() < maxSize) {
                    if (classHasSupportedFeatures(rel.getRelatedClass(), supportsLookup, supportsInquiry)) {
                        maxSize = rel.getParentToChildReferences().size();
                        relationship = rel;
                    }
                }
            }
        }
    } else {
        ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(dataObjectClass);
        if (moduleService != null && moduleService.isExternalizable(dataObjectClass)) {
            relationship = getRelationshipMetadata(dataObjectClass, attributeName, attributePrefix);
            if ((relationship != null) && classHasSupportedFeatures(relationship.getRelatedClass(), supportsLookup,
                    supportsInquiry)) {
                return relationship;
            } else {
                return null;
            }
        }
    }

    if (ddReference != null && ddReference.getPrimitiveAttributes().size() < maxSize) {
        if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) {
            relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference, null,
                    keysOnly);
        }
    }

    return relationship;
}
 
Example 18
Source File: BundleEntry.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
public BundleEntry(JarEntry entry, InputStream is, BundleContext bundleContext) throws IOException {
    super(entry, is);
    String[] segments = entry.getName().split("\\/");
    String startStr = segments[2];
    if (segments[1].contains(".")) {
        runmode = StringUtils.substringAfter(segments[1], ".");
    } else {
        runmode = null;
    }
    start = Integer.parseInt(startStr, 10);
    log.debug("Loaded start level {}", start);
    try (JarInputStream bundleIs = new JarInputStream(new ByteArrayInputStream(this.getContents()))) {

        Manifest manifest = bundleIs.getManifest();
        Attributes attributes = manifest.getMainAttributes();

        if (attributes.getValue(BUNDLE_SYMBOLIC_NAME).contains(";")) {
            symbolicName = StringUtils.substringBefore(attributes.getValue(BUNDLE_SYMBOLIC_NAME), ";");
        } else {
            symbolicName = attributes.getValue(BUNDLE_SYMBOLIC_NAME);
        }
        log.debug("Loaded symbolic name: {}", symbolicName);

        version = new Version(attributes.getValue("Bundle-Version"));
        log.debug("Loaded version: {}", version);
    }

    Bundle currentBundle = null;
    for (Bundle b : bundleContext.getBundles()) {
        if (b.getSymbolicName().equals(this.symbolicName)) {
            currentBundle = b;
        }
    }
    if (currentBundle != null) {
        installed = true;
        if (currentBundle.getVersion().compareTo(version) < 0) {
            updated = true;
        } else {
            updated = false;
        }
    } else {
        installed = false;
        updated = true;
    }
}
 
Example 19
Source File: PropertyUtils.java    From jdal with Apache License 2.0 4 votes vote down vote up
public static String getFirstPropertyName(String propertyPath) {
	return isNested(propertyPath) ? 
			StringUtils.substringBefore(propertyPath, PROPERTY_SEPARATOR) : propertyPath;
}
 
Example 20
Source File: AbstractValidateCodeProcessor.java    From imooc-security with Apache License 2.0 2 votes vote down vote up
/**
 * 根据请求的url获取校验码的类型
 * 
 * @param request
 * @return
 */
private ValidateCodeType getValidateCodeType(ServletWebRequest request) {
	String type = StringUtils.substringBefore(getClass().getSimpleName(), "CodeProcessor");
	return ValidateCodeType.valueOf(type.toUpperCase());
}