This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.jcr.jackrabbit.usermanager-2.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-jackrabbit-usermanager.git
commit 7f905a7ab07f96f1e83e2d7d851938e41b5d3156 Author: Eric Norman <enor...@apache.org> AuthorDate: Sun Aug 8 15:31:36 2010 +0000 SLING-1578 reduce code duplication between post servlet and usermanager git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/jackrabbit-usermanager@983427 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 4 + .../usermanager/impl/helper/DateParser.java | 141 ------------ .../usermanager/impl/helper/RequestProperty.java | 256 --------------------- .../impl/post/AbstractAuthorizablePostServlet.java | 4 +- .../usermanager/impl/post/CreateGroupServlet.java | 2 +- .../usermanager/impl/post/CreateUserServlet.java | 2 +- .../usermanager/impl/post/UpdateGroupServlet.java | 2 +- .../usermanager/impl/post/UpdateUserServlet.java | 2 +- 8 files changed, 10 insertions(+), 403 deletions(-) diff --git a/pom.xml b/pom.xml index 86f2168..ef4f7b7 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,10 @@ <Private-Package> org.apache.sling.jackrabbit.usermanager.impl.* </Private-Package> + <Embed-Dependency> + org.apache.sling.servlets.post;inline="org/apache/sling/servlets/post/impl/helper/RequestProperty* + |org/apache/sling/servlets/post/impl/helper/DateParser*" + </Embed-Dependency> </instructions> </configuration> </plugin> diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/helper/DateParser.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/helper/DateParser.java deleted file mode 100644 index e67c5df..0000000 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/helper/DateParser.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.jackrabbit.usermanager.impl.helper; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; - -import javax.jcr.Value; -import javax.jcr.ValueFactory; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Takes a string representation of a time-date string and tries for parse it - * using different formats. - */ -public class DateParser { - - /** - * default log - */ - private static final Logger log = LoggerFactory.getLogger(DateParser.class); - - /** - * lits of formats - */ - private final List<DateFormat> formats = new LinkedList<DateFormat>(); - - /** - * Registers a format string to the list of internally checked ones. Uses - * the {@link SimpleDateFormat}. - * - * @param format format as in {@link SimpleDateFormat} - * @throws IllegalArgumentException if the format is not valid. - */ - public void register(String format) { - register(new SimpleDateFormat(format, Locale.US)); - } - - /** - * Registers a date format to the list of internally checked ones. - * - * @param format date format - */ - public void register(DateFormat format) { - formats.add(format); - } - - /** - * Parses the given source string and returns the respective calendar - * instance. If no format matches returns <code>null</code>. - * <p/> - * Note: method is synchronized because SimpleDateFormat is not. - * - * @param source date time source string - * @return calendar representation of the source or <code>null</code> - */ - public synchronized Calendar parse(String source) { - for (DateFormat fmt : formats) { - try { - Date d = fmt.parse(source); - if (log.isDebugEnabled()) { - log.debug("Parsed " + source + " using " + fmt + " into " - + d); - } - Calendar c = Calendar.getInstance(); - c.setTime(d); - return c; - } catch (ParseException e) { - if (log.isDebugEnabled()) { - log.debug("Failed parsing " + source + " using " + fmt); - } - } - } - return null; - } - - /** - * Parses the given source strings and returns the respective calendar - * instances. If no format matches for any of the sources returns - * <code>null</code>. - * <p/> - * Note: method is synchronized because SimpleDateFormat is not. - * - * @param sources date time source strings - * @return calendar representations of the source or <code>null</code> - */ - public synchronized Calendar[] parse(String sources[]) { - Calendar ret[] = new Calendar[sources.length]; - for (int i = 0; i < sources.length; i++) { - if ((ret[i] = parse(sources[i])) == null) { - return null; - } - } - return ret; - } - - /** - * Parses the given source strings and returns the respective jcr date value - * instances. If no format matches for any of the sources returns - * <code>null</code>. - * <p/> - * Note: method is synchronized because SimpleDateFormat is not. - * - * @param sources date time source strings - * @param factory the value factory - * @return jcr date value representations of the source or <code>null</code> - */ - public synchronized Value[] parse(String sources[], ValueFactory factory) { - Value ret[] = new Value[sources.length]; - for (int i = 0; i < sources.length; i++) { - Calendar c = parse(sources[i]); - if (c == null) { - return null; - } - ret[i] = factory.createValue(c); - } - return ret; - } -} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/helper/RequestProperty.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/helper/RequestProperty.java deleted file mode 100644 index 8a99c1d..0000000 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/helper/RequestProperty.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.jackrabbit.usermanager.impl.helper; - -import org.apache.sling.api.request.RequestParameter; -import org.apache.sling.api.resource.ResourceUtil; -import org.apache.sling.servlets.post.SlingPostConstants; - -/** - * This is a copy of the class from 'org.apache.sling.servlets.post.impl.helper' - * which is not exported. Encapsulates all infos from the respective request - * parameters that are needed to create the repository property - */ -public class RequestProperty { - - private static final RequestParameter[] EMPTY_PARAM_ARRAY = new RequestParameter[0]; - - public static final String DEFAULT_IGNORE = SlingPostConstants.RP_PREFIX - + "ignore"; - - public static final String DEFAULT_NULL = SlingPostConstants.RP_PREFIX - + "null"; - - private final String path; - - private final String name; - - private final String parentPath; - - private RequestParameter[] values; - - private String[] stringValues; - - private String typeHint; - - private boolean hasMultiValueTypeHint; - - private RequestParameter[] defaultValues = EMPTY_PARAM_ARRAY; - - private boolean isDelete; - - private String repositoryResourcePath; - - private boolean isRepositoryResourceMove; - - public RequestProperty(String path) { - assert path.startsWith("/"); - this.path = ResourceUtil.normalize(path); - this.parentPath = ResourceUtil.getParent(path); - this.name = ResourceUtil.getName(path); - } - - public String getTypeHint() { - return typeHint; - } - - public boolean hasMultiValueTypeHint() { - return this.hasMultiValueTypeHint; - } - - public void setTypeHintValue(String typeHint) { - if (typeHint != null && typeHint.endsWith("[]")) { - this.typeHint = typeHint.substring(0, typeHint.length() - 2); - this.hasMultiValueTypeHint = true; - } else { - this.typeHint = typeHint; - this.hasMultiValueTypeHint = false; - } - } - - public String getPath() { - return path; - } - - public String getName() { - return name; - } - - public String getParentPath() { - return parentPath; - } - - public boolean hasValues() { - return values != null; - } - - public RequestParameter[] getValues() { - return values; - } - - public void setValues(RequestParameter[] values) { - this.values = values; - } - - public RequestParameter[] getDefaultValues() { - return defaultValues; - } - - public void setDefaultValues(RequestParameter[] defaultValues) { - if (defaultValues == null) { - this.defaultValues = EMPTY_PARAM_ARRAY; - } else { - this.defaultValues = defaultValues; - } - } - - public boolean isFileUpload() { - return !values[0].isFormField(); - } - - /** - * Checks if this property provides any values. this is the case if one of - * the values is not empty or if the default handling is not 'ignore' - * - * @return <code>true</code> if this property provides values - */ - public boolean providesValue() { - // should void double creation of string values - String[] sv = getStringValues(); - if (sv == null) { - // is missleading return type. but means that property should not - // get auto-create values - return true; - } - for (String s : sv) { - if (!s.equals("")) { - return true; - } - } - return false; - } - - /** - * Returns the assembled string array out of the provided request values and - * default values. - * - * @return a String array or <code>null</code> if the property needs to be - * removed. - */ - public String[] getStringValues() { - if (stringValues == null) { - if (values.length > 1) { - // TODO: how the default values work for MV props is not very - // clear - stringValues = new String[values.length]; - for (int i = 0; i < stringValues.length; i++) { - stringValues[i] = values[i].getString(); - } - } else { - String value = values[0].getString(); - if (value.equals("")) { - if (defaultValues.length == 1) { - String defValue = defaultValues[0].getString(); - if (defValue.equals(DEFAULT_IGNORE)) { - // ignore means, do not create empty values - return new String[0]; - } else if (defValue.equals(DEFAULT_NULL)) { - // null means, remove property if exist - return null; - } - value = defValue; - } - } - stringValues = new String[] { value }; - } - } - return stringValues; - } - - /** - * Specifies whether this property should be deleted before any new content - * is to be set according to the values stored. - * - * @param isDelete <code>true</code> if the repository item described by - * this is to be deleted before any other operation. - */ - public void setDelete(boolean isDelete) { - this.isDelete = isDelete; - } - - /** - * Returns <code>true</code> if the repository item described by this is to - * be deleted before setting new content to it. - */ - public boolean isDelete() { - return isDelete; - } - - /** - * Sets the path of the repository item from which the content for this - * property is to be copied or moved. The path may be relative in which case - * it will be resolved relative to the absolute path of this property. - * - * @param sourcePath The path of the repository item to get the content from - * @param isMove <code>true</code> if the source content is to be moved, - * otherwise the source content is copied from the repository - * item. - */ - public void setRepositorySource(String sourcePath, boolean isMove) { - - // make source path absolute - if (!sourcePath.startsWith("/")) { - sourcePath = getParentPath() + "/" + sourcePath; - sourcePath = ResourceUtil.normalize(sourcePath); - } - - this.repositoryResourcePath = sourcePath; - this.isRepositoryResourceMove = isMove; - } - - /** - * Returns <code>true</code> if the content of this property is to be set by - * moving content from another repository item. - * - * @see #getRepositorySource() - */ - public boolean hasRepositoryMoveSource() { - return isRepositoryResourceMove; - } - - /** - * Returns <code>true</code> if the content of this property is to be set by - * copying content from another repository item. - * - * @see #getRepositorySource() - */ - public boolean hasRepositoryCopySource() { - return getRepositorySource() != null && !hasRepositoryMoveSource(); - } - - /** - * Returns the absolute path of the repository item from which the content - * for this property is to be copied or moved. - * - * @see #hasRepositoryCopySource() - * @see #hasRepositoryMoveSource() - * @see #setRepositorySource(String, boolean) - */ - public String getRepositorySource() { - return repositoryResourcePath; - } -} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java index fccf282..315f636 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java @@ -44,8 +44,8 @@ import org.apache.sling.api.servlets.HtmlResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.apache.sling.api.wrappers.SlingRequestPaths; import org.apache.sling.commons.osgi.OsgiUtil; -import org.apache.sling.jackrabbit.usermanager.impl.helper.DateParser; -import org.apache.sling.jackrabbit.usermanager.impl.helper.RequestProperty; +import org.apache.sling.servlets.post.impl.helper.DateParser; +import org.apache.sling.servlets.post.impl.helper.RequestProperty; import org.apache.sling.jackrabbit.usermanager.impl.resource.AuthorizableResourceProvider; import org.apache.sling.servlets.post.Modification; import org.apache.sling.servlets.post.SlingPostConstants; diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java index 5a63b07..5a24c84 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java @@ -28,7 +28,7 @@ import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.servlets.HtmlResponse; -import org.apache.sling.jackrabbit.usermanager.impl.helper.RequestProperty; +import org.apache.sling.servlets.post.impl.helper.RequestProperty; import org.apache.sling.jackrabbit.usermanager.impl.resource.AuthorizableResourceProvider; import org.apache.sling.jcr.base.util.AccessControlUtil; import org.apache.sling.servlets.post.Modification; diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java index f983d15..c5f102d 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java @@ -28,7 +28,7 @@ import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.servlets.HtmlResponse; -import org.apache.sling.jackrabbit.usermanager.impl.helper.RequestProperty; +import org.apache.sling.servlets.post.impl.helper.RequestProperty; import org.apache.sling.jackrabbit.usermanager.impl.resource.AuthorizableResourceProvider; import org.apache.sling.jcr.api.SlingRepository; import org.apache.sling.jcr.base.util.AccessControlUtil; diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java index c4ed8f2..e9de57c 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java @@ -27,7 +27,7 @@ import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceNotFoundException; import org.apache.sling.api.servlets.HtmlResponse; -import org.apache.sling.jackrabbit.usermanager.impl.helper.RequestProperty; +import org.apache.sling.servlets.post.impl.helper.RequestProperty; import org.apache.sling.jackrabbit.usermanager.impl.resource.AuthorizableResourceProvider; import org.apache.sling.servlets.post.Modification; diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java index a65dfbd..cf908a3 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java @@ -27,7 +27,7 @@ import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceNotFoundException; import org.apache.sling.api.servlets.HtmlResponse; -import org.apache.sling.jackrabbit.usermanager.impl.helper.RequestProperty; +import org.apache.sling.servlets.post.impl.helper.RequestProperty; import org.apache.sling.jackrabbit.usermanager.impl.resource.AuthorizableResourceProvider; import org.apache.sling.servlets.post.Modification; -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.