Package com.hp.hpl.jena.datatypes

Examples of com.hp.hpl.jena.datatypes.RDFDatatype


    public static Node checkAndGetStringLiteral(String label, NodeValue nv)
    {
        Node n = nv.asNode() ;
        if ( ! n.isLiteral() )
            throw new ExprEvalException(label+": Not a literal: "+nv) ;
        RDFDatatype dt = n.getLiteralDatatype() ;
        String lang = n.getLiteralLanguage() ;
       
        if ( dt != null && ! dt.equals(XSDDatatype.XSDstring) )
            throw new ExprEvalException(label+": Not a string literal: "+nv) ;
        return n ;
    }
View Full Code Here


                    // Must be able to resolve the datattype else we can't find it's datatype.
                    throw new RiotException("Invalid token: "+this) ;
                Node n = dtToken.asNode(pmap);
                if ( ! n.isURI() )
                    throw new RiotException("Invalid token: "+this) ;
                RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(n.getURI()) ;
                return NodeFactory.createLiteral(lexToken.getImage(), null, dt;
            }
            case LITERAL_LANG : return NodeFactory.createLiteral(tokenImage, tokenImage2, null;
            case STRING:
            case STRING1:
View Full Code Here

       
        Node n = null ;
       
        if ( datatype != null)
        {
            RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(datatype) ;
            n = com.hp.hpl.jena.graph.NodeFactory.createLiteral(lexicalForm, null, dType) ;
        }
        else
            n = com.hp.hpl.jena.graph.NodeFactory.createLiteral(lexicalForm, langTag, null) ;
        return NodeValue.makeNode(n) ;
View Full Code Here

        if ( NodeUtils.hasLang(node) )
            // Check for RDF 1.1!
            return null ;
        LiteralLabel lit = node.getLiteral() ;
        String lex = lit.getLexicalForm() ;
        RDFDatatype datatype = lit.getDatatype() ;

        // Quick check.
        // Only XSD supported.
        // And (for testing) roman numerals.
        String datatypeURI = datatype.getURI() ;
        if ( ! datatypeURI.startsWith(xsdNamespace) && ! enableRomanNumerals.getValue() )
        {
            // Not XSD.
            return null ;
        }

        try { // DatatypeFormatException - should not happen
           
            if ( sameValueAsString && XSDstring.isValidLiteral(lit) )
                    // String - plain or xsd:string
                return new NodeValueString(lit.getLexicalForm(), node) ;
           
            // Otherwise xsd:string is like any other unknown datatype.
            // Ditto literals with language tags (which are handled by nodeToNodeValue)
           
            // isValidLiteral is a value test - not a syntactic test. 
            // This makes a difference in that "1"^^xsd:decimal" is a
            // valid literal for xsd:integer (all other cases are subtypes of xsd:integer)
            // which we want to become integer anyway).

            // Order here is promotion order integer-decimal-float-double
           
            if ( ! datatype.equals(XSDdecimal) )
            {
                // XSD integer and derived types
                if ( XSDinteger.isValidLiteral(lit) )
                {
                    String s = node.getLiteralLexicalForm() ;
                    if ( s.startsWith("+") )
                        // BigInteger does not accept leading "+"
                        s = s.substring(1) ;
                    // Includes subtypes (int, byte, postiveInteger etc).
                    // NB Known to be valid for type by now
                    BigInteger integer = new BigInteger(s) ;
                    return new NodeValueInteger(integer, node) ;
                }
            }
           
            if ( datatype.equals(XSDdecimal) && XSDdecimal.isValidLiteral(lit) )
            {
                BigDecimal decimal = new BigDecimal(lit.getLexicalForm()) ;
                return new NodeValueDecimal(decimal, node) ;
            }
           
            if ( datatype.equals(XSDfloat) && XSDfloat.isValidLiteral(lit) )
            {
                // NB If needed, call to floatValue, then assign to double.
                // Gets 1.3f != 1.3d right
                float f = ((Number)lit.getValue()).floatValue() ;
                return new NodeValueFloat(f, node) ;
            }

            if ( datatype.equals(XSDdouble) && XSDdouble.isValidLiteral(lit) )
            {
                double d = ((Number)lit.getValue()).doubleValue() ;
                return new NodeValueDouble(d, node) ;
            }

            // XXX Pending Jena update ...
            if ( ( datatype.equals(XSDdateTime) || dtXSDdateTimeStamp.equals(datatypeURI) ) &&
                    XSDdateTime.isValid(lex) )
            {
                XSDDateTime dateTime = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDdate) && XSDdate.isValidLiteral(lit) )
            {
                // Jena datatype support works on masked dataTimes.
                XSDDateTime dateTime = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDtime) && XSDtime.isValidLiteral(lit) )
            {
                // Jena datatype support works on masked dataTimes.
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDgYear) && XSDgYear.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
            if ( datatype.equals(XSDgYearMonth) && XSDgYearMonth.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
            if ( datatype.equals(XSDgMonth) && XSDgMonth.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            if ( datatype.equals(XSDgMonthDay) && XSDgMonthDay.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
            if ( datatype.equals(XSDgDay) && XSDgDay.isValidLiteral(lit) )
            {
                XSDDateTime time = (XSDDateTime)lit.getValue() ;
                return new NodeValueDT(lex, node) ;
            }
           
            // XXX Pending Jena update ...
            if ( ( datatype.equals(XSDduration) ||
                   dtXSDdayTimeDuration.equals(datatypeURI) ||
                   dtXSDyearMonthDuration.equals(datatypeURI) ) &&
                   XSDduration.isValid(lex) ) // use lex
            {
                Duration duration = xmlDatatypeFactory.newDuration(lex) ;
               
                if ( dtXSDdayTimeDuration.equals(datatypeURI) && ! XSDFuncOp.isDayTime(duration) )
                    return null ;
                if ( dtXSDyearMonthDuration.equals(datatypeURI) && ! XSDFuncOp.isYearMonth(duration) )
                    return null ;
               
                return new NodeValueDuration(duration, node) ;
            }
           
            if ( datatype.equals(XSDboolean) && XSDboolean.isValidLiteral(lit) )
            {
                boolean b = ((Boolean)lit.getValue()).booleanValue() ;
                return new NodeValueBoolean(b, node) ;
            }
           
View Full Code Here

            if (lit.isWellFormedXML()) {
                return NodeFactory.createLiteral(lit.toString(), null, true);
            }

            RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(dtURI);
            return NodeFactory.createLiteral(lit.toString(), null, dt);

        }
View Full Code Here

                        String langTag = parser.getAttributeValue(XML_NS, "lang") ;
                       
                        // Works for XML literals (returning them as a string)
                        String text = parser.getElementText() ;
                       
                        RDFDatatype dType = null ;
                        if ( datatype != null )
                            dType = TypeMapper.getInstance().getSafeTypeByName(datatype);
                       
                        Node n = NodeFactory.createLiteral(text,  langTag, dType) ;
                        if ( varName == null )
View Full Code Here

    public Node convert(Node node)
    {
        if ( ! node.isLiteral() )
            return node ;
           
        RDFDatatype dt = node.getLiteralDatatype() ;
        Node n2 ;
        if ( dt == null )
        {
            if ( node.getLiteralLanguage().equals("") )
                //n2 = NormalizeValue.dtSimpleLiteral.handle(node, node.getLiteralLexicalForm(), null) ;
View Full Code Here

                    default :
                        throw new RiotException("Expected IRI for datatype: " + token) ;
                }

                uriStr = resolveIRI(uriStr, tokenDT.getLine(), tokenDT.getColumn()) ;
                RDFDatatype dt = NodeFactory.getType(uriStr) ;
                return createTypedLiteral(str, dt, line, col) ;
            }

            case LITERAL_LANG :
                return createLangLiteral(str, token.getImage2(), line, col) ;
View Full Code Here

        {
            String lang = stringOrNull(term, kXmlLang) ;
            String dtStr = stringOrNull(term, kDatatype) ;
            if ( lang != null && dtStr != null )
                throw new ResultSetException("Both language and datatype defined: "+term) ;
            RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(dtStr) ;
            return NodeFactory.createLiteral(v, lang, dt;
        }
       
        if ( kBnode.equals(type) )
            return labelMap.get(null, v) ;
View Full Code Here

        private void endElementLiteral(String ns, String localName, String name)
        {
            endAccumulate() ;
            String lexicalForm = buff.toString() ;
           
            RDFDatatype dType = null ;
            if ( datatype != null )
                dType = TypeMapper.getInstance().getSafeTypeByName(datatype);
           
            Node n = NodeFactory.createLiteral(lexicalForm.toString(),  langTag, dType) ;
            if ( checkVarName("Literal: "+FmtUtils.stringForNode(n)) )
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.datatypes.RDFDatatype

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.