Example usage for com.liferay.portal.kernel.util Validator isUrl

List of usage examples for com.liferay.portal.kernel.util Validator isUrl

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Validator isUrl.

Prototype

public static boolean isUrl(String url) 

Source Link

Document

Returns true if the string is a valid URL based on the rules in URL .

Usage

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

protected void validate(String url) throws PortalException {
    if (!Validator.isUrl(url)) {
        throw new EntryURLException();
    }/*from w ww.  j  a va  2 s  .co  m*/
}

From source file:com.liferay.dynamic.data.mapping.form.evaluator.functions.IsURLFunction.java

License:Open Source License

@Override
public Object evaluate(Object... parameters) {
    if (parameters.length != 1) {
        throw new IllegalArgumentException("One parameter is expected");
    }/*  w  w w.jav  a2 s  .c  om*/

    return Validator.isUrl(parameters[0].toString());
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java

License:Open Source License

/**
 * Adds a template with additional parameters.
 *
 * @param  userId the primary key of the template's creator/owner
 * @param  groupId the primary key of the group
 * @param  classNameId the primary key of the class name for the template's
 *         related model/*from   www. j  a  v a  2  s . co  m*/
 * @param  classPK the primary key of the template's related entity
 * @param  resourceClassNameId the primary key of the class name for
 *         template's resource model
 * @param  templateKey the unique string identifying the template
 *         (optionally <code>null</code>)
 * @param  nameMap the template's locales and localized names
 * @param  descriptionMap the template's locales and localized descriptions
 * @param  type the template's type. For more information, see
 *         DDMTemplateConstants in the dynamic-data-mapping-api module.
 * @param  mode the template's mode. For more information, see
 *         DDMTemplateConstants in the dynamic-data-mapping-api module.
 * @param  language the template's script language. For more information,
 *         see DDMTemplateConstants in the dynamic-data-mapping-api module.
 * @param  script the template's script
 * @param  cacheable whether the template is cacheable
 * @param  smallImage whether the template has a small image
 * @param  smallImageURL the template's small image URL (optionally
 *         <code>null</code>)
 * @param  smallImageFile the template's small image file (optionally
 *         <code>null</code>)
 * @param  serviceContext the service context to be applied. Can set the
 *         UUID, creation date, modification date, guest permissions, and
 *         group permissions for the template.
 * @return the template
 * @throws PortalException if a portal exception occurred
 */
@Override
public DDMTemplate addTemplate(long userId, long groupId, long classNameId, long classPK,
        long resourceClassNameId, String templateKey, Map<Locale, String> nameMap,
        Map<Locale, String> descriptionMap, String type, String mode, String language, String script,
        boolean cacheable, boolean smallImage, String smallImageURL, File smallImageFile,
        ServiceContext serviceContext) throws PortalException {

    // Template

    User user = userLocalService.getUser(userId);

    if (Validator.isNull(templateKey)) {
        templateKey = String.valueOf(counterLocalService.increment());
    } else {
        templateKey = StringUtil.toUpperCase(templateKey.trim());
    }

    script = formatScript(type, language, script);

    byte[] smallImageBytes = null;

    if (smallImage) {
        try {
            smallImageBytes = FileUtil.getBytes(smallImageFile);
        } catch (IOException ioe) {
        }

        if ((smallImageBytes == null) || Validator.isUrl(smallImageURL)) {
            smallImage = false;
        }
    }

    validate(groupId, classNameId, templateKey, nameMap, script, smallImage, smallImageURL, smallImageFile,
            smallImageBytes);

    long templateId = counterLocalService.increment();

    DDMTemplate template = ddmTemplatePersistence.create(templateId);

    template.setUuid(serviceContext.getUuid());
    template.setGroupId(groupId);
    template.setCompanyId(user.getCompanyId());
    template.setUserId(user.getUserId());
    template.setUserName(user.getFullName());
    template.setVersionUserId(user.getUserId());
    template.setVersionUserName(user.getFullName());
    template.setClassNameId(classNameId);
    template.setClassPK(classPK);
    template.setResourceClassNameId(resourceClassNameId);
    template.setTemplateKey(templateKey);
    template.setVersion(DDMTemplateConstants.VERSION_DEFAULT);
    template.setNameMap(nameMap);
    template.setDescriptionMap(descriptionMap);
    template.setType(type);
    template.setMode(mode);
    template.setLanguage(language);
    template.setScript(script);
    template.setCacheable(cacheable);
    template.setSmallImage(smallImage);
    template.setSmallImageId(counterLocalService.increment());
    template.setSmallImageURL(smallImageURL);

    ddmTemplatePersistence.update(template);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addTemplateResources(template, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addTemplateResources(template, serviceContext.getModelPermissions());
    }

    // Small image

    saveImages(smallImage, template.getSmallImageId(), smallImageFile, smallImageBytes);

    // Template version

    addTemplateVersion(user, template, DDMTemplateConstants.VERSION_DEFAULT, serviceContext);

    return template;
}

