Search in sources :

Example 86 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project ApkToolBoxGUI by jiangxincode.

the class I18nAddPanel method getSourceElement.

private Element getSourceElement(File sourceFile, String itemName) {
    if (!sourceFile.exists()) {
        logger.warn("sourceFile does not exist: " + sourceFile);
        return null;
    }
    SAXBuilder builder = new SAXBuilder();
    Document sourceDoc = null;
    try (InputStream in = new FileInputStream(sourceFile)) {
        sourceDoc = builder.build(in);
        logger.info("build source document: " + sourceFile);
    } catch (JDOMException | IOException e) {
        logger.error("build source document failed: " + sourceFile, e);
        return null;
    }
    if (sourceDoc == null) {
        logger.error("sourceDoc is null");
        return null;
    }
    Element sourceElement = null;
    for (Element sourceChild : sourceDoc.getRootElement().getChildren()) {
        String sourceValue = sourceChild.getAttributeValue("name");
        if (sourceValue != null && sourceValue.equals(itemName)) {
            sourceElement = sourceChild.clone();
            break;
        }
    }
    return sourceElement;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.jdom2.Element) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) FileInputStream(java.io.FileInputStream)

Example 87 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project ApkToolBoxGUI by jiangxincode.

the class I18nAddPanel method setTargetElement.

private boolean setTargetElement(File targetFile, Element sourceElement, String itemName) {
    SAXBuilder builder = new SAXBuilder();
    Document targetDoc;
    try {
        targetDoc = builder.build(targetFile);
        logger.info("build target document: " + targetFile);
    } catch (JDOMException | IOException e) {
        logger.error("build target document failed: " + targetFile, e);
        return false;
    }
    Element targetRoot = targetDoc.getRootElement();
    boolean isFinished = false;
    for (Element targetChild : targetRoot.getChildren()) {
        String targetValue = targetChild.getAttributeValue("name");
        if (targetValue != null && targetValue.equals(itemName)) {
            targetChild.setText(sourceElement.getText());
            isFinished = true;
            break;
        }
    }
    if (!isFinished) {
        targetRoot.addContent("    ");
        targetRoot.addContent(sourceElement);
        targetRoot.addContent("\n");
    }
    XMLOutputter out = new XMLOutputter();
    Format format = Format.getRawFormat();
    format.setEncoding("UTF-8");
    format.setLineSeparator("\n");
    out.setFormat(format);
    OutputStream os = null;
    try {
        os = new FileOutputStream(targetFile);
        out.output(targetDoc, os);
    } catch (IOException e) {
        logger.error("output fail", e);
        return false;
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                logger.error("close output stream exception", e);
            }
        }
    }
    return true;
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) Format(org.jdom2.output.Format) Element(org.jdom2.Element) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 88 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project ApkToolBoxGUI by jiangxincode.

the class I18nInfo method sort.

private void sort(String sourceBaseStr, String itemName) {
    File[] sourceParentFiles = new File(sourceBaseStr).listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.getName().startsWith("values");
        }
    });
    if (sourceParentFiles == null) {
        logger.error("None valid directory found");
        return;
    }
    for (File sourceParentFile : sourceParentFiles) {
        File sourceFile = new File(sourceParentFile, "strings.xml");
        if (sourceFile.exists()) {
            SAXBuilder builder = new SAXBuilder();
            Document sourceDoc;
            try {
                sourceDoc = builder.build(sourceFile);
            } catch (JDOMException | IOException e) {
                logger.error("build failed: " + sourceFile, e);
                continue;
            }
            Element sourceRoot = sourceDoc.getRootElement();
            for (Element child : sourceRoot.getChildren()) {
                String value = child.getAttributeValue("name");
                if (value != null && value.equals(itemName)) {
                    String text = child.getText();
                    if (text != null) {
                        I18nInfo info = new I18nInfo(getCanonicalPath(sourceFile), text, text.length());
                        infos.add(info);
                        break;
                    }
                }
            }
        }
    }
    Collections.sort(infos, new Comparator<I18nInfo>() {

        @Override
        public int compare(I18nInfo o1, I18nInfo o2) {
            return o2.length - o1.length;
        }
    });
    logger.info(infos);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) FileFilter(java.io.FileFilter) File(java.io.File)

