コード例 #1
0
def get_modification_date_4suite(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    4suite extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record modification date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:modification_date(445)"/>

    if value is int, value is converted to string
    if value is Node, first child node (text node) is taken as value
    """
    try:
        if len(recID) > 0 and isinstance(recID[0], Node):
            recID_int = recID[0].firstChild.nodeValue
            if recID_int is None:
                return ''
        else:
            recID_int = int(recID_int)

        if len(fmt) > 0 and isinstance(fmt[0], Node):
            fmt_str = fmt[0].firstChild.nodeValue
            if fmt_str is None:
                fmt_str = "%Y-%m-%dT%H:%M:%SZ"
        else:
            fmt_str = str(fmt)

        return get_modification_date(recID_int, fmt_str)
    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''
コード例 #2
0
def get_modification_date_libxslt(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    libxslt extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record modification date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:creation_date(445)"/> where 445 is a recID

    if recID is string, value is converted to int
    if recID is Node, first child node (text node) is taken as value
    """
    try:
        if isinstance(recID, str):
            recID_int = int(recID)
        elif isinstance(recID, (int, long)):
            recID_int = recID
        else:
            recID_int = libxml2.xmlNode(_obj=recID[0]).children.content

        if isinstance(fmt, str):
            fmt_str = fmt
        else:
            fmt_str = libxml2.xmlNode(_obj=recID[0]).children.content

        return get_modification_date(recID_int, fmt_str)
    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''
コード例 #3
0
def get_modification_date_4suite(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    4suite extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record modification date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:modification_date(445)"/>

    if value is int, value is converted to string
    if value is Node, first child node (text node) is taken as value
    """
    try:
        if len(recID) > 0 and isinstance(recID[0], Node):
            recID_int = recID[0].firstChild.nodeValue
            if recID_int is None:
                return ''
        else:
            recID_int = int(recID_int)

        if len(fmt) > 0 and isinstance(fmt[0], Node):
            fmt_str = fmt[0].firstChild.nodeValue
            if fmt_str is None:
                fmt_str = "%Y-%m-%dT%H:%M:%SZ"
        else:
            fmt_str = str(fmt)

        return get_modification_date(recID_int, fmt_str)
    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''
コード例 #4
0
def get_modification_date_libxslt(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    libxslt extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record modification date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:creation_date(445)"/> where 445 is a recID

    if recID is string, value is converted to int
    if recID is Node, first child node (text node) is taken as value
    """
    try:
        if isinstance(recID, str):
            recID_int = int(recID)
        elif isinstance(recID, (int, long)):
            recID_int = recID
        else:
            recID_int = libxml2.xmlNode(_obj=recID[0]).children.content

        if isinstance(fmt, str):
            fmt_str = fmt
        else:
            fmt_str = libxml2.xmlNode(_obj=recID[0]).children.content

        return get_modification_date(recID_int, fmt_str)
    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''
コード例 #5
0
def get_modification_date_lxml(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    libxslt extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record modification date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:creation_date(445)"/> where 445 is a recID

    if recID is string, value is converted to int
    if recID is Node, first child node (text node) is taken as value

    @param ctx: context as passed by lxml
    @param recID: record ID
    @param fmt: format of the returned date
    @return: modification date of X{recID}
    @rtype: string
    """
    try:
        if isinstance(recID, str):
            recID_int = int(recID)
        elif isinstance(recID, (int, long)):
            recID_int = recID
        elif isinstance(recID, list):
            recID = recID[0]
            if isinstance(recID, str):
                recID_int = int(recID)
            else:
                recID_int = int(recID.text)
        else:
            recID_int = int(recID.text)

        if isinstance(fmt, str):
            fmt_str = fmt
        elif isinstance(fmt, list):
            fmt = fmt[0]
            if isinstance(fmt, str):
                fmt_str = fmt
            else:
                fmt_str = fmt.text
        else:
            fmt_str = fmt.text

        return get_modification_date(recID_int, fmt_str)
    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''
コード例 #6
0
def get_modification_date_lxml(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    libxslt extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record modification date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:creation_date(445)"/> where 445 is a recID

    if recID is string, value is converted to int
    if recID is Node, first child node (text node) is taken as value

    @param ctx: context as passed by lxml
    @param recID: record ID
    @param fmt: format of the returned date
    @return: modification date of X{recID}
    @rtype: string
    """
    try:
        if isinstance(recID, str):
            recID_int = int(recID)
        elif isinstance(recID, (int, long)):
            recID_int = recID
        elif isinstance(recID, list):
            recID = recID[0]
            if isinstance(recID, str):
                recID_int = int(recID)
            else:
                recID_int = int(recID.text)
        else:
            recID_int = int(recID.text)

        if isinstance(fmt, str):
            fmt_str = fmt
        elif isinstance(fmt, list):
            fmt = fmt[0]
            if isinstance(fmt, str):
                fmt_str = fmt
            else:
                fmt_str = fmt.text
        else:
            fmt_str = fmt.text

        return get_modification_date(recID_int, fmt_str)
    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''