api.newsitem

News item manipulation methods

newsitem.save()

Save news item. Triggers a validation of the news item.

newsitem.replaceSource(sourceXml, [etag])

Replace the NewsML source. Will effectively replace the current article with anything in the incoming NewsML.

Param Type Default
sourceXml string
[etag] string null

newsitem.setSource()

Deprecated

Use api.newsItem.replaceSource() instead

newsitem.getGuid() ⇒ string | null

Return the GUID in the NewsItemArticle Can return null if no GUID is found in NewsItem

newsitem.setGuid(uuid)

Set news item guid (uuid)

Param Type Description
uuid string New uuid or null to clear

newsitem.getLocale() ⇒ string

Gets locale from article's idf-element. Formatted with underscore, eg. sv_SE, en_GB, nl_NL. Uses fallback languages if the article's language only uses two characters. If fallback fails, will return the configured "language"-property from writer-config.

newsitem.getLanguageParts() ⇒ Object

Gets a language parts object parsed from article's NewsML.

newsitem.setLanguage(name, languageCode, textDirection)

Sets xml:lang property on article's idf-element. Language code should be two two-character codes separated by a dash, eg. sv-SE, en-GB

Param Type Default Description
name string Plugin-id that set language
languageCode string Two two-character language-region codes, separated by a dash. eg. sv-SE, en-GB, nl-NL
textDirection string "ltr" 'ltr' or 'rtl'

newsitem.getNewsPriority() ⇒ Object

Get news priority.

Returns: Object - News priority object in JXON format

newsitem.createNewsPriority(name, newsPriority)

Create and insert a new newsPriority object into the news item content meta data. Triggers a documentChanged event to all documentChanged listeners except the plugin making the change.

Emits: event.event:DOCUMENT_CHANGED

Param Type
name string
newsPriority object

newsitem.setNewsPriority(name, newsPriority)

Set news priority.

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin making the call
newsPriority Object News priority object

newsitem.getMainChannel() ⇒ object

Get main channel (channel with attribute why="imext:main")

newsitem.getSections() ⇒ Array | *

Get Sections. Finds all the service nodes with a qCode containing imsection:

Renames @qcode to qcode so plugins doesn't have to handle

newsitem.getSection() ⇒ *

Get Section.

Find section on article if any. If no section null is returned. Note that by using this function it is presumed that there can be max one section on an article.

newsitem.getChannels() ⇒ Array

Get Channels Finds all the service nodes with a qCode containing imchn:

Renames @qcode to qcode so plugins doesn't have to handle

newsitem.updateSection(name, section)

Update Section. Removes existing section and add new. Note expects article to only allow one section.

Throws:

  • Error

Emits: event.event:DOCUMENT_CHANGED

Param Description
name Name of plugin.
section Section object to set on article.

newsitem.removeSection(name, section, muteEvent)

Removes .

Throws:

  • Error

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of plugin.
section string Section object to remove.
muteEvent boolean Optional. Mute event if set to true, only used internally.

newsitem.addChannel(name, channel, setAsMainChannel)

Add a channel as a . Renaming qcode to @qcode.

Throws:

  • Error

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of plugin
channel string Name of channel
setAsMainChannel boolean Set this channel as main channel

newsitem.removeChannel(name, channel, muteEvent)

Removes .

Throws:

  • Error

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of plugin
channel string Name of channel
muteEvent boolean Optional. Mute event if set to true, only used internally.

newsitem.getPubStatus() ⇒ Object

Get the pubStatus of document

Returns: Object - Return object with current pubStatus of document

newsitem.setPubStatus(name, pubStatus)

Set pubStatus Creates a pubStatus node in itemMeta if it not exists

Emits: event.event:DOCUMENT_CHANGED

Param Type
name string
pubStatus object

newsitem.getPubStart() ⇒ object

Get pubStart

Returns: object - Object {value: "2016-02-08T20:37:25 01:00", type: "imext:pubstart"}

newsitem.setPubStart(name, pubStart)