Example 89 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project d3web-KnowWE by denkbares.

the class DOTRenderer method augmentSVG.

/**
 * Adds the target-tag to every URL in the svg-file
 *
 * @created 01.08.2012
 */
private static void augmentSVG(File svg) throws IOException {
    LOGGER.trace("Starting to augment SVG: " + svg.getAbsolutePath());
    try {
        // check if svg file is closed, otherwise wait timeout second
        long start = System.currentTimeMillis();
        while (!Utils.isFileClosed(svg)) {
            if ((System.currentTimeMillis() - start) > TIMEOUT) {
                LOGGER.warn("Exceeded timeout while waiting for SVG file to be closed.");
                return;
            }
        }
        Document doc = SAXBuilderSingleton.getInstance().build(svg);
        Element root = doc.getRootElement();
        if (root == null)
            return;
        findAndAugmentElements(root);
        XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
        // noinspection ImplicitDefaultCharsetUsage
        xmlOutputter.output(doc, new FileWriter(svg));
        LOGGER.trace("Finished augmenting SVG: " + svg.getAbsolutePath());
    } catch (JDOMException e) {
        LOGGER.warn("Exception while augmenting SVG " + svg.getAbsolutePath() + ": " + e.getClass().getSimpleName() + ": " + e.getMessage());
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) FileWriter(java.io.FileWriter) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 90 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project grpc-gcp-java by GoogleCloudPlatform.

the class BatchGetDocuments method batchGetDocumentsCall.

public void batchGetDocumentsCall() {
    List<String> docList = new ArrayList<String>();
    System.out.println("\n :: Batch Retrieve Documents :: \n");
    Scanner sc = new Scanner(System.in);
    String input = "initial";
    FirestoreGrpc.FirestoreStub firestoreStub = new GRPCFirebaseClientFactory().createFirebaseClient().getFirestoreStub();
    DrawDocument dd = new DrawDocument();
    while (!input.matches("DONE")) {
        System.out.print("Enter Document Id (Enter DONE when finished): ");
        input = sc.next();
        if (!input.matches("DONE")) {
            docList.add("projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + input);
        }
    }
    BatchGetDocumentsRequest batchGetDocsRequest = BatchGetDocumentsRequest.newBuilder().setDatabase("projects/firestoretestclient/databases/(default)").addAllDocuments(docList).build();
    final CountDownLatch finishLatch = new CountDownLatch(1);
    StreamObserver respStream = new StreamObserver() {

        @Override
        public void onNext(Object resp) {
            BatchGetDocumentsResponse response = (BatchGetDocumentsResponse) resp;
            Document doc = response.getFound();
            dd.draw(doc);
        }

        @Override
        public void onError(Throwable throwable) {
            System.out.println("Error During Call: " + throwable.getMessage());
            finishLatch.countDown();
        }

        @Override
        public void onCompleted() {
            Menu menu = new Menu();
            menu.draw();
            finishLatch.countDown();
        }
    };
    try {
        firestoreStub.batchGetDocuments(batchGetDocsRequest, respStream);
        finishLatch.await(1, TimeUnit.MINUTES);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Scanner(java.util.Scanner) GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Document(com.google.firestore.v1beta1.Document) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument) BatchGetDocumentsRequest(com.google.firestore.v1beta1.BatchGetDocumentsRequest) BatchGetDocumentsResponse(com.google.firestore.v1beta1.BatchGetDocumentsResponse) Menu(org.roguewave.grpc.util.gfx.Menu) FirestoreGrpc(com.google.firestore.v1beta1.FirestoreGrpc) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument)

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