Search in sources :

Example 6 with ContentType

use of com.google.cloud.asset.v1.ContentType in project java-asset by googleapis.

the class ListAssets method testListAssetsExample.

@Test
public void testListAssetsExample() throws Exception {
    // Use the default project Id (configure it by setting environment variable
    // "GOOGLE_CLOUD_PROJECT").
    String projectId = ServiceOptions.getDefaultProjectId();
    String[] assetTypes = { "storage.googleapis.com/Bucket", "bigquery.googleapis.com/Table" };
    ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED;
    ListAssetsExample.listAssets(projectId, assetTypes, contentType);
    String got = bout.toString();
    if (!got.isEmpty()) {
        assertThat(got).contains("asset");
    }
}
Also used : ContentType(com.google.cloud.asset.v1.ContentType) Test(org.junit.Test)

Example 7 with ContentType

use of com.google.cloud.asset.v1.ContentType in project java-asset by googleapis.

the class ListAssets method testListAssetsRelationshipExample.

@Test
public void testListAssetsRelationshipExample() throws Exception {
    // Use the default project Id (configure it by setting environment variable
    // "GOOGLE_CLOUD_PROJECT").
    String projectId = ServiceOptions.getDefaultProjectId();
    String[] assetTypes = { "compute.googleapis.com/Instance", "compute.googleapis.com/Disk" };
    ContentType contentType = ContentType.RELATIONSHIP;
    ListAssetsExample.listAssets(projectId, assetTypes, contentType);
    String got = bout.toString();
    if (!got.isEmpty()) {
        assertThat(got).contains("asset");
    }
}
Also used : ContentType(com.google.cloud.asset.v1.ContentType) Test(org.junit.Test)

Example 8 with ContentType

use of com.google.cloud.asset.v1.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 9 with ContentType

use of com.google.cloud.asset.v1.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 10 with ContentType

use of com.google.cloud.asset.v1.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

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)5 ContentType (com.google.cloud.asset.v1.ContentType)4 ProjectName (com.google.cloud.asset.v1.ProjectName)4 IOException (java.io.IOException)4 ContentType (org.geotoolkit.owc.xml.v10.ContentType)4 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 ExportAssetsRequest (com.google.cloud.asset.v1.ExportAssetsRequest)2 ExportAssetsResponse (com.google.cloud.asset.v1.ExportAssetsResponse)2 OutputConfig (com.google.cloud.asset.v1.OutputConfig)2 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