Skip to content

Commit 39e63f0

Browse files
committed
Created new template type/template, Updated Language Toggle, Restructure packages, Multiple CSS fixes
1 parent f5646f6 commit 39e63f0

File tree

160 files changed

+2745
-531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+2745
-531
lines changed

source/core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.adobe.acs</groupId>
2222
<artifactId>adobeuxp</artifactId>
23-
<version>0.0.1-SNAPSHOT</version>
23+
<version>0.2.0-SNAPSHOT</version>
2424
<relativePath>../pom.xml</relativePath>
2525
</parent>
2626
<artifactId>adobeuxp.core</artifactId>
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,23 @@
1212
package com.adobe.acs.adobeuxp.wcm.core.components.models;
1313

1414
import java.io.Serializable;
15-
1615
import javax.inject.Inject;
1716
import javax.jcr.Node;
18-
1917
import org.apache.sling.api.resource.Resource;
2018
import org.apache.sling.models.annotations.Model;
2119
import org.apache.sling.models.annotations.Optional;
2220
import org.apache.sling.models.annotations.injectorspecific.Self;
2321
import org.slf4j.Logger;
2422
import org.slf4j.LoggerFactory;
25-
2623
import com.adobe.cq.wcm.core.components.models.ListItem;
2724

2825

2926
@Model(adaptables = Resource.class)
30-
public class CustomListItemModel implements ListItem, Serializable {
27+
public class CustomListItem implements ListItem, Serializable {
3128

3229
private static final long serialVersionUID = 1L;
3330

34-
private static final Logger LOGGER = LoggerFactory.getLogger(CustomListItemModel.class);
31+
private static final Logger LOGGER = LoggerFactory.getLogger(CustomListItem.class);
3532

3633
@Self
3734
private Node node;
@@ -49,7 +46,7 @@ public class CustomListItemModel implements ListItem, Serializable {
4946
private String url;
5047

5148

52-
public CustomListItemModel(){
49+
public CustomListItem(){
5350
//nothing
5451
}
5552
@Override
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2020 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
package com.adobe.acs.adobeuxp.wcm.core.components.models;
13+
14+
import org.osgi.annotation.versioning.ConsumerType;
15+
16+
@ConsumerType
17+
public interface DetectLanguageForms {
18+
19+
default String getLang(){
20+
throw new UnsupportedOperationException();
21+
}
22+
23+
default boolean isSelector(){
24+
throw new UnsupportedOperationException();
25+
}
26+
27+
default String getActionURL(){
28+
throw new UnsupportedOperationException();
29+
}
30+
default String getLabel(){
31+
throw new UnsupportedOperationException();
32+
}
33+
}

source/core/src/main/java/com/adobe/acs/adobeuxp/wcm/core/components/models/HeaderModel.java

Lines changed: 0 additions & 100 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.adobe.acs.adobeuxp.wcm.core.components.models;
2+
3+
public interface LanguageNavigationLabel {
4+
5+
String getSubtitle();
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.osgi.annotation.versioning.ConsumerType;
1515

1616
@ConsumerType
17-
public interface QuickSearchModel {
17+
public interface QuickSearch {
1818
default String getActionURL(){
1919
throw new UnsupportedOperationException();
2020
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
Copyright 2020 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
package com.adobe.acs.adobeuxp.wcm.core.components.models.impl;
13+
14+
import java.util.Arrays;
15+
import java.util.List;
16+
import java.util.Locale;
17+
import java.util.MissingResourceException;
18+
19+
import org.apache.commons.lang3.StringUtils;
20+
import org.apache.sling.api.SlingHttpServletRequest;
21+
import org.apache.sling.api.resource.Resource;
22+
import org.apache.sling.api.resource.ResourceResolver;
23+
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
24+
import org.apache.sling.models.annotations.Exporter;
25+
import org.apache.sling.models.annotations.Model;
26+
import org.apache.sling.models.annotations.Via;
27+
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
28+
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
29+
import org.apache.sling.models.annotations.injectorspecific.Self;
30+
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
31+
import org.apache.sling.models.annotations.via.ResourceSuperType;
32+
import org.jetbrains.annotations.NotNull;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
35+
36+
import com.adobe.cq.export.json.ExporterConstants;
37+
import com.adobe.cq.wcm.core.components.models.ExperienceFragment;
38+
import com.day.cq.wcm.api.Page;
39+
40+
import lombok.experimental.Delegate;
41+
42+
43+
@Model(adaptables = { Resource.class,
44+
SlingHttpServletRequest.class }, adapters = ExperienceFragment.class, resourceType = CustomExperienceFragmentImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
45+
46+
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
47+
48+
public class CustomExperienceFragmentImpl implements ExperienceFragment {
49+
private static final Logger LOGGER = LoggerFactory.getLogger(CustomExperienceFragmentImpl.class);
50+
51+
public static final String RESOURCE_TYPE = "adobeuxp/components/content/experiencefragment";
52+
public static final String AF_ACCEPT_LANG_PARAM = "afAcceptLang";
53+
public static final String AF_FORMS_LOCATION = "/content/forms/af";
54+
public static final String LANG_REGEX = "(\\/([\\w]{2})-([\\w]{2})\\/)|(\\/([\\w]{2})\\/)";
55+
56+
@Self
57+
@Via(type = ResourceSuperType.class)
58+
@Delegate(excludes = DelegationExclusion.class)
59+
private ExperienceFragment delegate;
60+
61+
@Self
62+
private SlingHttpServletRequest request;
63+
64+
@SlingObject
65+
private ResourceResolver resourceResolver;
66+
67+
@ScriptVariable(injectionStrategy = InjectionStrategy.OPTIONAL)
68+
private Page currentPage;
69+
70+
@Override
71+
public String getLocalizedFragmentVariationPath() {
72+
73+
try {
74+
if(StringUtils.startsWith(currentPage.getPath(), AF_FORMS_LOCATION) ) {
75+
String fragmentVariationPath = request.getResource().getValueMap().get(ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, String.class);
76+
String lng = getLanguageParameter();
77+
LOGGER.debug("Language {}", lng);
78+
if(StringUtils.isNoneEmpty(fragmentVariationPath) && lng!=null) {
79+
LOGGER.debug("Current Page: {} FragmentVariationPath: {} Language: {}",currentPage.getPath(),fragmentVariationPath,lng);
80+
fragmentVariationPath = StringUtils.replaceFirst(fragmentVariationPath, LANG_REGEX, "/"+lng+"/");
81+
if(resourceExists(fragmentVariationPath)) {
82+
return fragmentVariationPath;
83+
}
84+
85+
}
86+
}
87+
} catch (Exception e) {
88+
LOGGER.error(e.getMessage());
89+
}
90+
return delegate.getLocalizedFragmentVariationPath();
91+
}
92+
93+
@NotNull
94+
private String getLanguageParameter() {
95+
96+
return java.util.Optional.ofNullable(
97+
java.util.Optional.ofNullable(request.getParameter(AF_ACCEPT_LANG_PARAM))
98+
.orElseGet(()->java.util.Optional.ofNullable(getLanguageSelector())
99+
.orElse(null)))
100+
.orElse(null);
101+
}
102+
103+
private String getLanguageSelector() {
104+
if(request.getRequestPathInfo().getSelectors().length > 0) {
105+
List<String> selectors = Arrays.asList(request.getRequestPathInfo().getSelectors());
106+
107+
if(isValid(parseLocale(selectors.get(0)))) {
108+
return selectors.get(0);
109+
}
110+
}
111+
return null;
112+
}
113+
114+
private Locale parseLocale(String locale) {
115+
String[] parts = locale.split("_");
116+
switch (parts.length) {
117+
case 3: return new Locale(parts[0], parts[1], parts[2]);
118+
case 2: return new Locale(parts[0], parts[1]);
119+
case 1: return new Locale(parts[0]);
120+
default: throw new IllegalArgumentException("Invalid locale: " + locale);
121+
}
122+
}
123+
124+
private boolean isValid(Locale locale) {
125+
try {
126+
return locale.getISO3Language() != null && locale.getISO3Country() != null;
127+
} catch (MissingResourceException e) {
128+
return false;
129+
}
130+
}
131+
132+
private boolean resourceExists(final String path) {
133+
return (StringUtils.isNotEmpty(path) && this.request.getResourceResolver().getResource(path) != null);
134+
}
135+
136+
private interface DelegationExclusion {
137+
String getLocalizedFragmentVariationPath();
138+
}
139+
}

0 commit comments

Comments
 (0)