
com.adobe.aemds.guide.progressive.GuideProgressiveField Maven / Gradle / Ivy
package com.adobe.aemds.guide.progressive;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.aemds.guide.utils.GuideContainerThreadLocal;
import com.adobe.aemds.guide.utils.GuideFragmentHolder;
import com.adobe.aemds.guide.utils.NodeStructureUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import java.io.StringWriter;
/**
* Class representing a field present inside a guide
* progressive section
*/
public class GuideProgressiveField {
private String id;
private String path;
private String prefixId;
private ResourceResolver resourceResolver;
public GuideProgressiveField(String id, String path, String prefixId,ResourceResolver resourceResolver){
this.id = id;
this.path = path;
this.prefixId = prefixId;
this.resourceResolver = resourceResolver;
}
/**
* Returns the JSON representaion of the guide progressive field
* @return
*/
public String convertToJSON() {
StringWriter jsonStringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(jsonStringWriter);
try {
jsonWriter.object();
jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_SECTION_ID).value(this.getId());
jsonWriter.key("path").value(this.getPath());
jsonWriter.key("prefixId").value(this.getPrefixId());
jsonWriter.endObject();
} catch (JSONException ex) {
throw new GuideException(ex.getMessage(), ex);
}
return jsonStringWriter.toString();
}
/**
* Returns the id of the progressive field
* @return
*/
public String getId(){
return id;
}
/**
* Returns the path of the progressive field
* @return
*/
public String getPath() {
return path;
}
public String getPrefixId() {
return prefixId;
}
// Stores the previous fragment prefix id
private String fragRefPreviousPrefixID = null;
/**
* @todo: This has to be moved from bean to Util class
*/
public void getMarkedFragmentPrefixId(){
GuideFragmentHolder guideFragmentHolder = GuideContainerThreadLocal.getGuideFragmentHolder();
if(guideFragmentHolder != null) {
fragRefPreviousPrefixID = guideFragmentHolder.getFragPrefixID();
}
GuideContainerThreadLocal.setGuideFragmentHolder(prefixId, null, null,null);
}
/**
* @todo: This has to be moved from bean to Util class
*/
public void getUnmarkedFragmentPrefixId(){
GuideContainerThreadLocal.setGuideFragmentHolder(fragRefPreviousPrefixID, null, null,null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy