Skip to content

Instantly share code, notes, and snippets.

@rotty3000
Last active December 26, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rotty3000/7198775 to your computer and use it in GitHub Desktop.
Save rotty3000/7198775 to your computer and use it in GitHub Desktop.
example
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.sample.portlet;
import aQute.bnd.annotation.component.Component;
import java.io.IOException;
import java.io.PrintWriter;
import javax.portlet.GenericPortlet;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* @author Raymond Augé
*/
@Component(
immediate=true,
properties={
"javax.portlet.display-name=Sample OSGi Portlet One",
"javax.portlet.name=SampleOSGiPortletOne"
},
provide={Portlet.class, SampleOSGiPortlet_One.class}
)
public class SampleOSGiPortlet_One extends GenericPortlet {
@Override
public void render(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
PrintWriter writer = response.getWriter();
writer.println("Sample OSGi Portlet One!");
writer.flush();
writer.close();
}
}
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.sample.configurationaction;
import aQute.bnd.annotation.component.Activate;
import aQute.bnd.annotation.component.Component;
import aQute.bnd.annotation.component.Deactivate;
import aQute.bnd.annotation.component.Reference;
import com.liferay.portal.kernel.portlet.ConfigurationAction;
import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
import com.liferay.portal.kernel.portlet.ResourceServingConfigurationAction;
import com.liferay.portal.model.Portlet;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* @author Raymond Augé
*/
@Component(
immediate=true,
properties={
"javax.portlet.name=SampleOSGiPortletOne"
},
provide={
ConfigurationAction.class, ResourceServingConfigurationAction.class
}
)
public class SampleOSGiPortlet_OneConfigurationAction
extends DefaultConfigurationAction {
@Activate
protected void activate() {
System.out.println(this + " activated!");
}
@Deactivate
protected void deactivate() {
System.out.println(this + " deactivated!");
}
@Override
public String render(
PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse)
throws Exception {
return "/o/SampleOSGiPortletOne/blah.jsp";
}
@Reference(
target="(javax.portlet.name=SampleOSGiPortletOne)",
optional=false
)
protected void setPortlet(Portlet portlet) {
System.out.println("Got it! " + portlet);
}
protected void unsetPortlet(Portlet portlet) {
System.out.println("Done! " + portlet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment