Magnolia CMS Modules
by Devexperts![]()
dx-magnolia-ocm is a library which integrates Jackrabbit OCM with Magnolia CMS
dx-magnolia-ocm doesn't depend on Magnolia, allowing to read and write Magnolia Jackrabbit storage from external applications
Download library:
dx-magnolia-ocm-1.0.1.jar
dx-magnolia-ocm-1.0.1-sources.jar
Install it into your Maven repository:
call mvn install:install-file -DgroupId=com.devexperts.web -DartifactId=dx-magnolia-ocm -Dversion=1.0.1 -Dpackaging=jar -Dfile=dx-magnolia-ocm-1.0.1.jar -DgeneratePom=true
call mvn install:install-file -DgroupId=com.devexperts.web -DartifactId=dx-magnolia-ocm -Dversion=1.0.1 -Dpackaging=jar -Dclassifier=sources -Dfile=dx-magnolia-ocm-1.0.1-sources.jar -DgeneratePom=false
You may also put this library into external repository instead of local one.
Note: the library is going be published to publicitly available Maven repository soon, making these steps reduntant. Stay tuned.
Add the following dependency to your Maven project:
<dependency>
<groupId>com.devexperts.web</groupId>
<artifactId>dx-magnolia-ocm</artifactId>
<version>${dx-magnolia-ocm.version}</version>
</dependency>
Specify packages where OCM bean classes are searched. Add the following JVM parameter:
-Dcom.devexperts.ocm.packages=<comma separated list of packages>
Now you can use this library in your code.
All bean classes must inherit com.devexperts.ocm.BaseOCM class.
Also they must be placed in packages specified by com.devexperts.web.packages system property.
dx-magnolia-ocm uses the same rules as Jackrabbit OCM does. See
@Node(jcrType = BaseOCM.MGNL_CONTENT_NODE_TYPE)
public class FinancePlan extends BaseOCM {
public enum PricingModel {
FREE, PAID
}
@Field
private String name;
@Field
private PricingModel pricingModel;
@Field(jcrDefaultValue = "false")
private boolean active;
@Bean
private Money price;
public FinancePlan() {}
public PricingModel getPricingModel() {
return pricingModel;
}
public void setPricingModel(PricingModel pricingModel) {
this.pricingModel = pricingModel;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public boolean getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Money getPrice() {
return price;
}
public void setPrice(Money price) {
this.price = price;
}
}
Note the following:
To perform operations with OCM beans, you need com.devexperts.ocm.OCM object.
To create OCM object you need javax.jcr.Session.
In Magnolia, it can be constructed in the following way:
Session session = MgnlContext.getHierarchyManager("data").getWorkspace().getSession();
OCM ocm = new OCM(session);
Specify the workspace you need when calling getHierarchyManager method.
When you have an instance of OCM object you may perform operations on bean objects.
FinancePlan plan = new FinancePlan();
plan.setName("My plan");
plan.setMoney(new Money("10.00$"));
plan.setPricingModel(FinancePlan.PricingModel.PAID);
plan.setPath("/plans/myplan"); // Path in Jackrabbit repository
ocm.insert(plan);
ocm.save();
The library is released under GPL license. Contact us if you need this module under different license.