Search in sources :

Example 1 with ContentType

use of org.geotoolkit.owc.xml.v10.ContentType in project eec by wangguanquan.

the class ExcelReader method checkContentType.

// --- PRIVATE FUNCTIONS
private ContentType checkContentType(Path root) {
    SAXReader reader = new SAXReader();
    Document document;
    // Read [Content_Types].xml
    try {
        document = reader.read(Files.newInputStream(root.resolve("[Content_Types].xml")));
    } catch (DocumentException | IOException e) {
        FileUtil.rm_rf(root.toFile(), true);
        throw new ExcelReadException("The file format is incorrect or corrupted. [[Content_Types].xml]");
    }
    ContentType contentType = new ContentType();
    List<Element> list = document.getRootElement().elements();
    for (Element e : list) {
        if ("Override".equals(e.getName())) {
            ContentType.Override override = new ContentType.Override(e.attributeValue("ContentType"), e.attributeValue("PartName"));
            if (!Files.exists(root.resolve(override.getPartName().substring(1)))) {
                FileUtil.rm_rf(root.toFile(), true);
                throw new ExcelReadException("The file format is incorrect or corrupted. [" + override.getPartName() + "]");
            }
            contentType.add(override);
        }
    }
    return contentType;
}
Also used : ContentType(org.ttzero.excel.entity.e7.ContentType) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Document(org.dom4j.Document)

Example 2 with ContentType

use of org.geotoolkit.owc.xml.v10.ContentType in project geotoolkit by Geomatys.

the class OwcXmlIO method readStyle.

private static MutableStyle readStyle(OfferingType offering, boolean def) throws JAXBException, FactoryException {
    final List<Object> content = offering.getOperationOrContentOrStyleSet();
    for (Object co : content) {
        if (co instanceof JAXBElement)
            co = ((JAXBElement) co).getValue();
        if (!(co instanceof StyleSetType))
            continue;
        final StyleSetType sst = (StyleSetType) co;
        if (sst.isDefault() != def)
            continue;
        final List<Object> ssc = sst.getNameOrTitleOrAbstract();
        for (Object ss : ssc) {
            if (ss instanceof JAXBElement)
                ss = ((JAXBElement) ss).getValue();
            if (!(ss instanceof ContentType))
                continue;
            final ContentType ct = (ContentType) ss;
            final List<Object> subcs = ct.getContent();
            for (Object subc : subcs) {
                if (subc instanceof JAXBElement)
                    subc = ((JAXBElement) subc).getValue();
                if (!(subc instanceof UserStyle))
                    continue;
                final StyleXmlIO io = new StyleXmlIO();
                return io.readStyle(subc, Specification.SymbologyEncoding.V_1_1_0);
            }
        }
    }
    return null;
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) ContentType(org.geotoolkit.owc.xml.v10.ContentType) StyleSetType(org.geotoolkit.owc.xml.v10.StyleSetType) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) JAXBElement(javax.xml.bind.JAXBElement)

Example 3 with ContentType

use of org.geotoolkit.owc.xml.v10.ContentType in project geotoolkit by Geomatys.

the class OwcXmlIO method readEntry.

private static MapItem readEntry(final EntryType entry) throws JAXBException, FactoryException, DataStoreException {
    final List<Object> entryContent = entry.getAuthorOrCategoryOrContent();
    String layerName = "";
    String layerTitle = "";
    String layerAbstract = "";
    boolean visible = true;
    boolean selectable = true;
    double layerOpacity = 1.0;
    MapItem mapItem = null;
    MutableStyle baseStyle = null;
    MutableStyle selectionStyle = null;
    final List<MapItem> children = new ArrayList<>();
    for (Object o : entryContent) {
        QName name = null;
        if (o instanceof JAXBElement) {
            final JAXBElement jax = (JAXBElement) o;
            name = jax.getName();
            o = jax.getValue();
            if (GEOTK_FACTORY._Visible_QNAME.equals(name)) {
                visible = (Boolean) o;
            } else if (GEOTK_FACTORY._Selectable_QNAME.equals(name)) {
                selectable = (Boolean) o;
            } else if (GEOTK_FACTORY._Opacity_QNAME.equals(name)) {
                layerOpacity = (Double) o;
            }
        }
        if (o instanceof OfferingType) {
            final OfferingType offering = (OfferingType) o;
            for (OwcExtension ext : getExtensions()) {
                if (ext.getCode().equals(offering.getCode())) {
                    mapItem = ext.createLayer(offering);
                    break;
                }
            }
            // search for styles
            baseStyle = readStyle(offering, true);
            selectionStyle = readStyle(offering, false);
        } else if (o instanceof ContentType) {
            // decode children
            final ContentType content = (ContentType) o;
            final List<Object> contentContent = content.getContent();
            for (Object co : contentContent) {
                if (co instanceof JAXBElement) {
                    co = ((JAXBElement) o).getValue();
                }
                if (co instanceof EntryType) {
                    children.add(readEntry((EntryType) co));
                }
            }
        } else if (o instanceof IdType) {
            final IdType idType = (IdType) o;
            final String value = idType.getValue();
            layerName = value;
        } else if (o instanceof TextType) {
            final TextType tt = (TextType) o;
            if (ATOM_FACTORY._EntryTypeTitle_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerTitle = (String) tt.getContent().get(0);
                }
            } else if (ATOM_FACTORY._EntryTypeSummary_QNAME.equals(name)) {
                if (!tt.getContent().isEmpty()) {
                    layerAbstract = (String) tt.getContent().get(0);
                }
            }
        }
    }
    if (mapItem == null) {
        mapItem = MapBuilder.createItem();
    } else if (mapItem instanceof MapLayer) {
        if (baseStyle != null) {
            ((MapLayer) mapItem).setStyle(baseStyle);
        }
        ((MapLayer) mapItem).setOpacity(layerOpacity);
    }
    mapItem.setIdentifier(layerName);
    mapItem.setTitle(layerTitle);
    mapItem.setAbstract(layerAbstract);
    mapItem.setVisible(visible);
    if (mapItem instanceof MapLayers) {
        ((MapLayers) mapItem).getComponents().addAll(children);
    } else if (!children.isEmpty()) {
        throw new IllegalArgumentException("MapLayer can not have children layers.");
    }
    return mapItem;
}
Also used : ContentType(org.geotoolkit.owc.xml.v10.ContentType) QName(javax.xml.namespace.QName) MapLayer(org.apache.sis.portrayal.MapLayer) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) IdType(org.w3._2005.atom.IdType) TextType(org.w3._2005.atom.TextType) OfferingType(org.geotoolkit.owc.xml.v10.OfferingType) EntryType(org.w3._2005.atom.EntryType) MutableStyle(org.geotoolkit.style.MutableStyle) List(java.util.List) ArrayList(java.util.ArrayList) MapItem(org.apache.sis.portrayal.MapItem) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 4 with ContentType

