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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations