Search in sources :

Example 21 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project archi by archimatetool.

the class ViewpointManager method loadDefaultViewpointsFile.

/**
 * Load viewpoints from XML file
 */
void loadDefaultViewpointsFile() throws IOException, JDOMException {
    URL url = Platform.getBundle(BUNDLE_ID).getEntry(VIEWPOINTS_FILE);
    Document doc = new SAXBuilder().build(url);
    Element rootElement = doc.getRootElement();
    for (Element xmlViewpoint : rootElement.getChildren("viewpoint")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String id = xmlViewpoint.getAttributeValue("id");
        if (id == null || "".equals(id)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            System.err.println("Blank id for viewpoint");
            continue;
        }
        // $NON-NLS-1$
        Element xmlName = xmlViewpoint.getChild("name");
        if (xmlName == null) {
            // $NON-NLS-1$
            System.err.println("No name element for viewpoint");
            continue;
        }
        String name = xmlName.getText();
        if (name == null || "".equals(name)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            System.err.println("Blank name for viewpoint");
            continue;
        }
        Viewpoint vp = new Viewpoint(id, name);
        for (Element xmlConcept : xmlViewpoint.getChildren("concept")) {
            // $NON-NLS-1$
            String conceptName = xmlConcept.getText();
            if (conceptName == null || "".equals(conceptName)) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                System.err.println("Blank concept name for viewpoint");
                continue;
            }
            if (ELEMENTS_MAP.containsKey(conceptName)) {
                addCollection(vp, conceptName);
            } else {
                EClass eClass = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(conceptName);
                if (eClass != null) {
                    addConcept(vp, eClass);
                } else {
                    // $NON-NLS-1$
                    System.err.println("Couldn't get eClass: " + conceptName);
                }
            }
        }
        VIEWPOINTS.put(id, vp);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) EClass(org.eclipse.emf.ecore.EClass) Element(org.jdom2.Element) Document(org.jdom2.Document) URL(java.net.URL)

Example 22 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project coprhd-controller by CoprHD.

the class ServiceCatalogBuilder method build.

/**
 * Parses xml file to ServiceCatalog with Jdom
 *
 * @param xmlFile
 *            The instance of xml file
 * @return instance of ServiceCatalog
 */
public static ServiceCatalog build(final File xmlFile) {
    String fileName = xmlFile.getName().trim().toLowerCase();
    // remove suffix
    if (fileName.endsWith(Constants.XML_FILE_SUFFIX)) {
        fileName = fileName.substring(0, fileName.length() - Constants.XML_FILE_SUFFIX.length() - 1);
    } else {
        throw new IllegalArgumentException("API file is not xml format: " + fileName);
    }
    // filter name
    int separatorIndex = fileName.indexOf(Constants.NAME_STRING_SEPARATOR);
    if (separatorIndex == -1) {
        throw new IllegalArgumentException("API file name should split with " + Constants.NAME_STRING_SEPARATOR + " actually: " + fileName);
    }
    String serviceName = fileName.substring(0, separatorIndex);
    String version = fileName.substring(separatorIndex + 1, fileName.length());
    Document document;
    try {
        document = new SAXBuilder().build(xmlFile);
    } catch (Exception ex) {
        throw new IllegalArgumentException("Invalid XML file:\n " + xmlFile.getAbsolutePath(), ex);
    }
    if (document == null) {
        return null;
    }
    // Navigates to resource tag, it's a little tricky here, depends on structure of xml file completely.
    List<Element> resourceList = document.getRootElement().getChild(Constants.REST_NODE).getChild(Constants.RESOURCES_NODE).getChildren();
    // Navigates to element tag, it's a little tricky here, depends on structure of xml file completely.
    List<Element> elementList = document.getRootElement().getChild(Constants.DATA_NODE).getChild(Constants.DATA_SCHEMA_NODE).getChild(Constants.ELEMENTS_NODE).getChildren();
    return new ServiceCatalog(parseResource(resourceList), parseElement(elementList), serviceName, version);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 23 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSyntaxExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSyntaxExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeSyntax(document, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 24 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextExceptionTest.

@Test
@SuppressWarnings("all")
public void annotateTextExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.annotateText(document, features, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1beta2.AnnotateTextRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) Features(com.google.cloud.language.v1beta2.AnnotateTextRequest.Features) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 25 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextTest.

@Test
@SuppressWarnings("all")
public void annotateTextTest() {
    String language = "language-1613589672";
    AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(features, actualRequest.getFeatures());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1beta2.AnnotateTextRequest) EncodingType(com.google.cloud.language.v1beta2.EncodingType) AnnotateTextResponse(com.google.cloud.language.v1beta2.AnnotateTextResponse) Document(com.google.cloud.language.v1beta2.Document) Features(com.google.cloud.language.v1beta2.AnnotateTextRequest.Features) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18