Package org.apache.xmpbox.type

Examples of org.apache.xmpbox.type.TypeMapping


        }
    }

    private PropertyType checkPropertyDefinition(XMPMetadata xmp, QName prop) throws XmpParsingException
    {
        TypeMapping tm = xmp.getTypeMapping();
        // test if namespace is set in xml
        if (!nsFinder.containsNamespace(prop.getNamespaceURI()))
        {
            throw new XmpParsingException(ErrorType.NoSchema, "Schema is not set in this document : "
                    + prop.getNamespaceURI());
        }
        // test if namespace is defined
        String nsuri = prop.getNamespaceURI();
        if (!tm.isDefinedNamespace(nsuri))
        {
            throw new XmpParsingException(ErrorType.NoSchema, "Cannot find a definition for the namespace "
                    + prop.getNamespaceURI());
        }
        try
        {
            return tm.getSpecifiedPropertyType(prop);
        }
        catch (BadFieldValueException e)
        {
            throw new XmpParsingException(ErrorType.InvalidType, "Failed to retreive property definition", e);
        }
View Full Code Here


        else
        {
            AbstractSimpleProperty specifiedTypeProperty;
            try
            {
                TypeMapping tm = getMetadata().getTypeMapping();
                specifiedTypeProperty = tm.instanciateSimpleProperty(null, getPrefix(), qualifiedName, propertyValue,
                        type);
            }
            catch (Exception e)
            {
                throw new IllegalArgumentException(
View Full Code Here

        return null;
    }

    protected AbstractSimpleProperty instanciateSimple(String param, Object value)
    {
        TypeMapping tm = getMetadata().getTypeMapping();
        return tm.instanciateSimpleField(getClass(), null, getPrefix(), param, value);
    }
View Full Code Here

    }
    @Test
    public void checkExistence () throws Exception {
        // ensure schema exists
        XMPMetadata xmpmd = new XMPMetadata();
        TypeMapping mapping = new TypeMapping(xmpmd);
        XMPSchemaFactory factory = mapping.getSchemaFactory(namespace);
        assertNotNull("Schema not existing: " + namespace, factory);
        // ensure preferred is as expected
        XMPSchema schema = factory.createXMPSchema(xmpmd,"aa");
        assertEquals(preferred,schema.getPreferedPrefix());
        // ensure field is defined
View Full Code Here

    @Test
    public void testArrayList() throws Exception
    {
        XMPMetadata meta = XMPMetadata.createXMPMetadata();
        ArrayProperty newSeq = meta.getTypeMapping().createArrayProperty(null, "nsSchem", "seqType", Cardinality.Seq);
        TypeMapping tm = meta.getTypeMapping();
        TextType li1 = tm.createText(null, "rdf", "li", "valeur1");
        TextType li2 = tm.createText(null, "rdf", "li", "valeur2");
        newSeq.getContainer().addProperty(li1);
        newSeq.getContainer().addProperty(li2);
        schem.addProperty(newSeq);
        List<AbstractField> list = schem.getUnqualifiedArrayList("seqType");
        Assert.assertTrue(list.contains(li1));
View Full Code Here

     *             If DOM Document associated could not be created
     */
    protected XMPMetadata(String xpacketBegin, String xpacketId, String xpacketBytes, String xpacketEncoding)
    {
        this.schemas = new ArrayList<XMPSchema>();
        this.typeMapping = new TypeMapping(this);

        this.xpacketBegin = xpacketBegin;
        this.xpacketId = xpacketId;
        this.xpacketBytes = xpacketBytes;
        this.xpacketEncoding = xpacketEncoding;
View Full Code Here

    }

    private void parseDescriptionRoot(XMPMetadata xmp, Element description) throws XmpParsingException
    {
        nsFinder.push(description);
        TypeMapping tm = xmp.getTypeMapping();
        try
        {
            List<Element> properties = DomHelper.getElementChildren(description);
            // parse attributes as properties
            NamedNodeMap nnm = description.getAttributes();
            for (int i = 0; i < nnm.getLength(); i++)
            {
                Attr attr = (Attr) nnm.item(i);
                if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getPrefix()))
                {
                    // do nothing
                }
                else if (XmpConstants.DEFAULT_RDF_PREFIX.equals(attr.getPrefix())
                        && XmpConstants.ABOUT_NAME.equals(attr.getLocalName()))
                {
                    // do nothing
                }
                else if (attr.getPrefix() == null && XmpConstants.ABOUT_NAME.equals(attr.getLocalName()))
                {
                    // do nothing
                }
                else
                {
                    String namespace = attr.getNamespaceURI();
                    XMPSchema schema = xmp.getSchema(namespace);
                    if (schema == null)
                    {
                        schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, attr.getPrefix());
                        loadAttributes(schema, description);
                    }
                    ComplexPropertyContainer container = schema.getContainer();
                    PropertyType type = checkPropertyDefinition(xmp,
                            new QName(attr.getNamespaceURI(), attr.getLocalName()));
                    AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, schema.getPrefix(),
                            attr.getLocalName(), attr.getValue(), type.type());
                    container.addProperty(sp);
                }

            }
            // parse children elements as properties
            for (Element property : properties)
            {
                String namespace = property.getNamespaceURI();
                PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
                // create the container
                if (!tm.isDefinedSchema(namespace))
                {
                    throw new XmpParsingException(ErrorType.NoSchema,
                            "This namespace is not a schema or a structured type : " + namespace);
                }
                XMPSchema schema = xmp.getSchema(namespace);
                if (schema == null)
                {
                    schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, property.getPrefix());
                    loadAttributes(schema, description);
                }
                ComplexPropertyContainer container = schema.getContainer();
                // create property
                createProperty(xmp, property, type, container);
View Full Code Here

    }

    private void manageSimpleType(XMPMetadata xmp, Element property, Types type, ComplexPropertyContainer container)
            throws XmpParsingException
    {
        TypeMapping tm = xmp.getTypeMapping();
        String prefix = property.getPrefix();
        String name = property.getLocalName();
        String namespace = property.getNamespaceURI();
        AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, prefix, name, property.getTextContent(),
                type);
        loadAttributes(sp, property);
        container.addProperty(sp);
    }
