Java Code Examples for org.apache.commons.lang3.StringUtils.startsWithAny()

The following are Jave code examples for showing how to use startsWithAny() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: JuniperBotJ   File: BlurImageController.java   View Source Code Vote up 8 votes
@RequestMapping(value = "/blur", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> blur(@RequestParam("source") String sourceUrl, HttpServletResponse response) {
    if (!StringUtils.startsWithAny(sourceUrl, ALLOWED_PREFIX)) {
        return ResponseEntity.badRequest().build();
    }

    String hash = DigestUtils.sha1Hex(sourceUrl);

    try {
        ImageInfo info = readCached(hash);
        if (info == null) {
            info = renderImage(sourceUrl);
            if (info != null) {
                saveCached(hash, info);
            }
        }
        if (info != null) {
            return ResponseEntity.ok()
                    .contentLength(info.contentLength)
                    .contentType(MediaType.IMAGE_JPEG)
                    .body(new InputStreamResource(info.inputStream));
        }
    } catch (IOException e) {
        // fall down
    }
    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
 
Example 2
Project: AEM   File: AEMConfigurationProviderImpl.java   View Source Code Vote up 6 votes
private Map<String, InertProperty> getNodePropertiesMap(
        Node node,
        Map<String, InertProperty> propsMap,
        String propertyPrefix) throws Exception {
    NodeIterator nodeIterator = node.getNodes();
    while (nodeIterator.hasNext()) {
        Node childNode = nodeIterator.nextNode();
        String childNodePropertyPrefix = propertyPrefix + childNode.getName() + DOT;
        getNodePropertiesMap(childNode, propsMap, childNodePropertyPrefix);
    }

    //add properties to map
    PropertyIterator props = node.getProperties();
    while (props.hasNext()) {
        InertProperty property = new InertProperty(props.nextProperty());
        if (!StringUtils.startsWithAny(property.name(), RESERVED_SYSTEM_NAME_PREFIXES)) {
            propsMap.put(propertyPrefix + property.name(), property);
        }
    }
    return propsMap;
}
 
Example 3
Project: JahiaDF   File: PropertyUtils.java   View Source Code Vote up 6 votes
/**
 * Takes an Iterator properties and turns it into map.
 *
 * @param properties This is a list of Iterator Properties
 * @param ignoreSystemNames This is a boolean value to whether ignore system names
 * @param renderContext A renderContext object
 * @param resource A resource object
 * @param ignoreSystemNames A boolean flag indicating if systems names should be ignored
 * @return content This is a list of Objects of Property
 * @throws Exception
 */
public static Map<String, Object> propsToMap(
        Iterator properties,
        RenderContext renderContext,
        Resource resource,
        boolean ignoreSystemNames)
        throws Exception {
    Map<String, Object> content = new JSONObject();
    while (properties.hasNext()) {
        Property property = (Property) properties.next(); // This is required so we can take any kind of Iterator, not just PropertyIterator
        String propertyName = property.getName();
        if (ignoreSystemNames && StringUtils.startsWithAny(propertyName, RESERVED_SYSTEM_NAME_PREFIXES))
            continue;
        if (property.getType() == (PropertyType.WEAKREFERENCE)) {
            content.put(propertyName, resolveReference(property, renderContext, resource));
        } else {
            content.put(propertyName, distill(property));
        }
    }
    return content;
}
 
Example 4
Project: AEM   File: AddAllResourceContentPropertiesContextProcessor.java   View Source Code Vote up 5 votes
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
        throws ProcessException {
    try {
        SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
        Resource resource = request.getResource();
        Map<String, Object> content = new HashMap<>();
        if (resource != null) {
            Node node = resource.adaptTo(Node.class);
            if (node != null) {
                String componentContentId = DigestUtils.md5Hex(resource.getPath());
                content.put(XK_CONTENT_ID_CP, componentContentId);
                Map<String, Object> propsMap = propsToMap(node.getProperties());
                for (String propertyName : propsMap.keySet()) {
                    if (!StringUtils.startsWithAny(propertyName, RESERVED_SYSTEM_NAME_PREFIXES)) {
                        content.put(propertyName, propsMap.get(propertyName));
                    }
                }
                content.put(ID, DigestUtils.md5Hex(resource.getPath()));
            } else {
                // the resource doesn't exist so we clear the content
                content.clear();
            }
        } else {
            content.put(XK_CONTENT_ID_CP, "_NONE");
        }
        content.put(PATH, resource.getPath());
        content.put(NAME, resource.getName());
        contentModel.set(RESOURCE_CONTENT_KEY, content);
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
Example 5
Project: AEM   File: PropertyUtils.java   View Source Code Vote up 5 votes
/**
 * Takes an Iterator properties and turns it into map.
 *
 * @param properties This is a list of Iterator Properties
 * @param ignoreSystemNames This is a boolean value to whether ignore system names
 * @return content This is a list of Objects of Property
 * @throws Exception
 */
public static Map<String, Object> propsToMap(Iterator properties, boolean ignoreSystemNames)
        throws Exception {
    Map<String, Object> content = new JSONObject();
    while (properties.hasNext()) {
        Property property = (Property) properties.next(); // This is required so we can take any kind of Iterator, not just PropertyIterator
        String propertyName = property.getName();
        if (ignoreSystemNames && StringUtils.startsWithAny(propertyName, RESERVED_SYSTEM_NAME_PREFIXES))
            continue;
        content.put(property.getName(), distill(property));
    }
    return content;
}
 
Example 6
Project: solo-spring   File: Callstacks.java   View Source Code Vote up 5 votes
/**
 * Prints call stack with the specified logging level.
 * 
 * @param logLevel
 *            the specified logging level
 * @param carePackages
 *            the specified packages to print, for example,
 *            ["org.b3log.latke", "org.b3log.solo"], {@code null} to care
 *            nothing
 * @param exceptablePackages
 *            the specified packages to skip, for example, ["com.sun",
 *            "java.io", "org.b3log.solo.filter"], {@code null} to skip
 *            nothing
 */
public static void printCallstack(final String[] carePackages, final String[] exceptablePackages) {
	final Throwable throwable = new Throwable();
	final StackTraceElement[] stackElements = throwable.getStackTrace();

	if (null == stackElements) {
		logger.warn("Empty call stack");

		return;
	}

	final StringBuilder stackBuilder = new StringBuilder("CallStack [").append(SoloConstant.LINE_SEPARATOR);

	for (int i = 1; i < stackElements.length; i++) {
		final String stackElemClassName = stackElements[i].getClassName();

		if (!StringUtils.startsWithAny(stackElemClassName, carePackages)
				|| StringUtils.startsWithAny(stackElemClassName, exceptablePackages)) {
			continue;
		}
		stackBuilder.append("    [className=").append(stackElements[i].getClassName()).append(", fileName=")
				.append(stackElements[i].getFileName()).append(", lineNumber=")
				.append(stackElements[i].getLineNumber()).append(", methodName=")
				.append(stackElements[i].getMethodName()).append(']').append(SoloConstant.LINE_SEPARATOR);
	}
	stackBuilder.append("], full depth [").append(stackElements.length).append("]");

	logger.info(stackBuilder.toString());
}
 
Example 7
Project: cyberduck   File: MantaSession.java   View Source Code Vote up 5 votes
protected boolean isUserWritable(final MantaObject object) {
    final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath());
    return StringUtils.startsWithAny(
        object.getPath(),
        account.getAccountPublicRoot().getAbsolute(),
        account.getAccountPrivateRoot().getAbsolute());
}
 
Example 8
Project: JahiaDF   File: AddAllResourceContentPropertiesContextProcessor.java   View Source Code Vote up 5 votes
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)throws ProcessException {
    try {
        Map<String, Object> content = new HashMap<>();
        Resource resource = (Resource) executionContext.get(JAHIA_RESOURCE);
        RenderContext renderContext = (RenderContext) executionContext.get(JAHIA_RENDER_CONTEXT);

        if (resource != null) {
            Node node = resource.getNode();
            if (node != null) {
                String componentContentId = DigestUtils.md5Hex(resource.getPath());
                content.put(XK_CONTENT_ID_CP, componentContentId);
                Map<String, Object> propsMap = PropertyUtils.propsToMap(
                        node.getProperties(), renderContext, resource);
                for (String propertyName : propsMap.keySet()) {
                    if (!StringUtils.startsWithAny(propertyName, RESERVED_SYSTEM_NAME_PREFIXES)) {
                        content.put(propertyName, propsMap.get(propertyName));
                    }
                }
                content.put(ID, DigestUtils.md5Hex(resource.getPath()));
                content.put(JCR_NODE_UUID,node.getIdentifier());
            } else {
                // the resource doesn't exist so we clear the content
                content.clear();
            }
        } else {
            content.put(XK_CONTENT_ID_CP, "_NONE");
        }

        content.put(PATH, resource.getPath());
        content.put(NAME, resource.getNode().getName());
        contentModel.set(RESOURCE_CONTENT_KEY, content);

    } catch (Exception e) {
        LOG.error("DANTA Exception: "+e.getMessage(),e);
        throw new ProcessException(e);
    }
}
 
Example 9
Project: JahiaDF   File: PropertyUtils.java   View Source Code Vote up 5 votes
/**
 * Takes an Iterator properties and turns it into map.
 *
 * @param properties This is a list of Iterator Properties
 * @param ignoreSystemNames This is a boolean value to whether ignore system names
 * @return content This is a list of Objects of Property
 * @throws Exception
 */
public static Map<String, Object> propsToMap(Iterator properties, boolean ignoreSystemNames)
        throws Exception {
    Map<String, Object> content = new JSONObject();
    while (properties.hasNext()) {
        Property property = (Property) properties.next(); // This is required so we can take any kind of Iterator, not just PropertyIterator
        String propertyName = property.getName();
        if (ignoreSystemNames && StringUtils.startsWithAny(propertyName, RESERVED_SYSTEM_NAME_PREFIXES))
            continue;
        content.put(property.getName(), distill(property));
    }
    return content;
}
 
Example 10
Project: GameResourceBot   File: Commands.java   View Source Code Vote up 4 votes
private static List<StockType> getTargetStockTypes(Scanner scanner, Message message,
        String operation) {
    Locale locale = getResponseLocale(message);
    List<StockType> stockTypes = new ArrayList<>();
    List<String> unknownStockTypes = new ArrayList<>();
    List<String> inputNames = new ArrayList<>();
    while (scanner.hasNext()) {
        String next = scanner.next();
        boolean groupStart = StringUtils.startsWithAny(next, "\"", "\'");
        if (!groupStart) {
            inputNames.add(next);
        } else {
            StringBuilder buffer = new StringBuilder(next);
            boolean groupEnd = false;
            while (scanner.hasNext() && !groupEnd) {
                next = scanner.next();
                groupEnd = StringUtils.endsWithAny(next, "\"", "\'");
                buffer.append(" ");
                buffer.append(next);
            }
            buffer.deleteCharAt(0);
            buffer.deleteCharAt(buffer.length() - 1);
            inputNames.add(buffer.toString());
        }
    }
    for (String inputName : inputNames) {
        try {
            // may throws IllegalArgumentException if there is no
            String key = Resource.getItemKey(inputName, locale);
            Optional<StockType> stockOpt = getStockTypeDao().findByKey(key);
            if (!stockOpt.isPresent()) {
                unknownStockTypes.add(inputName);
            } else {
                stockTypes.add(stockOpt.get());
            }
        } catch (Exception e) {
            unknownStockTypes.add(inputName);
        }
    }
    if (!unknownStockTypes.isEmpty()) {
        String msg = String.format(Resource.getString("GROUP_UNKNOWN_TYPE", locale),
                unknownStockTypes.toString());
        Speaker.err(message, msg);
    }
    return stockTypes;
}
 
Example 11
Project: cyberduck   File: MantaSession.java   View Source Code Vote up 4 votes
protected boolean isWorldReadable(final MantaObject object) {
    final MantaAccountHomeInfo accountHomeInfo = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath());
    return StringUtils.startsWithAny(
        object.getPath(),
        accountHomeInfo.getAccountPublicRoot().getAbsolute());
}
 
Example 12
Project: JahiaDF   File: PageContentModelToJSONServlet.java   View Source Code Vote up 4 votes
@Override
public ActionResult doExecute(HttpServletRequest request, RenderContext renderContext, Resource resource,
                              JCRSessionWrapper session, Map<String, List<String>> parameters,
                              URLResolver urlResolver) throws Exception {

    JSONObject filteredContentMap = new JSONObject();
    final HttpServletResponse response = renderContext.getResponse();

    try {
        View view = null;
        if ( resource.getNode() != null && resource.getNode().getPrimaryNodeType() != null &&
                StringUtils.startsWithAny(resource.getNode().getPrimaryNodeType().getName(),
                        LIST_TEMPLATE_OPTION_TYPES) ){
            view = JahiaUtils.resolveTemplateResourceView(request, resource, renderContext);
            // Set view in the request since the view is needed by the contentModelFactoryService service
            request.setAttribute(JAHIA_SCRIPT_VIEW, view);
        }
        if (view != null) {
            TemplateContentModel templateContentModel = (TemplateContentModel)
                    contentModelFactoryService.getContentModel(request, response, renderContext, resource);

            boolean clientAccessible =
                    (Boolean) templateContentModel.get(CONFIG_PROPERTIES_KEY + DOT + XK_CLIENT_ACCESSIBLE_CP);

            if (clientAccessible) {
                // get list of contexts
                Configuration configuration = configurationProvider.getFor(view);

                Collection<String> props = configuration.asStrings(XK_CLIENT_MODEL_PROPERTIES_CP, Mode.MERGE);
                String[] contexts = props.toArray(new String[0]);

                // get content model json with the XK_CLIENT_MODEL_PROPERTIES_CP contexts
                filteredContentMap = templateContentModel.toJSONObject(contexts);

                // add component id
                String componentContentId = DigestUtils.md5Hex(resource.getPath());
                filteredContentMap.put(XK_CONTENT_ID_CP, componentContentId);
            }

            // add component list with clientaccessible as true on the resource page
            filteredContentMap.put(PAGE_COMPONENT_RESOURCE_LIST_AN, getComponentList(
                    resource, request, response, renderContext));
        }
    } catch (Exception ew) {

        throw new ServletException(ew);
    }

    response.setContentType(SERVER_RESPONSE_CONTENT_TYPE);
    response.getWriter().write( filteredContentMap.toString() );

    return ActionResult.OK;
}
 
Example 13
Project: spring-boot-starter-dynamic-datasource   File: DataSourceAspect.java   View Source Code Vote up 2 votes
/**
 * 判断是否为读库
 * 
 * @param methodName
 * @return
 */
private Boolean isSlave(String methodName) {
    // 方法名以query、find、get开头的方法名走从库
    return StringUtils.startsWithAny(methodName, getSlaveMethodStart());
}