Search in sources :

Example 56 with Document

use of io.atlasmap.v2.Document in project atlasmap by atlasmap.

the class JsonModule method processSourceFieldMapping.

@Override
public void processSourceFieldMapping(AtlasInternalSession session) throws AtlasException {
    Field sourceField = session.head().getSourceField();
    JsonFieldReader reader = session.getFieldReader(getDocId(), JsonFieldReader.class);
    if (reader == null) {
        AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Source document '%s' doesn't exist", getDocId()), sourceField.getPath(), AuditStatus.ERROR, null);
        return;
    }
    reader.read(session);
    if (sourceField.getActions() != null && sourceField.getActions().getActions() != null) {
        getFieldActionService().processActions(sourceField.getActions(), sourceField);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processSourceFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue());
    }
}
Also used : Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonFieldReader(io.atlasmap.json.core.JsonFieldReader)

Example 57 with Document

use of io.atlasmap.v2.Document in project atlasmap by atlasmap.

the class InstanceInspector method inspect.

public void inspect(Document document) {
    xmlDocument.setFields(new Fields());
    parseDocument(document.getDocumentElement());
}
Also used : XmlFields(io.atlasmap.xml.v2.XmlFields) Fields(io.atlasmap.v2.Fields)

Example 58 with Document

use of io.atlasmap.v2.Document in project atlasmap by atlasmap.

the class SchemaInspectorTest method inspectFlatPrimitiveNoRoot.

@Test
public void inspectFlatPrimitiveNoRoot() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/flatprimitive-base-unrooted.json")));
    JsonDocument document = inspectionService.inspectJsonSchema(instance);
    assertNotNull(document);
    assertEquals(5, document.getFields().getField().size());
    List<Field> fields = document.getFields().getField();
    JsonField field = (JsonField) fields.get(0);
    assertEquals("booleanField", field.getName());
    assertEquals("/booleanField", field.getPath());
    assertEquals(FieldType.BOOLEAN, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = (JsonField) fields.get(1);
    assertEquals("stringField", field.getName());
    assertEquals("/stringField", field.getPath());
    assertEquals(FieldType.STRING, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = (JsonField) fields.get(2);
    assertEquals("numberField", field.getName());
    assertEquals("/numberField", field.getPath());
    assertEquals(FieldType.NUMBER, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = (JsonField) fields.get(3);
    assertEquals("intField", field.getName());
    assertEquals("/intField", field.getPath());
    assertEquals(FieldType.INTEGER, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = (JsonField) fields.get(4);
    assertEquals("nullField", field.getName());
    assertEquals("/nullField", field.getPath());
    assertEquals(FieldType.NONE, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
}
Also used : Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 59 with Document

use of io.atlasmap.v2.Document in project xwiki-platform by xwiki.

the class DefaultEntityResourceActionLister method initialize.

@Override
public void initialize() throws InitializationException {
    // Parse the Struts config file (struts-config.xml) to extract all available actions
    List<String> actionNames = new ArrayList<>();
    SAXBuilder builder = new SAXBuilder();
    // Make sure we don't require an Internet Connection to parse the Struts config file!
    builder.setEntityResolver(new EntityResolver() {

        @Override
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new StringReader(""));
        }
    });
    // Step 1: Get a stream on the Struts config file if it exists
    InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
    if (strutsConfigStream != null) {
        // Step 2: Parse the Strust config file, looking for action names
        Document document;
        try {
            document = builder.build(strutsConfigStream);
        } catch (JDOMException | IOException e) {
            throw new InitializationException(String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
        }
        Element mappingElement = document.getRootElement().getChild("action-mappings");
        for (Element element : mappingElement.getChildren("action")) {
            // We extract the action name from the path mapping. Note that we cannot use the "name" attribute since
            // it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its
            // "name" element value.
            actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/"));
        }
    }
    this.strutsActionNames = actionNames;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InitializationException(org.xwiki.component.phase.InitializationException) SAXException(org.xml.sax.SAXException) StringReader(java.io.StringReader)

Example 60 with Document

use of io.atlasmap.v2.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)

Aggregations

Document (org.jdom2.Document)403 Element (org.jdom2.Element)248 Test (org.junit.Test)111 SAXBuilder (org.jdom2.input.SAXBuilder)95 IOException (java.io.IOException)74 File (java.io.File)58 XMLOutputter (org.jdom2.output.XMLOutputter)55 JDOMException (org.jdom2.JDOMException)44 Field (io.atlasmap.v2.Field)40 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 ArrayList (java.util.ArrayList)30 Test (org.junit.jupiter.api.Test)27 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 InputStream (java.io.InputStream)23 JsonField (io.atlasmap.json.v2.JsonField)22 MCRContent (org.mycore.common.content.MCRContent)22 Document (com.google.cloud.language.v1.Document)21 HashMap (java.util.HashMap)21 MCRException (org.mycore.common.MCRException)21