Set pubStart

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Plugin name
pubStart object Expect object with value property. Type is ignored. Object {value: "2016-02-08T20:37:25 01:00"}

newsitem.removePubStart(name)

Remove the node for the pubStart

Emits: event.event:DOCUMENT_CHANGED

Param
name

newsitem.getPubStop() ⇒ object

Get pubStop

newsitem.setPubStop(name, pubStop)

Set pubStop.

Emits: event.event:DOCUMENT_CHANGED

Param Type
name string
pubStop object

newsitem.removePubStop(name)

Remove the node for pubStop.

Param Type Description
name string Plugin name

newsitem.getEdNote() ⇒ String

Get editorial note from edNote element in itemMeta section.

newsitem.setEdNote(content)

Set editorial note content in edNote element in itemMeta section

Throws:

  • Error
Param Type Description
content string String content of editorial note

newsitem.getNewspilotArticleId() ⇒ *

Get Newspilot article id (if any).

newsitem.getAuthors() ⇒ *

Get all author links in itemMeta links

newsitem.getOrganisation()

Get IMID organisation and unit(s)

newsitem.removeAuthorByUUID(name, uuid)

Remove an author from newsItem.

Throws:

  • NotFoundError When no node is found by provided UUID the NotFoundError is thrown

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin
uuid string The UUID of the author to be deleted

newsitem.addAuthor(name, author)

Add an known author with a specified uuid to the newsItem

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Plugin name
author object Author object with the properties name and uuid

newsitem.addSimpleAuthor(name, author)

Add an simple/unknown author to the newsItem

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Plugin name
author object Author object with the properties name and uuid

newsitem.updateAuthorWithUUID(name, uuid, author)

Updates itemMeta > links > link[type="x-im/author"]/@name for specified uuid.

If parameter author object contains any of

  • email
  • firstName
  • lastName
  • phone
  • facebookUrl
  • twitterUrl
  • shortDescription
  • longDescription a child element, 'data', will be created and a child element to that element with the name of object field will be created, e.g. data > phone.

    Note that an existing 'data' element will be removed from link.

Param Type Description
name string Plugin name
uuid string The uuid for the author in the newsItem
author object Object containing name and, optional, fields (see above)

newsitem.updateConcept(name, conceptObject, propertyMap, triggerDocumentChanged)

Update existing concept link with new data

Emits: event.event:DOCUMENT_CHANGED Fires a documentChanged event with updated link

Param Type Default Description
name string
conceptObject object
propertyMap object
triggerDocumentChanged boolean true set to false to suppress document changed event, default is set to true

newsitem.updateRelationalLinks(relation, conceptObject, conceptNode, propertyMap)

Recursive function that will add a concepts Broader relations as links in the existing concept link

Param Type
relation string
conceptObject object
conceptNode object
propertyMap object

newsitem.updateConceptData(conceptObject, conceptNode)

Update a concept links data node

Param Type
conceptObject object
conceptNode object

newsitem.createExtendedGeoLink(relatedGeoPolygons)

Attach link with related-geo data to article meta

Param Type
relatedGeoPolygons object

newsitem.removeAuthorByTitle(name, authorName)

Remove an author from newsItem

Throws:

  • NotFoundError When no node is found by provided authorName the NotFoundError is thrown

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin
authorName string The name of the author to be deleted

newsitem.getLinksByType(name, types, subject) ⇒ *

Generic method to retrieve links with a certain type from the itemMeta section

Param Type Description
name Plugin name
types array Types of links to select
subject string optional Which kind of subject to select, defaults to "subject"

Example

import {api} from 'writer'
api.newsItem.getLinksByType(this.name, [ 'x-im/organisation', 'x-im/person', 'x-im/topic' ], "subject")

newsitem.getTags(types) ⇒ *

Get tags (link elements from the itemMeta section)

Returns: * - Return array of tags in JSON or null if no links was found
Example:: { rel: "subject", title: "Dalarna", type: "x-im/category", uuid: "03d22994-91e4-11e5-8994-feff819cdc9f" }

