Search in sources :

Example 6 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project tis by qlangtech.

the class XModifier method main.

public static void main(String[] arg) throws Exception {
    // StringReader read = new StringReader(schema);
    // InputSource source = new InputSource(read);
    SAXBuilder builder = new SAXBuilder(new XMLReaderSAX2Factory(false));
    // builder.setEntityResolver(entityResolver);
    builder.setEntityResolver(new EntityResolver() {

        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            InputSource source = new InputSource();
            source.setCharacterStream(new StringReader(""));
            return source;
        }
    });
    InputStream inputStream = new FileInputStream(new File("D:\\home\\schema.xml"));
    Document document = builder.build(inputStream);
    XModifier modifier = new XModifier(document);
    modifier.addModify("/types/fieldType[@name='singleString']/@class", "java.lang.String");
    modifier.addModify("/types/fieldType[@name='kkkkkkkk']/@class", "ddddddd");
    modifier.addModify("/types/fieldType[@name='xxxxxx'][@class='java.lang.String']");
    modifier.addModify("/uniqueKey/text()", "ddddddd");
    modifier.addModify("/fields/field[@name='email_dynamic_info'](:delete)");
    modifier.modify();
    // 设置xml文件格式---选用这种格式可以使生成的xml文件自动换行同时缩进
    Format format = Format.getPrettyFormat();
    // ▲▲▲▲▲▲************************ 构建schema文件格式
    // 将生成的元素加入文档:根元素
    // 添加docType属性
    DocType docType = new DocType("schema", "http://tis.qlangtech.com:9999/dtd/solrschema.dtd");
    document.setDocType(docType);
    XMLOutputter xmlout = new XMLOutputter(format);
    // 设置xml内容编码
    xmlout.setFormat(format.setEncoding("utf8"));
    ByteArrayOutputStream byteRsp = new ByteArrayOutputStream();
    xmlout.output(document, byteRsp);
    System.out.println(byteRsp.toString("utf8"));
}
Also used : XMLReaderSAX2Factory(org.jdom2.input.sax.XMLReaderSAX2Factory) XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) EntityResolver(org.xml.sax.EntityResolver) Document(org.jdom2.Document) SAXException(org.xml.sax.SAXException) Format(org.jdom2.output.Format) DocType(org.jdom2.DocType)

Example 7 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project mule-migration-assistant by mulesoft.

the class AbstractSpringMigratorStep method moveNamespacesDeclarations.

protected void moveNamespacesDeclarations(Document muleDocument, Element movedElement, Document springDocument) {
    Set<Namespace> declaredNamespaces = doGetNamespacesDeclarationsRecursively(movedElement);
    Attribute schemaLocationAttribute = muleDocument.getRootElement().getAttribute("schemaLocation", muleDocument.getRootElement().getNamespace("xsi"));
    if (schemaLocationAttribute != null) {
        Map<String, String> locations = new HashMap<>();
        String[] splitLocations = stream(schemaLocationAttribute.getValue().split("\\s")).filter(s -> !StringUtils.isEmpty(s)).toArray(String[]::new);
        for (int i = 0; i < splitLocations.length; i += 2) {
            locations.put(splitLocations[i], splitLocations[i + 1]);
        }
        for (Namespace namespace : declaredNamespaces) {
            if (!StringUtils.isEmpty(namespace.getURI()) && locations.containsKey(namespace.getURI())) {
                getApplicationModel().addNameSpace(namespace, fixSpringSchemaLocationVersion(locations.get(namespace.getURI())), springDocument.getDocument());
            }
        }
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) TreeSet(java.util.TreeSet) Document(org.jdom2.Document) Attribute(org.jdom2.Attribute) JDOMException(org.jdom2.JDOMException) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) Paths(java.nio.file.Paths) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) Map(java.util.Map) Entry(java.util.Map.Entry) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) StringUtils.substring(org.apache.commons.lang3.StringUtils.substring) Arrays.stream(java.util.Arrays.stream) Path(java.nio.file.Path) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) HashMap(java.util.HashMap) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace)

Example 8 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project mule-migration-assistant by mulesoft.

the class AbstractSpringMigratorStep method resolveSpringFile.

protected Document resolveSpringFile(Document currentDoc, Document springDocument, final Map<Path, Document> artifactDocs) {
    Path beansPath = null;
    // Check if a spring file already exists for this mule config
    for (Entry<Path, Document> entry : artifactDocs.entrySet()) {
        if (currentDoc.equals(entry.getValue())) {
            beansPath = resolveSpringBeansPath(entry);
            if (artifactDocs.containsKey(Paths.get(SPRING_FOLDER + beansPath.getFileName().toString()))) {
                return artifactDocs.get(Paths.get(SPRING_FOLDER + beansPath.getFileName().toString()));
            }
        }
    }
    // If not, create it and link it
    for (Entry<Path, Document> entry : artifactDocs.entrySet()) {
        if (currentDoc.equals(entry.getValue())) {
            beansPath = resolveSpringBeansPath(entry);
            try {
                SAXBuilder saxBuilder = new SAXBuilder();
                springDocument = saxBuilder.build(AbstractSpringMigratorStep.class.getClassLoader().getResourceAsStream("spring/empty-beans.xml"));
            } catch (JDOMException | IOException e) {
                throw new MigrationStepException(e.getMessage(), e);
            }
            addSpringModuleConfig(currentDoc, "spring/" + beansPath.getFileName().toString());
            break;
        }
    }
    if (beansPath == null) {
        return null;
    }
    artifactDocs.put(Paths.get(SPRING_FOLDER + beansPath.getFileName().toString()), springDocument);
    return springDocument;
}
Also used : Path(java.nio.file.Path) SAXBuilder(org.jdom2.input.SAXBuilder) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 9 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project mule-migration-assistant by mulesoft.

the class SpringConfigInMuleConfig method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    Document muleDocument = object.getDocument();
    Document springDocument = resolveSpringDocument(muleDocument);
    for (Element element : new ArrayList<>(object.getChildren())) {
        element.detach();
        springDocument.getRootElement().addContent(element);
        moveNamespacesDeclarations(muleDocument, element, springDocument);
    }
    object.detach();
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document)

Example 10 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project mule-migration-assistant by mulesoft.

the class DocumentHelper method getNodesFromFile.

public static void getNodesFromFile(String Xpath, AbstractApplicationModelMigrationStep step, String filePath) throws Exception {
    Document document = getDocument(filePath);
    List<Element> nodes = getElementsFromDocument(document, Xpath);
// step.setDocument(document);
// step.setNodes(nodes);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)340 SAXBuilder (org.jdom2.input.SAXBuilder)271 IOException (java.io.IOException)266 XMLOutputter (org.jdom2.output.XMLOutputter)182 JDOMException (org.jdom2.JDOMException)162 File (java.io.File)148 ArrayList (java.util.ArrayList)75 InputStream (java.io.InputStream)74 StringReader (java.io.StringReader)63 Path (java.nio.file.Path)59 HashMap (java.util.HashMap)57 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Attribute (org.jdom2.Attribute)44 List (java.util.List)42 Namespace (org.jdom2.Namespace)39