Package org.apache.xmpbox.type

Examples of org.apache.xmpbox.type.TypeMapping


        }
        else
        {
            // no child, so consider as simple text
            String text = liElement.getTextContent();
            TypeMapping tm = xmp.getTypeMapping();
            AbstractSimpleProperty sp = tm.instanciateSimpleProperty(descriptor.getNamespaceURI(),
                    descriptor.getPrefix(), descriptor.getLocalPart(), text, Types.Text);
            loadAttributes(sp, liElement);
            return sp;
        }
    }
View Full Code Here


    }

    private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName descriptor, Element liElement)
            throws XmpParsingException
    {
        TypeMapping tm = xmp.getTypeMapping();
        List<Element> elements = DomHelper.getElementChildren(liElement);
        if (elements.size() == 0)
        {
            // The list is empty
            return null;
        }
        // Instantiate abstract structured type with hint from first element
        Element first = elements.get(0);
        PropertyType ctype = checkPropertyDefinition(xmp, DomHelper.getQName(first));
        Types tt = ctype.type();
        AbstractStructuredType ast = instanciateStructured(tm, tt, descriptor.getLocalPart(), first.getNamespaceURI());

        ast.setNamespace(descriptor.getNamespaceURI());
        ast.setPrefix(descriptor.getPrefix());

        PropertiesDescription pm;
        if (tt.isStructured())
        {
            pm = tm.getStructuredPropMapping(tt);
        }
        else
        {
            pm = tm.getDefinedDescriptionByNamespace(first.getNamespaceURI());
        }
        for (Element element : elements)
        {
            String prefix = element.getPrefix();
            String name = element.getLocalName();
            String namespace = element.getNamespaceURI();
            PropertyType type = pm.getPropertyType(name);
            if (type == null)
            {
                // not defined
                throw new XmpParsingException(ErrorType.NoType, "Type '" + name + "' not defined in "
                        + element.getNamespaceURI());
            }
            else if (type.card().isArray())
            {
                ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
                ast.getContainer().addProperty(array);
                Element bagOrSeq = DomHelper.getUniqueElementChild(element);
                List<Element> lis = DomHelper.getElementChildren(bagOrSeq);
                for (Element element2 : lis)
                {
                    AbstractField ast2 = parseLiElement(xmp, descriptor, element2);
                    if (ast2 != null)
                    {
                        array.addProperty(ast2);
                    }
                }
            }
            else if (type.type().isSimple())
            {
                AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, prefix, name,
                        element.getTextContent(), type.type());
                loadAttributes(sp, element);
                ast.getContainer().addProperty(sp);
            }
            else if (type.type().isStructured())
View Full Code Here

        }
    }

    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

    }

    public static void populateSchemaMapping(XMPMetadata meta) throws XmpParsingException
    {
        List<XMPSchema> schems = meta.getAllSchemas();
        TypeMapping tm = meta.getTypeMapping();
        StructuredType stPdfaExt = PDFAExtensionSchema.class.getAnnotation(StructuredType.class);
        for (XMPSchema xmpSchema : schems)
        {
            if (xmpSchema.getNamespace().equals(stPdfaExt.namespace()))
            {
                // ensure the prefix is the preferred one (cannot use other
                // definition)
                if (!xmpSchema.getPrefix().equals(stPdfaExt.preferedPrefix()))
                {
                    throw new XmpParsingException(ErrorType.InvalidPrefix,
                            "Found invalid prefix for PDF/A extension, found '" + xmpSchema.getPrefix()
                                    + "', should be '" + stPdfaExt.preferedPrefix() + "'");
                }
                // create schema and types
                PDFAExtensionSchema pes = (PDFAExtensionSchema) xmpSchema;
                ArrayProperty sp = pes.getSchemasProperty();
                for (AbstractField af : sp.getAllProperties())
                {
                    if (af instanceof PDFASchemaType)
                    {
                        PDFASchemaType st = (PDFASchemaType) af;
                        String namespaceUri = st.getNamespaceURI();
                        String prefix = st.getPrefixValue();
                        ArrayProperty properties = st.getProperty();
                        ArrayProperty valueTypes = st.getValueType();
                        XMPSchemaFactory xsf = tm.getSchemaFactory(namespaceUri);
                        // retrieve namespaces
                        if (xsf == null)
                        {
                            // create namespace with no field
                            tm.addNewNameSpace(namespaceUri, prefix);
                            xsf = tm.getSchemaFactory(namespaceUri);
                        }
                        // populate value type
                        if (valueTypes != null)
                        {
                            for (AbstractField af2 : valueTypes.getAllProperties())
                            {
                                if (af2 instanceof PDFATypeType)
                                {
                                    PDFATypeType type = (PDFATypeType) af2;
                                    String ttype = type.getType();
                                    String tns = type.getNamespaceURI();
                                    String tprefix = type.getPrefixValue();
                                    String tdescription = type.getDescription();
                                    ArrayProperty fields = type.getFields();
                                    if (ttype == null || tns == null || tprefix == null || tdescription == null)
                                    {
                                        // all fields are mandatory
                                        throw new XmpParsingException(ErrorType.RequiredProperty,
                                                "Missing field in type definition");
                                    }
                                    // create the structured type
                                    DefinedStructuredType structuredType = new DefinedStructuredType(meta, tns,
                                            tprefix, null); // TODO
                                                            // maybe
                                                            // a name
                                                            // exists
                                    if (fields != null)
                                    {
                                        List<AbstractField> definedFields = fields.getAllProperties();
                                        for (AbstractField af3 : definedFields)
                                        {
                                            if (af3 instanceof PDFAFieldType)
                                            {
                                                PDFAFieldType field = (PDFAFieldType) af3;
                                                String fName = field.getName();
                                                String fDescription = field.getDescription();
                                                String fValueType = field.getValueType();
                                                if (fName == null || fDescription == null || fValueType == null)
                                                {
                                                    throw new XmpParsingException(ErrorType.RequiredProperty,
                                                            "Missing field in field definition");
                                                }
                                                try
                                                {
                                                    Types fValue = Types.valueOf(fValueType);
                                                    structuredType.addProperty(fName,
                                                            TypeMapping.createPropertyType(fValue, Cardinality.Simple));
                                                }
                                                catch (IllegalArgumentException e)
                                                {
                                                    throw new XmpParsingException(ErrorType.NoValueType,
                                                            "Type not defined : " + fValueType, e);
                                                    // TODO could fValueType be
                                                    // a structured type ?
                                                }
                                            } // else TODO
                                        }
                                    }
                                    // add the structured type to list
                                    PropertiesDescription pm = new PropertiesDescription();
                                    for (Map.Entry<String, PropertyType> entry : structuredType.getDefinedProperties()
                                            .entrySet())
                                    {
                                        pm.addNewProperty(entry.getKey(), entry.getValue());
                                    }
                                    tm.addToDefinedStructuredTypes(ttype, tns, pm);
                                }
                            }
                        }
                        // populate properties
                        for (AbstractField af2 : properties.getAllProperties())
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

     *             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

    @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

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.