Search in sources :

Example 6 with Document

use of com.google.firestore.v1.Document in project pcgen by PCGen.

the class RoomBoardFactory method load.

public static RoomBoard load(File dataDir) {
    //Create a new list for the room and board
    PairList<RBCost> inns = new PairList<>();
    PairList<RBCost> foods = new PairList<>();
    PairList<RBCost> animals = new PairList<>();
    File path = new File(dataDir, DIR_RNBPRICE);
    if (path.isDirectory()) {
        File[] dataFiles = path.listFiles(new XMLFilter());
        SAXBuilder builder = new SAXBuilder();
        for (int i = 0; i < dataFiles.length; i++) {
            try {
                Document methodSet = builder.build(dataFiles[i]);
                DocType dt = methodSet.getDocType();
                if (//$NON-NLS-1$
                dt.getElementName().equals("RNBPRICE")) {
                    //Do work here
                    loadRBData(methodSet, inns, foods, animals);
                }
                methodSet = null;
                dt = null;
            } catch (Exception e) {
                Logging.errorPrintLocalised("XML Error with file {0}", dataFiles[i].getName());
                Logging.errorPrint(e.getMessage(), e);
            }
        }
    } else {
        //$NON-NLS-1$
        Logging.errorPrintLocalised("in_plugin_overland_noDatafile", path.getPath());
    }
    return new RoomBoardImplementation(inns, foods, animals);
}
Also used : RBCost(plugin.overland.util.RBCost) SAXBuilder(org.jdom2.input.SAXBuilder) XMLFilter(plugin.overland.gui.XMLFilter) PairList(plugin.overland.util.PairList) Document(org.jdom2.Document) File(java.io.File) DocType(org.jdom2.DocType) ParseException(java.text.ParseException)

Example 7 with Document

use of com.google.firestore.v1.Document in project gocd by gocd.

the class XmlView method renderMergedOutputModel.

protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Document document = (Document) model.get("document");
    ServletOutputStream outputStream = response.getOutputStream();
    try {
        XmlUtils.writeXml(document, outputStream);
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) Document(org.jdom2.Document)

Example 8 with Document

use of com.google.firestore.v1.Document in project gocd by gocd.

the class GoControlLog method writeLogFile.

protected void writeLogFile(File file, Element element) throws IOException {
    // Write the log file out, let jdom care about the encoding by using
    // an OutputStream instead of a Writer.
    OutputStream logStream = null;
    try {
        Format format = Format.getPrettyFormat();
        XMLOutputter outputter = new XMLOutputter(format);
        IO.mkdirFor(file);
        file.setWritable(true);
        logStream = new BufferedOutputStream(new FileOutputStream(file));
        outputter.output(new Document(element), logStream);
    } finally {
        IO.close(logStream);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Format(org.jdom2.output.Format) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) Document(org.jdom2.Document) BufferedOutputStream(java.io.BufferedOutputStream)

Example 9 with Document

use of com.google.firestore.v1.Document in project dq-easy-cloud by dq-open-cloud.

the class DqXMLUtils method getMapFromInputStream.

/**
 * <p>
 * 将xml流中的信息放入map中
 * </p>
 *
 * @param inputStream
 *            : InputStream : xml输入流
 * @param paramsMap
 *            : Map<String, Object> : xml结果容器
 * @return Map<String, Object>
 * @throws IOException
 * @author daiqi 创建时间 2018年2月23日 下午12:49:06
 */
public static Map<String, Object> getMapFromInputStream(InputStream inputStream, Map<String, Object> paramsMap) throws IOException {
    if (null == paramsMap) {
        paramsMap = new HashMap<>();
    }
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(inputStream);
        Element root = doc.getRootElement();
        List<Element> list = root.getChildren();
        Iterator<Element> it = list.iterator();
        while (it.hasNext()) {
            Element e = (Element) it.next();
            String k = e.getName();
            Object v = DqStringUtils.EMPTY;
            List<Element> children = e.getChildren();
            if (children.isEmpty()) {
                v = e.getTextNormalize();
            } else {
                v = getChildren(children);
            }
            paramsMap.put(k, v);
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return paramsMap;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 10 with Document

use of com.google.firestore.v1.Document in project dq-easy-cloud by dq-open-cloud.

the class XmlUtilsTest method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    // Document doc = builder.build(new File("src/test.xml"));
    // Document doc = builder.build(new FileInputStream("src/test.xml"));
    // Document doc = builder.build(new FileReader("src/test.xml"));
    // Document doc = builder.build(new URL("http://localhost:8080/jdomTest/test.xml"));
    Document doc = builder.build(DqSourceCodeRelativePath.RESOURCES + "\\test.xml");
    readXmlFile(doc);
// addXmlElement(doc);
// updateXmlElement(doc);
// deleteXmlElement(doc);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)402 Element (org.jdom2.Element)249 Test (org.junit.Test)119 SAXBuilder (org.jdom2.input.SAXBuilder)94 IOException (java.io.IOException)73 File (java.io.File)57 XMLOutputter (org.jdom2.output.XMLOutputter)55 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 ArrayList (java.util.ArrayList)24 DocType (org.jdom2.DocType)24 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 Document (com.google.cloud.language.v1.Document)21 HashMap (java.util.HashMap)21 MCRException (org.mycore.common.MCRException)21 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 InputStream (java.io.InputStream)18