use of org.geotoolkit.owc.xml.v10.ContentType in project eec by wangguanquan.

the class AbstractTemplate method bindSheetData.

protected int bindSheetData() {
    // Read content
    Path contentTypePath = zipPath.resolve("[Content_Types].xml");
    SAXReader reader = new SAXReader();
    Document document;
    try {
        document = reader.read(Files.newInputStream(contentTypePath));
    } catch (DocumentException | IOException e) {
        // read style file fail.
        wb.what("9002", "[Content_Types].xml");
        return 0;
    }
    // Find Override
    List<Element> overrides = document.getRootElement().elements("Override");
    int[] result = overrides.stream().filter(e -> Const.ContentType.SHEET.equals(e.attributeValue("ContentType"))).map(e -> zipPath.resolve(e.attributeValue("PartName").substring(1))).mapToInt(this::bindSheet).toArray();
    int n = 0;
    for (int i : result) n += i;
    return n;
}
Also used : Path(java.nio.file.Path) Document(org.dom4j.Document) ContentType(org.ttzero.excel.entity.e7.ContentType) Iterator(java.util.Iterator) Files(java.nio.file.Files) IOException(java.io.IOException) HashMap(java.util.HashMap) SAXReader(org.dom4j.io.SAXReader) Field(java.lang.reflect.Field) FileUtil.exists(org.ttzero.excel.util.FileUtil.exists) FileUtil(org.ttzero.excel.util.FileUtil) ArrayList(java.util.ArrayList) DocumentException(org.dom4j.DocumentException) List(java.util.List) Const(org.ttzero.excel.manager.Const) Map(java.util.Map) Element(org.dom4j.Element) Comparator(java.util.Comparator) Path(java.nio.file.Path) Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) IOException(java.io.IOException) Document(org.dom4j.Document)

Example 5 with ContentType

use of org.geotoolkit.owc.xml.v10.ContentType in project eec by wangguanquan.

the class AbstractTemplate method check.

/**
 * The open-xml legitimate check
 *
 * @return true if legitimate
 */
public boolean check() {
    // Integrity check
    Path contentTypePath = zipPath.resolve("[Content_Types].xml");
    SAXReader reader = new SAXReader();
    Document document;
    try {
        document = reader.read(Files.newInputStream(contentTypePath));
    } catch (DocumentException | IOException e) {
        wb.what("9002", "[Content_Types].xml");
        return false;
    }
    List<ContentType.Override> overrides = new ArrayList<>();
    List<ContentType.Default> defaults = new ArrayList<>();
    Iterator<Element> it = document.getRootElement().elementIterator();
    while (it.hasNext()) {
        Element e = it.next();
        if ("Override".equals(e.getName())) {
            overrides.add(new ContentType.Override(e.attributeValue("ContentType"), e.attributeValue("PartName")));
        } else if ("Default".equals(e.getName())) {
            defaults.add(new ContentType.Default(e.attributeValue("ContentType"), e.attributeValue("Extension")));
        }
    }
    return checkDefault(defaults) && checkOverride(overrides);
}
Also used : Path(java.nio.file.Path) ContentType(org.ttzero.excel.entity.e7.ContentType) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException)

Aggregations

ContentType (org.geotoolkit.owc.xml.v10.ContentType)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Document (org.dom4j.Document)3 DocumentException (org.dom4j.DocumentException)3 Element (org.dom4j.Element)3 SAXReader (org.dom4j.io.SAXReader)3 StyleSetType (org.geotoolkit.owc.xml.v10.StyleSetType)3 ContentType (org.ttzero.excel.entity.e7.ContentType)3 Path (java.nio.file.Path)2 List (java.util.List)2 JAXBElement (javax.xml.bind.JAXBElement)2 MapItem (org.apache.sis.portrayal.MapItem)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 MapLayers (org.apache.sis.portrayal.MapLayers)2 OfferingType (org.geotoolkit.owc.xml.v10.OfferingType)2 StyleXmlIO (org.geotoolkit.sld.xml.StyleXmlIO)2 UserStyle (org.geotoolkit.sld.xml.v110.UserStyle)2 EntryType (org.w3._2005.atom.EntryType)2 IdType (org.w3._2005.atom.IdType)2