This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch forms-enhancements
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/forms-enhancements by this
push:
new d2353fa Fixing build error and adding test coverage
d2353fa is described below
commit d2353fa058c7366903c012b02df483f079ee26b3
Author: Dan Klco <[email protected]>
AuthorDate: Fri Jan 15 16:00:30 2021 -0500
Fixing build error and adding test coverage
---
.../core/internal/rewriter/HTML5Serializer.java | 182 ---------------------
.../internal/rewriter/Html5SerializerFactory.java | 44 -----
feature/src/main/features/cms/dependencies.json | 2 +-
.../sling/cms/reference/forms/FormConstants.java | 2 +-
.../forms/impl/actions/UpdateProfileAction.java | 32 +++-
.../main/resources/OSGI-INF/l10n/bundle.properties | 5 +-
.../impl/actions/ResetPasswordActionTest.java | 34 ++--
transformer/src/test/resources/thumbnail.png | Bin 21183 -> 20437 bytes
8 files changed, 52 insertions(+), 249 deletions(-)
diff --git
a/core/src/main/java/org/apache/sling/cms/core/internal/rewriter/HTML5Serializer.java
b/core/src/main/java/org/apache/sling/cms/core/internal/rewriter/HTML5Serializer.java
deleted file mode 100644
index 214d30e..0000000
---
a/core/src/main/java/org/apache/sling/cms/core/internal/rewriter/HTML5Serializer.java
+++ /dev/null
@@ -1,182 +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.cms.core.internal.rewriter;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
-import org.apache.sling.rewriter.ProcessingComponentConfiguration;
-import org.apache.sling.rewriter.ProcessingContext;
-import org.apache.sling.rewriter.Serializer;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-
-/**
- * Serializer for writing HTML5 compliant markup
- */
-public class HTML5Serializer implements Serializer {
-
- private static final int CHAR_EQ = 61;
-
- private static final int CHAR_GT = 62;
-
- private static final int CHAR_SP = 32;
-
- private static final int CHAR_LT = 60;
-
- private static final Set<String> emptyTags = new HashSet<>();
- static {
- emptyTags.addAll(Arrays.asList("br", "area", "link", "img", "param",
"hr", "input", "col", "base", "meta"));
- }
- private PrintWriter writer;
-
- private ConfigurationResourceResolver resolver;
-
- private Resource rewriteConfig;
-
- public HTML5Serializer(ConfigurationResourceResolver resolver) {
- this.resolver = resolver;
- }
-
- @Override
- public void characters(char[] buffer, int offset, int length) throws
SAXException {
- if (length == 0) {
- writer.flush();
- } else {
- writer.write(buffer, offset, length);
- }
- }
-
- @Override
- public void dispose() {
- // Nothing required
- }
-
- @Override
- public void endDocument() throws SAXException {
- writer.flush();
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws
SAXException {
- if (!emptyTags.contains(localName)) {
- writer.write("</");
- writer.write(qName);
- writer.write(CHAR_GT);
- }
- }
-
- @Override
- public void endPrefixMapping(String s) throws SAXException {
- // Nothing required
- }
-
- @Override
- public void ignorableWhitespace(char[] ac, int i, int j) throws
SAXException {
- // Nothing required
- }
-
- @Override
- public void init(ProcessingContext context,
ProcessingComponentConfiguration config) throws IOException {
- if (context.getWriter() == null) {
- throw new IllegalArgumentException("Failed to initialize
HTML5Serializer, null writer specified!");
- } else {
- writer = context.getWriter();
- rewriteConfig =
resolver.getResource(context.getRequest().getResource(), "site", "rewrite");
- }
- }
-
- @Override
- public void processingInstruction(String s, String s1) throws SAXException
{
- // Nothing required
- }
-
- @Override
- public void setDocumentLocator(Locator locator1) {
- // Nothing required
- }
-
- @Override
- public void skippedEntity(String s) throws SAXException {
- // Nothing required
- }
-
- @Override
- public void startDocument() throws SAXException {
- writer.println(rewriteConfig.getValueMap().get("doctype",
String.class));
- }
-
- @Override
- public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
- boolean endSlash = false;
- writer.write(CHAR_LT);
- writer.write(qName);
-
- for (int i = 0; i < atts.getLength(); i++) {
- if ("endSlash".equals(atts.getQName(i))) {
- endSlash = true;
- }
- String value = atts.getValue(i);
- if (shouldContinue(localName, atts, i)) {
- continue;
- }
- writer.write(CHAR_SP);
- writer.write(atts.getQName(i));
-
- writer.write(CHAR_EQ);
- writer.write('"');
- writer.write(value);
- writer.write('"');
- }
-
- if (endSlash) {
- writer.write("/");
- }
- writer.write(CHAR_GT);
- }
-
- private boolean shouldContinue(String localName, Attributes atts, int i) {
- if ("endSlash".equals(atts.getQName(i))) {
- return true;
- }
- if ("a".equals(localName) && "shape".equals(atts.getLocalName(i))) {
- return true;
- }
- if ("iframe".equals(localName)
- && ("frameborder".equals(atts.getLocalName(i)) ||
"scrolling".equals(atts.getLocalName(i)))) {
- return true;
- }
- if ("br".equals(localName) && ("clear".equals(atts.getLocalName(i)))) {
- return true;
- }
- if (atts.getValue(i) == null) {
- return true;
- }
- return false;
- }
-
- @Override
- public void startPrefixMapping(String s, String s1) throws SAXException {
- // Nothing required
- }
-}
diff --git
a/core/src/main/java/org/apache/sling/cms/core/internal/rewriter/Html5SerializerFactory.java
b/core/src/main/java/org/apache/sling/cms/core/internal/rewriter/Html5SerializerFactory.java
deleted file mode 100644
index ef52189..0000000
---
a/core/src/main/java/org/apache/sling/cms/core/internal/rewriter/Html5SerializerFactory.java
+++ /dev/null
@@ -1,44 +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.cms.core.internal.rewriter;
-
-import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
-import org.apache.sling.rewriter.Serializer;
-import org.apache.sling.rewriter.SerializerFactory;
-import org.osgi.framework.Constants;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-
-/**
- * This sax serializer serializes HTML5 Compliant Markup
- */
-@Component(service = SerializerFactory.class, property = {
Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
- "pipeline.type=html5-serializer" })
-public class Html5SerializerFactory implements SerializerFactory {
-
- @Reference
- private ConfigurationResourceResolver resolver;
-
- /**
- * @see org.apache.sling.rewriter.SerializerFactory#createSerializer()
- */
- @Override
- public Serializer createSerializer() {
- return new HTML5Serializer(resolver);
- }
-
-}
diff --git a/feature/src/main/features/cms/dependencies.json
b/feature/src/main/features/cms/dependencies.json
index 626b817..accfa81 100644
--- a/feature/src/main/features/cms/dependencies.json
+++ b/feature/src/main/features/cms/dependencies.json
@@ -93,7 +93,7 @@
"start-order": "15"
},
{
- "id": "org.apache.sling:org.apache.sling.rewriter:1.2.2",
+ "id": "org.apache.sling:org.apache.sling.rewriter:1.2.3-SNAPSHOT",
"start-order": "15"
},
{
diff --git
a/reference/src/main/java/org/apache/sling/cms/reference/forms/FormConstants.java
b/reference/src/main/java/org/apache/sling/cms/reference/forms/FormConstants.java
index 182dcc9..ea556ae 100644
---
a/reference/src/main/java/org/apache/sling/cms/reference/forms/FormConstants.java
+++
b/reference/src/main/java/org/apache/sling/cms/reference/forms/FormConstants.java
@@ -33,5 +33,5 @@ public class FormConstants {
public static final String PN_RESETTOKEN = "resettoken";
public static final String PN_RESETTIMEOUT = "resettimeout";
- public static final String PN_PASSWORD = "passwordw";
+ public static final String PN_PASSWORD = "password";
}
diff --git
a/reference/src/main/java/org/apache/sling/cms/reference/forms/impl/actions/UpdateProfileAction.java
b/reference/src/main/java/org/apache/sling/cms/reference/forms/impl/actions/UpdateProfileAction.java
index 4aba5cc..9374cb8 100644
---
a/reference/src/main/java/org/apache/sling/cms/reference/forms/impl/actions/UpdateProfileAction.java
+++
b/reference/src/main/java/org/apache/sling/cms/reference/forms/impl/actions/UpdateProfileAction.java
@@ -18,6 +18,7 @@ package org.apache.sling.cms.reference.forms.impl.actions;
import java.util.Arrays;
import java.util.Calendar;
+import java.util.Optional;
import java.util.Map.Entry;
import java.util.stream.Collectors;
@@ -37,26 +38,37 @@ import
org.apache.sling.cms.reference.forms.FormActionResult;
import org.apache.sling.cms.reference.forms.FormConstants;
import org.apache.sling.cms.reference.forms.FormException;
import org.apache.sling.cms.reference.forms.FormRequest;
+import org.apache.sling.cms.reference.forms.FormUtils;
import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(service = FormAction.class)
+@Designate(ocd = UpdateProfileAction.Config.class)
public class UpdateProfileAction implements FormAction {
+ public static final String DEFAULT_RESOURCE_TYPE =
"reference/components/forms/actions/updateprofile";
+
private static final Logger log =
LoggerFactory.getLogger(UpdateProfileAction.class);
+ private Config config;
+
+ public UpdateProfileAction(Config config) {
+ this.config = config;
+ }
+
@Override
public FormActionResult handleForm(Resource actionResource, FormRequest
request) throws FormException {
ResourceResolver resolver =
request.getOriginalRequest().getResourceResolver();
String userId = resolver.getUserID();
- JackrabbitSession session = (JackrabbitSession)
resolver.adaptTo(Session.class);
- if (session == null) {
- log.warn("Failed to get session for {}", userId);
- return FormActionResult.failure("Failed to get session for " +
userId);
- }
try {
+ JackrabbitSession session =
Optional.ofNullable((JackrabbitSession) resolver.adaptTo(Session.class))
+ .orElseThrow(() -> new RepositoryException("Unable to get
Jackrabbit Session"));
+
final UserManager userManager = session.getUserManager();
if (userManager.getAuthorizable(userId) == null) {
@@ -103,7 +115,15 @@ public class UpdateProfileAction implements FormAction {
@Override
public boolean handles(Resource actionResource) {
- return
"reference/components/forms/actions/updateprofile".equals(actionResource.getResourceType());
+ return FormUtils.handles(config.supportedTypes(), actionResource);
+ }
+
+ @ObjectClassDefinition(name = "%cms.reference.updateprofile.name",
description = "%cms.reference.updateprofile.description", localization =
"OSGI-INF/l10n/bundle")
+ public @interface Config {
+
+ @AttributeDefinition(name = "%cms.reference.supportedTypes.name",
description = "%cms.reference.supportedTypes.description", defaultValue = {
+ DEFAULT_RESOURCE_TYPE })
+ String[] supportedTypes() default { DEFAULT_RESOURCE_TYPE };
}
}
diff --git a/reference/src/main/resources/OSGI-INF/l10n/bundle.properties
b/reference/src/main/resources/OSGI-INF/l10n/bundle.properties
index 5b263ae..7e4b1fb 100644
--- a/reference/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ b/reference/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -71,4 +71,7 @@ cms.reference.resetpassword.name=Apache Sling CMS - Reference
Password Reset
cms.reference.requestpasswordreset.description=Form action for resetting a
user password
cms.reference.sendemail.name=Apache Sling CMS - Reference Send Email
-cms.reference.requestpasswordreset.description=Form action for sending an email
\ No newline at end of file
+cms.reference.requestpasswordreset.description=Form action for sending an email
+
+cms.reference.sendemail.name=Apache Sling CMS - Reference Update Profile
+cms.reference.requestpasswordreset.description=Form action for updating a user
profile
\ No newline at end of file
diff --git
a/reference/src/test/java/org/apache/sling/cms/reference/forms/impl/actions/ResetPasswordActionTest.java
b/reference/src/test/java/org/apache/sling/cms/reference/forms/impl/actions/ResetPasswordActionTest.java
index 3f86f86..5e8a66f 100644
---
a/reference/src/test/java/org/apache/sling/cms/reference/forms/impl/actions/ResetPasswordActionTest.java
+++
b/reference/src/test/java/org/apache/sling/cms/reference/forms/impl/actions/ResetPasswordActionTest.java
@@ -47,7 +47,6 @@ import org.apache.sling.cms.reference.forms.FormConstants;
import org.apache.sling.cms.reference.forms.FormException;
import org.apache.sling.cms.reference.forms.FormRequest;
import org.apache.sling.cms.reference.forms.impl.FormRequestImpl;
-import
org.apache.sling.cms.reference.forms.impl.actions.RequestPasswordResetAction.Config;
import org.apache.sling.servlethelpers.MockSlingHttpServletRequest;
import org.apache.sling.testing.resourceresolver.MockResource;
import org.junit.Before;
@@ -119,39 +118,47 @@ public class ResetPasswordActionTest {
@Test
public void testHandleForm() throws FormException {
- RequestPasswordResetAction action = new
RequestPasswordResetAction(factory, null);
+ ResetPasswordAction action = new ResetPasswordAction(factory, null);
FormRequest request = new FormRequestImpl(new
MockSlingHttpServletRequest(resolver), null, null);
- request.getFormData().put("email", "[email protected]");
+ request.getFormData().put("email", "[email protected]");
request.getFormData().put(FormConstants.PN_RESETTOKEN, "123");
request.getFormData().put(FormConstants.PN_PASSWORD, "password1");
- Resource actionResource = new MockResource("/content",
Collections.emptyMap(), null);
+ Resource actionResource = new MockResource("/content",
+
Collections.singletonMap(RequestPasswordResetAction.PN_RESETTIMEOUT, 1000000),
null);
FormActionResult result = action.handleForm(actionResource, request);
assertTrue(result.isSucceeded());
}
- @Test
- public void testNoUser() throws FormException {
+ public FormActionResult doReset(String email) throws FormException {
ResetPasswordAction action = new ResetPasswordAction(factory, null);
FormRequest request = new FormRequestImpl(new
MockSlingHttpServletRequest(resolver), null, null);
- request.getFormData().put("email", "[email protected]");
+ request.getFormData().put("email", email);
Resource actionResource = new MockResource("/content",
Collections.singletonMap(RequestPasswordResetAction.PN_RESETTIMEOUT, 2), null);
- FormActionResult result = action.handleForm(actionResource, request);
- assertFalse(result.isSucceeded());
+ return action.handleForm(actionResource, request);
+
+ }
+
+ @Test
+ public void testInvalid() throws FormException {
+
+ assertFalse(doReset("[email protected]").isSucceeded());
+ assertFalse(doReset("[email protected]").isSucceeded());
+ assertFalse(doReset("[email protected]").isSucceeded());
}
@Test
public void testHandles() throws FormException {
- Config config = new Config() {
+ ResetPasswordAction action = new ResetPasswordAction(null, new
ResetPasswordAction.Config() {
@Override
public Class<? extends Annotation> annotationType() {
return null;
@@ -159,12 +166,11 @@ public class ResetPasswordActionTest {
@Override
public String[] supportedTypes() {
- return new String[] {
RequestPasswordResetAction.DEFAULT_RESOURCE_TYPE };
+ return new String[] {
ResetPasswordAction.DEFAULT_RESOURCE_TYPE };
}
- };
- RequestPasswordResetAction action = new
RequestPasswordResetAction(null, config);
+ });
Resource validResource = Mockito.mock(Resource.class);
-
Mockito.when(validResource.getResourceType()).thenReturn(RequestPasswordResetAction.DEFAULT_RESOURCE_TYPE);
+
Mockito.when(validResource.getResourceType()).thenReturn(ResetPasswordAction.DEFAULT_RESOURCE_TYPE);
assertTrue(action.handles(validResource));
Resource inValidResource = Mockito.mock(Resource.class);
diff --git a/transformer/src/test/resources/thumbnail.png
b/transformer/src/test/resources/thumbnail.png
index 62cf067..f38c3a4 100644
Binary files a/transformer/src/test/resources/thumbnail.png and
b/transformer/src/test/resources/thumbnail.png differ