How to get content from Liferay structure - liferay

I need help getting JournalArticle content of a particular content structure in liferay.
I want to display the field values of the Journal content. This content has a custom structure.

The structure is essentially an xml structure of the type DYNAMIC ELEMENT tags.
The value of the different fields of the structure that defines the article can be extracted using the format
Document document = SaxReaderUtil.read(journalarticle.getContent());
Node fieldNode = document.selectSingleNode("/root/dynamic-element[#name='Field-Name']/dynamic-content");
String brand = brandNode.getText();
`
See more at http://liferayiseasy.blogspot.com.ng/2015/08/get-web-contentjournal-article-fields.html

Related

Is there any API in Liferay that can be used to create the Journal Article XML Content?

We have a custom Journal Article web content structure and currently using the hard-coded XML content to populate the structure with the values. Is there any API in Liferay that we can make use in order to create the XML content for Journal Article.
I guess you are looking for this guy: com.liferay.dynamic.data.mapping.util.FieldsToDDMFormValuesC‌​onverter
DDMFormValues ddmFormValues = DDMUtil.getDDMFormValues(ddmStructure.getStructureId(), ...);
Fields fields = DDMUtil.getFields(ddmStructure.getStructureId(), ddmFormValues);
String content = _journalConverter.getContent(ddmStructure, fields)

Orchard CMS: Content Item Get Field By Name in View

I have created a custom content type (via the admin UI) that consists mostly of text fields. I know how to position the fields using zones and Placement.info but for simplicity I would like to use a single view template and to just arrange the fields by name instead of having to use Placement.info. Is there a good way to reference the fields by name from the content item in my MVC view?
So for example, I have a template named Content-MyContentType-Detail.cshtml. Instead of the generic
#Display(Model.Content)
I would like to be able to do something like
#Display(...MyField...)
#Display(...MyOtherField...)
Is there a way to explicitly render a field by name that is associated with my content item?
You can use Shape Tracing module to view model properties and how to get access to content parts.
Then in your template you can use something like this:
<h3>#Model.ContentItem.TitlePart.Title - £#Model.ContentItem.Product.Fields[1].Value</h3>
<p>#Model.ContentItem.BodyPart.Text</p>
If you don't just want to access the field's properties, but rather would like its shape rendered in-place, but like it would be when using placement (i.e. using the existing template), then read this article, which describes how to do direct rendering without placement: http://weblogs.asp.net/bleroy/archive/2013/02/13/easy-content-templates-for-orchard-take-2.aspx

Orchard - Query Custom Fields in Content Item

I have a Content Type "News" with custom field "NewsDate" (DateTimeField) and "Active" (BooleanField)
Now I'm need to get 3 active atimes order desc by NewsDate
Get all news, make them toList() and from there manipulate the data is not a solution.
P.S. I need to do something like:
var items = contentManager
.Query(Entities[PageType.Press])
.OrderByDescending<CommonPartRecord, DateTime?>(record => record.PublishedUtc)
.Slice(0, 3);
but instead of PublishedUTC use my custom field "NewsDate" and add Active == true, However it is not possible due to Orchard architecture of storing custom data in a separate field as XML data.
UPDATED:
In a nutshell I want to generate from code behind the following Query:
DECLARE #temp as TABLE(id int, xmldata xml)
INSERT #temp VALUES(1,'<Data><News><NewsDate>07/14/2011 11:42:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link></News></Data>')
INSERT #temp VALUES(2,'<Data><News><NewsDate>07/11/2011 12:11:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link></News></Data>')
INSERT #temp VALUES(3,'<Data><News><NewsDate>02/21/2012 16:56:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link><NewsLink></NewsLink></News></Data>')
SELECT
TOP 3 [id],
[xmldata].value('(Data/News/NewsDate)[1]', 'datetime') as NewsDate
FROM #temp
ORDER BY NewsDate DESC
P.S. I looked through the code for DynamicContentQueryTests, however all the examples uses the Part, and in my case Fields are just in the ContentItem:
E.g. News content type contains NewsDate field (datetime field) and some parts as well
Any suggestions are greatly appreciated.
Querying fields is possible since 1.4 through Projector and underlying index tables and new APIs on Content Manager. Your simplest bet actually may be to create a projection.
To get the values of fields that have been attached directly to a Content Item, you need to first look for the Content Part with the same name as the item, which is created by Orchard. So in your case in the Parts list for each News Content Item you'll find a part called "NewsPart", and inside this the Fields property will have your NewsDate and Active fields.
However, like you say Orchard serializes the field values into XML for storage to prevent it having to change the database structure every time you add/remove a field to/from a content type. For this reason, querying and ordering by fields is not recommended because all the serialized data needs to be de-serialized for each Content Item. If you want to be able to do this, the best way is to make your own Content Part with a Content Part Record and use your own table for storage, then you can do this:
contentManager.Query<NewsPart, NewsPartRecord>()...
...and query/sort on whatever values you like.
Bertrand is correct. Check this link : http://www.davidhayden.me/blog/projector-module-in-orchard-cms. You can implement your requirements easily with Projection Module. The link will tell you the steps to do that. If you don't want a widget, you can create a page with your query too. Once the module is enabled, you will see the option to create a Projection Page in the left hand side navigation.
EDIT :
Can't you simply parse the XML? You can query your content type 'News'. Something like -
var contentItems = contentManager.Query<ContentPart>("News").Join<TitlePartRecord>().Join<AutoroutePartRecord>().Join<CommonPartRecord>().List();
Once you have that, you can access the XML data by :
foreach (var item in contentItems)
{
var contentItem = (ContentItem)item.ContentItem;
ContentItemVersionRecord contentItemRecord = contentItem.VersionRecord;
string data = contentItemRecord.Data;
//Call some function here to parse 'data' and store the object in the list.
}
'data' has the information in XML format that you need.
You can parse it and then store the objects in your list that you can order by your custom field.

Sharepoint Document Library Schema.xml Customization

Hi I am trying to add a custom field to the Schema.xml of Document library in sharepoint
here is the code that I took from a blog
In the ID i have to put the guid to do so
do I have to add my own guid or do i have to query the sharepoint database and find the guid and paste it there...
If i have to get it from sharepoint database which database and in what table I will find this information....
any help will be greatly appreciated
Thanks,
srikrishna.
This is now a duplicate post from MSDN forms
http://social.technet.microsoft.com/Forums/en-US/sharepointcustomization/thread/72df8c80-9e58-4c09-b1a6-ddfe1fb96b0a
there is a sure and safe mean :
1 - create a list with the SharePoint UI
2 - add a column to the list within the SharePoint UI
Create an applicative page that gets the schema of the list and you are done :
SPList mylist=SPContext.Current.Web.Lists["myNewList"];
string schema = mylist.SchemaXml;
schema = schema.Replace("<", "<");
schema = schema.Replace(">", ">");
string myAddedColumnSchema = mylist.Fields["MyAddedColumn"].SchemaXml;
myAddedColumnSchema = myAddedColumnSchema .Replace("<", "<");
myAddedColumnSchema = myAddedColumnSchema .Replace(">", ">");
Response.Write(schema);
Response.Write("<br>");
Response.Write("<br>"); Response.Write(myAddedColumnSchema );
Response.Write("<br>");
Response.Write("<br>");
This gives you the schema of the list with the field, and also just the field row in the list schema (of course copy the result in Visual Studio and use "Format Document" because on the web page it is just unreadable.
You cannot use this list schema by copying and pasting it in a SharePoint 2010 list Schema but you can locate the place where put the XAML correponding to your custom field.
After that you have to create a custom Content Type just for your custom field.
With SharePoint 2007 you could put a local content type corresponding to the custom field within the list schema but IT IS OVER. (I think... if someone can do it I will be pleased to be wrong ;-))
Then install the list feature with the new schema, and activate it within a site.
Then install the Content Type feature and activate it.
Then create a list based on the new schema, allow content type gestion for that list and add the new content type.
All the items based on the new content type will be allowed to use the new field.

Redefine folder structure of document library with metadata

I have a problem in my sharepoint document library structure. Currently the document library consiste of folder sub-folder structure to store a document categorywise. Now our client want to redefine this folder structure with a metadata structure.
Can any one tell me how can I use metadata instade of folder sub folder structure..?
any related articles or links will be appriciated.
Thanks
Sachin
As already stated, you need to use columns for the metadata, preferably through a new Content Type. After creating this Content Type, you need to attach it to the library and convert all documents to it. Lastly, you also need to modify the views of the library, e.g. depending on your metadata you might only want to display certain columns or filter them.
There is an excellent whitepaper from Microsoft on Content Types available here:
http://technet.microsoft.com/en-us/library/cc262729.aspx
You can also read more about content type planning on Technet:
http://technet.microsoft.com/en-us/library/cc262735.aspx
And here's some info about Views:
http://office.microsoft.com/en-us/sharepointtechnology/HA100215771033.aspx
You must define columns for the metadata fields you want to have, create a content type that includes these columns, and assign this content type to your documents.
You might also change the default view of your document library, or create a new view, to make the new metadata columns visible.

Resources