Param Description
types An array of types considered being tags. Example ['x-im/person, x-im/channel']

newsitem.addTag(name, tag)

Adds a tag to itemMeta > links section in newsItem

The format used is identical to the search response provided by concepts backend

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string The name of the plugin
tag object Must containt title, type and uuid

Example

{
    "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
    "name": ["2016 Eurovision Song Contest"],
    "type": ["story"],
    "typeCatalog": ["imnat"],
    "imType": ["x-im/story"],
    "inputValue": "s"
}

newsitem.updateTag(name, uuid, tag)

Update a tag in itemMeta > links section

Throws:

  • NotFoundError When no node is found by provided UUID the NotFoundError is thrown

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string The name of the plugin
uuid string The UUID of the link element
tag object The tag, same format as concept backend provides in search {"name": [ "2016 Eurovision Song Contest" ], "type": [ "story" ], "typeCatalog": [ "imnat" ], "imType": [ "x-im/story" ] }

newsitem.removeLinkByUUID(name, uuid)

Removes a link in itemMeta links by providing an UUID

Emits: event.event:DOCUMENT_CHANGED

Param Description
name The name of the plugin calling the method
uuid The uuid of the link to be removed

newsitem.removeLinkByURI(name, uri)

Removes a link in itemMeta links by providing an URI

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string The name of the plugin calling the method
uri string The URI of the link to be removed

newsitem.removeAllLinksByType(name, type)

Removes all links in itemMeta links by providing a type

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string of the plugin calling the method
type string of the links to be removed

newsitem.removeLinkByUUIDAndRel(name, uuid, rel)

Remove a link from itemMeta links section by type and rel attributes

Emits: event.event:DOCUMENT_CHANGED

Param Type
name string
uuid string
rel string

newsitem.removeLinkContentMetaByTypeAndRel(name, type, rel)

Remove a link from contentMeta links section by type and rel attributes

Emits: event.event:DOCUMENT_CHANGED

Param Type
name string
type string
rel string

newsitem.removeLinkContentMetaByTypeAndMatchingFilter(name, type, filter)

Removes links from contentMeta links section that matches provided filter and type.

The filter function is called for each link mathing the type. If the filter returns 'true', the link is removed.

Param Type Description
name string The name of the plugin performing the remove.
type string The link type that should be part of removal
filter function A function that gets the a link as a argument. Should return 'true' if the link should be removed.

newsitem.addLocation(name, location)

Adds a new x-im/place link into itemMeta links

Emits: event.event:DOCUMENT_CHANGED

Param Description
name Plugin name calling function
location The location in JSON containing

Example

{
 "data":
   {
     "position":"POINT(16.570516 56.774485)"
   },
 "rel":"subject",
 "title":"Rälla",
 "type":"x-im/place",
 "uuid":"6599923a-d626-11e5-ab30-625662870761"
}

newsitem.updateLocation(name, location)

Update a location

Throws:

  • Error

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of plugin
location object The location in JSON

newsitem.getLocations(entity) ⇒ array

Get all location with link type x-im/place, x-im/polygon or x-im/position with the specified entity

Returns: array - {"data":{"position":"POINT(16.570516 56.774485)"},"rel":"subject","title":"Rälla","type":"x-im/place","uuid":"6599923a-d626-11e5-ab30-625662870761"}

Param Type Description
entity string Optional entity specification, either "all", "position" or "polygon"

Adds a link to itemMeta links section

Emits: event.event:DOCUMENT_CHANGED Fires a documentChanged event with added link

Param Type Default Description
name string The name of the plugin adding the link
link object Uses jxon.unbuild to transform JSON to XML. Make sure to use @ property names for attributes.
triggerDocumentChanged boolean true set to false to suppress document changed event, default is set to true

Example

import {api} from 'writer'