View Full Code Here

    }

    private void manageArray(XMPMetadata xmp, Element property, PropertyType type, ComplexPropertyContainer container)
            throws XmpParsingException
    {
        TypeMapping tm = xmp.getTypeMapping();
        String prefix = property.getPrefix();
        String name = property.getLocalName();
        String namespace = property.getNamespaceURI();
        Element bagOrSeq = DomHelper.getUniqueElementChild(property);
        // ensure this is the good type of array
        if (bagOrSeq == null)
        {
            // not an array
            throw new XmpParsingException(ErrorType.Format, "Invalid array definition, expecting " + type.card()
                    + " and found nothing");
        }
        if (!bagOrSeq.getLocalName().equals(type.card().name()))
        {
            // not the good array type
            throw new XmpParsingException(ErrorType.Format, "Invalid array type, expecting " + type.card()
                    + " and found " + bagOrSeq.getLocalName());
        }
        ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
        container.addProperty(array);
        List<Element> lis = DomHelper.getElementChildren(bagOrSeq);

        for (Element element : lis)
        {
View Full Code Here

    private void parseDescriptionInner(XMPMetadata xmp, Element description, ComplexPropertyContainer parentContainer)
            throws XmpParsingException
    {
        nsFinder.push(description);
        TypeMapping tm = xmp.getTypeMapping();
        try
        {
            List<Element> properties = DomHelper.getElementChildren(description);
            for (Element property : properties)
            {
                String name = property.getLocalName();
                PropertyType dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property));
                PropertyType ptype = tm.getStructuredPropMapping(dtype.type()).getPropertyType(name);
                // create property
                createProperty(xmp, property, ptype, parentContainer);
            }
        }
        finally
View Full Code Here

TOP

Related Classes of org.apache.xmpbox.type.TypeMapping

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.