From source file:com.liferay.knowledgebase.admin.importer.util.KBArticleMarkdownConverter.java

License:Open Source License

protected String buildSourceURL(String baseSourceURL, String fileEntryName) {

    if (!Validator.isUrl(baseSourceURL)) {
        return null;
    }//  w  w w .  j ava  2s.c o m

    int pos = baseSourceURL.length() - 1;

    while (pos >= 0) {
        char c = baseSourceURL.charAt(pos);

        if (c != CharPool.SLASH) {
            break;
        }

        pos--;
    }

    StringBundler sb = new StringBundler(3);

    sb.append(baseSourceURL.substring(0, pos + 1));

    if (!fileEntryName.startsWith(StringPool.SLASH)) {
        sb.append(StringPool.SLASH);
    }

    sb.append(fileEntryName);

    return sb.toString();
}

From source file:com.liferay.knowledgebase.service.impl.KBArticleLocalServiceImpl.java

License:Open Source License

protected void validateSourceURL(String sourceURL) throws PortalException {
    if (Validator.isNull(sourceURL)) {
        return;/*from  w ww. j av a 2 s .c om*/
    }

    if (!Validator.isUrl(sourceURL)) {
        throw new KBArticleSourceURLException(sourceURL);
    }
}

From source file:com.liferay.portal.settings.authentication.iam.web.internal.portlet.action.PortalSettingsIAMFormMVCActionCommand.java

License:Apache License

@Override
protected final void doValidateForm(final ActionRequest actionRequest, final ActionResponse actionResponse)
        throws Exception {

    boolean iamEnabled = getBoolean(actionRequest, "enabled");

    if (!iamEnabled) {
        return;//from   ww  w.j  av a  2 s . c  o  m
    }

    String iamConfigurationURL = getString(actionRequest, "configurationURL");
    String iamOauthAuthURL = getString(actionRequest, "oauthAuthURL");
    String iamOauthTokenURL = getString(actionRequest, "oauthTokenURL");
    String iamOpenidUserinfoURL = getString(actionRequest, "openidUserinfoURL");
    String iamOpenidJwkURL = getString(actionRequest, "openidJwkURL");

    if (Validator.isNotNull(iamConfigurationURL) && !Validator.isUrl(iamConfigurationURL)) {

        SessionErrors.add(actionRequest, "iamConfigurationURLInvalid");
    }

    if (Validator.isNotNull(iamOauthAuthURL) && !Validator.isUrl(iamOauthAuthURL)) {

        SessionErrors.add(actionRequest, "iamOauthAuthURLInvalid");
    }

    if (Validator.isNotNull(iamOauthTokenURL) && !Validator.isUrl(iamOauthTokenURL)) {

        SessionErrors.add(actionRequest, "iamOauthTokenURLInvalid");
    }

    if (Validator.isNotNull(iamOpenidUserinfoURL) && !Validator.isUrl(iamOpenidUserinfoURL)) {

        SessionErrors.add(actionRequest, "iamOpenidUserinfoURLInvalid");
    }

    if (Validator.isNotNull(iamOpenidJwkURL) && !Validator.isUrl(iamOpenidJwkURL)) {

        SessionErrors.add(actionRequest, "iamOpenidJWKURLInvalid");
    }
}

From source file:com.liferay.portlet.announcements.service.impl.AnnouncementsEntryLocalServiceImpl.java

License:Open Source License

protected void validate(String title, String content, String url) throws PortalException {

    if (Validator.isNull(title)) {
        throw new EntryTitleException();
    }/*from w  w w . j av a  2s  .  co  m*/

    if (Validator.isNull(content)) {
        throw new EntryContentException();
    }

    if (Validator.isNotNull(url) && !Validator.isUrl(url)) {
        throw new EntryURLException();
    }
}

From source file:com.liferay.portlet.portalsettings.action.EditCompanyAction.java

License:Open Source License