api.newsItem.addLink('Pluginname', {
      '@rel': 'channel',
      '@title': 'Jeremy Spencer',
      '@type': 'x-im/author',
      '@uuid': '5f9b8064-d54f-11e5-ab30-625662870761'
  });
<link rel="author" title="Jeremy Spencer" type="x-im/author" uuid="5f9b8064-d54f-11e5-ab30-625662870761"/>

Updates the rel value on a meta link

Param Type Description
name string The name of the plugin that is triggering the change
link object a link object with a valid uuid and valid rel

Example

api.newsItem.updateLinkRel('pluginName', {
     uuid: '5f9b8064-d54f-11e5-ab30-625662870761',
     rel: 'mainchannel'
})

Adds a link to contentMeta links section

Emits: event.event:DOCUMENT_CHANGED Fires a documentChanged event with added link

Param Type Description
name string The name of the plugin adding the link
link object Uses jxon.unbuild to transform JSON to XML. Make sure to use @ property names for attributes.

Example

import {api} from 'writer'

api.newsItem.addContentMetaLink('PluginName', {
      '@rel': 'gender',
      '@title': 'Male',
      '@type': 'x-im/gender',
      '@uri': 'im://gender/male'
  });
<link title="Male" uri="im://gender/male" rel="gender" type="x-im/gender"/>

newsitem.getLinkByTypeAndRel(name, type, rel) ⇒ array

Retrieve links from itemMeta section by specified type and rel

Returns: array - Array of links

Param Type
name string
type string
rel string

newsitem.getLinkByType(name, type) ⇒ array

Retrieve links from itemMeta section by specified type

Returns: array - Return array of links transformed to JSON

Param Type Description
name string Name of the plugin
type string The link type

newsitem.getContentMetaLinkByType(name, type) ⇒ array

Get links in contentMeta links section by specified type

Returns: array - Return array of links transformed to JSON

Param Type Description
name string Name of the plugin
type string The link type

newsitem.getStories() ⇒ array

Get stories

Returns: array - Array of stories found

newsitem.getConceptSections() ⇒ array

Get concept sections

Returns: array - Array of concept sections

newsitem.addStory(name, story)

Add a story link to itemMeta links section

Emits: event.event:DOCUMENT_CHANGED

Param
name
story

Example

{
 "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
 "title": "A name"
}

newsitem.updateStory(name, story)

Updates title on existing story

Throws:

  • NotFoundError

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Plugin name
story object A story object that atleast contains title and uuid

Example

{
 "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
 "title": "A name"
}

newsitem.addConceptProfile(name, contentprofile)

Deprecated

Adds a content-profile link to NewsItem

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin
contentprofile object A contentprofile object containing uuid and title

Example

{
 "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
 "title": "A name"
}

newsitem.addContentProfile(name, contentprofile)

Adds a content-profile link to NewsItem

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin
contentprofile object A contentprofile object containing uuid and title

Example

{
 "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
 "title": "A name"
}

newsitem.addCategory(name, category)

Adds a category link to NewsItem

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin
category object A category object containing uuid and title

Example

{
 "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
 "title": "A name"
}

newsitem.updateConceptProfile()

Deprecated

Use updateContentProfile instead.

Example

{
 "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
 "title": "A name"
}

newsitem.updateContentProfile(name, contentprofile)

Updates title on existing story

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Plugin name
contentprofile object A concept profile object that atleast contains title and uuid

Example

{
 "uuid": "88d36cbe-d6dd-11e5-ab30-625662870761",
 "title": "A name"
}

newsitem.getContentProfiles() ⇒ array | null

Returns a list of all existing content-profiles in NewsItem

newsitem.getConceptByUuid() ⇒ object | null

Returns a conceptItem with matching UUID

Returns: object | null - ConceptItem or null

newsitem.getCategories() ⇒ array | null

Returns a list of all existing categories in NewsItem

newsitem.getExtProperty(sectionName, type, raw) ⇒ string | Element

Retrieve either an itemMetaExtProperty or contentMetaExtProperty value from the item or content meta sections. Optionally return full element if raw parameter is set to true.

