Foren

How can I store Web Content with JAVA ?

Rüdiger Kowalski, geändert vor 12 Jahren.

How can I store Web Content with JAVA ?

New Member Beiträge: 22 Beitrittsdatum: 16.08.11 Neueste Beiträge
Hi, I want to read, change and update web content out of a JSF portlet programmatically.

Reading works fine:
static public String leseWebContent(final String title) throws PortalException, SystemException
{
String content = "";
final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final long groupId = td.getScopeGroupId();
final String languageKey = fc.getExternalContext().getRequestLocale().toString();
try
{
final JournalArticle ja = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, title);
final JournalArticleDisplay jad = JournalContentUtil.getDisplay(ja.getGroupId(), ja.getArticleId(), ja.getTemplateId(), languageKey, td);
content = jad.getContent();
return content;
}
catch (final Exception ex)
{
System.out.println(ex.getMessage());
return content;
}
}

Changing by using a PrimeFaces component works fine:
<prime:editor id="edit" value="#{hilfstextController.webContent}" height="320" width="480" />
(Getter method of webContent calls method "leseWebContent()")

Updating does not work:
static public void schreibeWebContent(final String title, final String webContent) throws PortalException, SystemException
{
final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final long groupId = td.getScopeGroupId();
final String languageKey = fc.getExternalContext().getRequestLocale().toString();
try
{
final JournalArticle ja = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, title);
final JournalArticleDisplay jad = JournalContentUtil.getDisplay(ja.getGroupId(), ja.getArticleId(), ja.getTemplateId(), languageKey, td);
jad.setContent(webContent);
? ? ?
JournalArticleLocalServiceUtil.updateJournalArticle(ja);
}
catch (final Exception ex)
{
System.out.println(ex.getMessage());
}
}

JounalArticleDisplay object contains the changed content. The method "JournalArticleLocalServiceUtil.updateJournalArticle()" however expects a JournalArticle object as parameter. Does anybody know a solution for this problem?

So I'm a JAVA newbie and I'm happy about every answer.

Best regards Rüdiger
thumbnail
Nagendra Kumar Busam, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

Liferay Master Beiträge: 678 Beitrittsdatum: 07.07.09 Neueste Beiträge
Hi Rudiger,

I never worked on PrimeFaces BUT i will give my idea how you can change the same.

Anyway you are getting article by groupId & urlTitle.

	JournalArticleLocalServiceUtil.updateContent(groupId, articleId, version, content)

Here
>> content is latest content you are getting from form
>> articleId is articleId of article you got using groupId & urlTitle
>> version you may need to increment according to current version of the article - check default JournalArticle impl for ref.


Please let us know if this works for you

Thanks,
- Nagendra Kumar
Rüdiger Kowalski, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

New Member Beiträge: 22 Beitrittsdatum: 16.08.11 Neueste Beiträge
Hi Nagendra,

first of all thanks for your quick reply. I acted on your suggestion and it works fine !

But now I have the next problem. In case of missing web content, I want to create one out of my form (JSF portlet). My idea was to use JournalArticleLocalServiceUtil.addJournalArticle( article ), but I don't know how to create a article.

Maybe you can help me in this issue too?

Thanks Rüdiger
thumbnail
Nagendra Kumar Busam, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

Liferay Master Beiträge: 678 Beitrittsdatum: 07.07.09 Neueste Beiträge
I didn't get what you really mean by missing web content. Can you be elaborate a bit more on the same.
Rüdiger Kowalski, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

New Member Beiträge: 22 Beitrittsdatum: 16.08.11 Neueste Beiträge
Nagendra Kumar Busam:
I didn't get what you really mean by missing web content. Can you be elaborate a bit more on the same.

Hi Nagendra,
yes, of course. I'm developing a portlet with several input fields. Beside every field there is a button, which will show a help dialog with field depending information. This help information should be placed in a web content. So when the button is clicked for the first time and there is no matching web content, I want to create and store one.

Thanks Rüdiger
Rüdiger Kowalski, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

New Member Beiträge: 22 Beitrittsdatum: 16.08.11 Neueste Beiträge
I've got it ! emoticon

final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final ServiceContext sc = new ServiceContext();
sc.setAddCommunityPermissions(true);
sc.setAddGuestPermissions(true);
sc.setScopeGroupId(td.getScopeGroupId());
sc.setCompanyId(td.getCompanyId());
sc.setUserId(td.getUserId());
JournalArticleLocalServiceUtil.addArticle(td.getUserId(), td.getScopeGroupId(), "", true, 1.0, title, "", webContent,
	"general", "", "", 11, 24, 2011, 9, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, "", null,
	null, title.toLowerCase(), sc);

Thanks to all for your help !!!
thumbnail
Nagendra Kumar Busam, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

Liferay Master Beiträge: 678 Beitrittsdatum: 07.07.09 Neueste Beiträge
Good you got it working.

I have one question why can't you just use Language.properties file to keep you help text for your custom portlet
Rüdiger Kowalski, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

New Member Beiträge: 22 Beitrittsdatum: 16.08.11 Neueste Beiträge
Hi Nagendra,

our customer wants to create his own help information with rich text editing features. Therefore we decided to use PrimeFaces <p:editor> component for manual input and Liferay web content for storing.

As I already told you, I'm very new in Java developing and in Liferay (nearly 6 months) and I don't know how to use language properties file. Is there any documentation about this, respectively where can I find it?

Thanks Rüdiger
Oliver Bayer, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Rüdiger,

please refer to this WIKI. If you have any other questions feel free to ask again.

Greets Oli
thumbnail
Anil Sunkari, geändert vor 12 Jahren.

RE: How can I store Web Content with JAVA ?

Expert Beiträge: 427 Beitrittsdatum: 12.08.09 Neueste Beiträge
Hi Rüdiger,

Rüdiger Kowalski:
Hi Nagendra,

first of all thanks for your quick reply. I acted on your suggestion and it works fine !

But now I have the next problem. In case of missing web content, I want to create one out of my form (JSF portlet). My idea was to use JournalArticleLocalServiceUtil.addJournalArticle( article ), but I don't know how to create a article.

Maybe you can help me in this issue too?

Thanks Rüdiger


I'm not sure but still i'm giving you my idea about your query.You can try this

JournalArticle journalArticle = new JournalArticleImpl();
journalArticle.setArticleId();
""
""
etc..
JournalArticleLocalServiceUtil.addJournalArticle(journalArticle);


Thanks,
Anil Sunkari