Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions it/apps/src/main/content/META-INF/vault/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<workspaceFilter version="1.0">
<filter root="/apps/forms-core-components-it"/>
<filter root="/apps/wknd"/>
<filter root="/apps/forms-core-components-it/config"/>
<filter root="/apps/core/fd/af-clientlibs/core-forms-components-runtime-all/resources/i18n" mode="update"/>
</workspaceFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Folder"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
contentTypes="[text/html]"
enabled="{Boolean}true"
generatorType="htmlparser"
order="1"
paths="[/content]"
serializerType="htmlwriter"
transformerTypes="[custom-linkrewriter]">
<generator-htmlparser
jcr:primaryType="nt:unstructured"
includeTags="[LINK,SCRIPT]" />
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="Forms Embed Component"
componentGroup=".Sites - Content"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## This component should be deployed in the Sites' instance where we need to embed the form
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Properties"
sling:resourceType="cq/gui/components/authoring/dialog">
<content
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<text
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Forms URL - should be prefixed with abbviecloud"
name="./formsUrl"/>
</items>
</column>
</items>
</content>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<div>
<!--TODO Replace the package name of the Model -->
<div class="cmp-formsembed__item" data-sly-use.model="com.adobe.cq.forms.core.components.it.models.embed.FormsEmbed">
<div class="cmp-formsembed-widget" data-forms-url=${model.formsUrl}>

<div class="afsection">
<div data-sly-test="${wcmmode.edit}">
Your Form Will Appear Here
</div>
</div>
</div>
</div>
<div data-sly-test="${!wcmmode.edit}">
<script>
var updateElementContent = function (targetElement, newHtml) {
targetElement.innerHTML = newHtml;
Array.from(targetElement.querySelectorAll("script")).forEach(oldScriptElement => {
const newScriptElement = document.createElement("script");
Array.from(oldScriptElement.attributes).forEach(attribute => {
newScriptElement.setAttribute(attribute.name, attribute.value);
});
const scriptText = document.createTextNode(oldScriptElement.innerHTML);
newScriptElement.appendChild(scriptText);
oldScriptElement.parentNode.replaceChild(newScriptElement, oldScriptElement);
});
}
var formsUrl = document.querySelector('.cmp-formsembed-widget').getAttribute('data-forms-url');
var options = {path:formsUrl, CSS_Selector:".afsection"};
if (options.path) {
fetch(options.path, {
method: 'GET',
// You can include additional headers or data here if needed
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
var element = document.querySelector(options.CSS_Selector);
if (element) {
updateElementContent(element, data);
}
})
.catch(error => {
// Error handling
console.error('Error fetching data:', error);
});
} else {
if (typeof console !== "undefined") {
console.log("Path of Adaptive Form not specified to loadAdaptiveForm");
}
}
</script>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.adobe.cq.forms.core.components.it.models.embed;

import com.adobe.cq.wcm.core.components.models.Component;
import org.osgi.annotation.versioning.ConsumerType;

@ConsumerType
public interface FormsEmbed extends Component {

String getFormsUrl();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.adobe.cq.forms.core.components.it.models.embed;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.drew.lang.annotations.Nullable;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

@Model(
adaptables = SlingHttpServletRequest.class,
adapters = {FormsEmbed.class, ComponentExporter.class},
resourceType = FormsEmbedImpl.RESOURCE_TYPE
)
@Exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION
)
public class FormsEmbedImpl implements FormsEmbed {

// TODO replace app name
public static final String RESOURCE_TYPE = "forms-core-component-it/components/formsembed";

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
protected String formsUrl;


@Override
public String getFormsUrl() {
return formsUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.adobe.cq.forms.core.components.it.service.rewriter;

import org.apache.sling.rewriter.DefaultTransformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

@Component(
service = TransformerFactory.class,
property = {
"pipeline.type=" + CustomCloudRewriterTransformer.TYPE,
}
)
public class CustomCloudRewriterTransformer implements TransformerFactory {

private static final Logger log = LoggerFactory.getLogger(CustomCloudRewriterTransformer.class);

public static final String TYPE = "custom-linkrewriter";

public static final String PATH_PREFIX = "custom";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace prefix path with your path



@Reference
private CustomRunModeConfiguration customRunModeConfiguration;

@Override
public TransformerImpl createTransformer() {
String runmode = customRunModeConfiguration.getRunMode();
log.info("current runmode = " + runmode);
boolean isPublish = "publish".equals(runmode);
return new TransformerImpl(isPublish);
}


protected static class TransformerImpl extends DefaultTransformer {

private final boolean isPublish;

public TransformerImpl(boolean isPublish) {
super();
this.isPublish = isPublish;
}

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
AttributesImpl mutableAttributes =
attributes instanceof AttributesImpl ? (AttributesImpl) attributes
: null;
if (isPublish) {
if ("link".equals(localName)) {
mutableAttributes = mutableAttributes != null ? mutableAttributes : new AttributesImpl(attributes);
replaceLinkPaths(mutableAttributes);
} else if ("script".equals(localName)) {
mutableAttributes = mutableAttributes != null ? mutableAttributes : new AttributesImpl(attributes);
replaceScriptPaths(mutableAttributes);
}
}
super.startElement(uri, localName, qName,
mutableAttributes != null ? mutableAttributes : attributes);
}

private void replaceLinkPaths(AttributesImpl attributes) {
if (attributes.getIndex("href") >= 0 && attributes.getIndex("rel") >= 0) {
String rel = attributes.getValue("rel");
if ("preload stylesheet".equals(rel) || "stylesheet".equals(rel)) {
int index = attributes.getIndex("href");
String value = attributes.getValue(index);
setAttribute(attributes, index, addPathPrefix(value));
}
}
}

private void replaceScriptPaths(AttributesImpl attributes) {
if (attributes.getIndex("src") >= 0) {
int index = attributes.getIndex("src");
String value = attributes.getValue(index);
setAttribute(attributes, index, addPathPrefix(value));
}
}

private String addPathPrefix(String url) {
return "/" + PATH_PREFIX + url;
}

private void setAttribute(AttributesImpl attributes, int index, String value) {
String attrUri = attributes.getURI(index);
String attrLocalName = attributes.getLocalName(index);
String attrQName = attributes.getQName(index);
String attrType = attributes.getType(index);
attributes.setAttribute(index, attrUri, attrLocalName, attrQName, attrType, value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.adobe.cq.forms.core.components.it.service.rewriter;

import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

@ObjectClassDefinition(name = "Runmode OSGI Configuration", description = "Configuration for Identifying Run Mode")
public @interface CustomRunMode {

@AttributeDefinition(name = "Runmode Information", description = "Runmode Info")
String runmode_info() default "default";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.adobe.cq.forms.core.components.it.service.rewriter;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;

@Component(
service = CustomRunModeConfiguration.class
)
public class CustomRunModeConfiguration {

private CustomRunMode customRunMode;

@Activate
public void activate(CustomRunMode customRunMode) {
this.customRunMode = customRunMode;
}

public String getRunMode() {
if (customRunMode != null) {
return customRunMode.runmode_info();
} else {
return "default";
}
}
}
Loading