protected void validateCAS(ActionRequest actionRequest) throws Exception {
    boolean casEnabled = ParamUtil.getBoolean(actionRequest, "settings--" + PropsKeys.CAS_AUTH_ENABLED + "--");

    if (!casEnabled) {
        return;/*from  ww w . j  a  va  2s  . c o  m*/
    }

    String casLoginURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_LOGIN_URL + "--");
    String casLogoutURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_LOGOUT_URL + "--");
    String casServerName = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVER_NAME + "--");
    String casServerURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVER_URL + "--");
    String casServiceURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVICE_URL + "--");
    String casNoSuchUserRedirectURL = ParamUtil.getString(actionRequest,
            "settings--" + PropsKeys.CAS_NO_SUCH_USER_REDIRECT_URL + "--");

    if (!Validator.isUrl(casLoginURL)) {
        SessionErrors.add(actionRequest, "casLoginURLInvalid");
    }

    if (!Validator.isUrl(casLogoutURL)) {
        SessionErrors.add(actionRequest, "casLogoutURLInvalid");
    }

    if (Validator.isNull(casServerName)) {
        SessionErrors.add(actionRequest, "casServerNameInvalid");
    }

    if (Validator.isNotNull(casServerURL) && Validator.isNotNull(casServiceURL)) {

        SessionErrors.add(actionRequest, "casServerURLAndServiceURLConflict");
    } else if (Validator.isNull(casServerURL) && Validator.isNull(casServiceURL)) {

        SessionErrors.add(actionRequest, "casServerURLAndServiceURLNotSet");
    } else {
        if (Validator.isNotNull(casServerURL) && !Validator.isUrl(casServerURL)) {

            SessionErrors.add(actionRequest, "casServerURLInvalid");
        }

        if (Validator.isNotNull(casServiceURL) && !Validator.isUrl(casServiceURL)) {

            SessionErrors.add(actionRequest, "casServiceURLInvalid");
        }
    }

    if (Validator.isNotNull(casNoSuchUserRedirectURL) && !Validator.isUrl(casNoSuchUserRedirectURL)) {

        SessionErrors.add(actionRequest, "casNoSuchUserURLInvalid");
    }
}

From source file:com.liferay.portlet.rss.RSSPreferencesValidator.java

License:Open Source License

public void validate(PortletPreferences preferences) throws ValidatorException {

    List<String> badURLs = new ArrayList<String>();

    String[] urls = preferences.getValues("urls", new String[0]);

    for (String url : urls) {
        if (!Validator.isUrl(url)) {
            badURLs.add(url);/*w w w  .j  a  v a 2  s.co m*/
        }
    }

    if (badURLs.size() > 0) {
        throw new ValidatorException("Failed to retrieve URLs", badURLs);
    }
}

From source file:com.liferay.portlet.softwarecatalog.service.impl.SCProductEntryLocalServiceImpl.java

License:Open Source License

protected void validate(long productEntryId, String name, String type, String shortDescription, String pageURL,
        String author, String repoGroupId, String repoArtifactId, long[] licenseIds, List<byte[]> thumbnails,
        List<byte[]> fullImages) throws PortalException, SystemException {

    if (Validator.isNull(name)) {
        throw new ProductEntryNameException();
    }//from w  w w.  j av  a2 s.c o  m

    if (Validator.isNull(type)) {
        throw new ProductEntryTypeException();
    }

    if (Validator.isNull(shortDescription)) {
        throw new ProductEntryShortDescriptionException();
    }

    if (Validator.isNull(pageURL)) {
        throw new ProductEntryPageURLException();
    } else if (!Validator.isUrl(pageURL)) {
        throw new ProductEntryPageURLException();
    }

    if (Validator.isNull(author)) {
        throw new ProductEntryAuthorException();
    }

    SCProductEntry productEntry = scProductEntryPersistence.fetchByRG_RA(repoGroupId, repoArtifactId);

    if ((productEntry != null) && (productEntry.getProductEntryId() != productEntryId)) {

        throw new DuplicateProductEntryModuleIdException();
    }

    if (licenseIds.length == 0) {
        throw new ProductEntryLicenseException();
    }

    if (thumbnails.size() != fullImages.size()) {
        throw new ProductEntryScreenshotsException();
    } else {
        Iterator<byte[]> itr = thumbnails.iterator();

        while (itr.hasNext()) {
            if (itr.next() == null) {
                throw new ProductEntryScreenshotsException();
            }
        }

        itr = fullImages.iterator();

        while (itr.hasNext()) {
            if (itr.next() == null) {
                throw new ProductEntryScreenshotsException();
            }
        }
    }
}