Param Type Default Description
sectionName string Either 'itemMeta' or 'contentMeta'
type string
raw boolean false Optional, return as raw dom element, default is false

newsitem.setExtProperty(name, sectionName, type, value)

Create new or set a value of existing itemMetaExtProperty or contentMetaExtProperty

Param Type Description
name string Identifier of caller
sectionName string Either 'itemMeta' or 'contentMeta'
type string Type string
value string Value

newsitem.deleteExtProperty(name, sectionName, type)

Delete a specified itemMetaExtProperty or contentMetaExtProperty

Param Type Description
name string Identifier of caller
sectionName string Either 'itemMeta' or 'contentMeta'
type string Type

newsitem.getTemporaryId() ⇒ * | null

Returns the generated temporary id for the article. Temporary id is used when a new article is created and before it's saved the first time.

newsitem.setTemporaryId(temporaryArticleID)

Set a temporaryId for the article

Param
temporaryArticleID

newsitem.hasTemporaryId() ⇒ boolean

Checks if current article has a temporary id

newsitem.getIdForArticle() ⇒ string

Get the id for the article

newsitem.getHasPublishedVersion() ⇒ bool

Get value of itemMetaExtProperty element with type imext:haspublihedversion that indicates whether the newsitem has published version or not.

newsitem.setHasPublishedVersion(name, value)

Set itemMetaExtProperty element with type imext:haspublihedversion to true/false in item > meta sections to indicate whether this newsitem has a published version or not.

Param Type Description
name string Identifier of caller
value bool True or false

newsitem.getContentMetaObjectsByType(objectType) ⇒ Array

Retrieve objects from contentmeta.medata section based on type.

Returns: Array - Array of objects in jxon format

Param Type Description
objectType string The type of object

newsitem.getContentMetaObjectById(id) ⇒ Object

Retrieve object from contentmeta.medata section based on id.

Returns: Object - Object in jxon format

Param Type Description
id string The id of object

newsitem.setContentMetaObject(name, jxonObject)

Create and add an object into the contentmeta.metadata section. The object is encoded as a jxon object with the mandatory attributes id and type. All data must reside in the sub data structure. If an object with the specified id already exists it is silently replaced. Triggers a document:changed event.

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin making the call
jxonObject Object The jxon encoded object

Example

import {api} from 'writer'

var idGen = require('writer/utils/IdGenerator');

api.newsItem.setContentMetaObject('ximimage', {
     '@id': idGen(),
     '@type': "x-im/newsvalue",
     data: {
         score: "2",
         description: 'My description',
         format: "lifetimecode",
         end: "2016-01-31T10:00:00.000+01:00"
     }
});

Example (Results in)

<object id="8400c74d665x" type="x-im/newsvalue">
    <data>
        <score>2</score>
        <description>My description</description>
        <format>lifetimecode</format>
        <end>2016-01-31T10:00:00.000+01:00</end>
    </data>
</object>

newsitem.removeContentMetaObject(name, id)

Remove a specific object identied by id from the contentmeta.metadata section. Triggers a document:changed event.

Emits: event.event:DOCUMENT_CHANGED

Param Type Description
name string Name of the plugin making the call
id string The id of the object

newsitem.invalidate()

Invalidate document and displays notification that document is invalid

Emits: event.event:DOCUMENT_INVALIDATED

newsitem.getVersionCreated() ⇒ *

Get version created date. Resides in newsItem > itemMeta block. If no version created date was found, null is returned.

newsitem.getFirstCreated() ⇒ *

Get first created date. Resides in newsItem > itemMeta block. If no first created date was found, null is returned.

newsitem.getContentCreated() ⇒ *

Get content created date. Resides in newsItem > contentMeta block. If no content created date was found, null is returned.

newsitem.getContentModified() ⇒ *

Get content modified date. Resides in newsItem > contentMeta block. If no content modified date was found, null is returned.

results matching ""

    No results matching ""