Search in sources :

Example 6 with Document

use of com.google.cloud.language.v1beta2.Document in project gocd by gocd.

the class GoConfigMigration method getCurrentSchemaVersion.

private int getCurrentSchemaVersion(String content) {
    try {
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(new ByteArrayInputStream(content.getBytes()));
        Element root = document.getRootElement();
        String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion);
        return Integer.parseInt(currentVersion);
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 7 with Document

use of com.google.cloud.language.v1beta2.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.cloud.language.v1beta2.Document in project pcgen by PCGen.

the class NameGenPanel method loadData.

private void loadData(File path) {
    if (path.isDirectory()) {
        File[] dataFiles = path.listFiles(new XMLFilter());
        SAXBuilder builder = new SAXBuilder();
        GeneratorDtdResolver resolver = new GeneratorDtdResolver(path);
        builder.setEntityResolver(resolver);
        for (File dataFile : dataFiles) {
            try {
                URL url = dataFile.toURI().toURL();
                Document nameSet = builder.build(url);
                DocType dt = nameSet.getDocType();
                if (dt.getElementName().equals("GENERATOR")) {
                    loadFromDocument(nameSet);
                }
            } catch (Exception e) {
                Logging.errorPrint(e.getMessage(), e);
                JOptionPane.showMessageDialog(this, "XML Error with file " + dataFile.getName());
            }
        }
        loadDropdowns();
    } else {
        JOptionPane.showMessageDialog(this, "No data files in directory " + path.getPath());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document) File(java.io.File) URL(java.net.URL) DocType(org.jdom2.DocType) FileNotFoundException(java.io.FileNotFoundException) DataConversionException(org.jdom2.DataConversionException)

Example 9 with Document

use of com.google.cloud.language.v1beta2.Document in project pcgen by PCGen.

the class DiceBagModel method saveToFile.

/**
	 * <p>Saves the dicebag to the specified file as a UTF-8 xml file, with the format
	 * specified above in {@code loadFromFile()}</p>
	 *
	 * @param file File to save to.
	 */
void saveToFile(File file) {
    try {
        Document doc = new Document();
        saveToDocument(doc);
        XMLOutputter xmlOut = new XMLOutputter();
        xmlOut.setFormat(Format.getPrettyFormat());
        FileWriter fr = new FileWriter(file);
        xmlOut.output(doc, fr);
        fr.flush();
        fr.close();
        m_filePath = file.getPath();
        m_changed = false;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(GMGenSystem.inst, "File load error: " + file.getName());
        Logging.errorPrint("File Load Error" + file.getName());
        Logging.errorPrint(e.getMessage(), e);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) FileWriter(java.io.FileWriter) Document(org.jdom2.Document)

Example 10 with Document

use of com.google.cloud.language.v1beta2.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)

Aggregations

Document (org.jdom2.Document)86 Element (org.jdom2.Element)57 File (java.io.File)29 Test (org.junit.Test)24 DocType (org.jdom2.DocType)23 SAXBuilder (org.jdom2.input.SAXBuilder)20 IOException (java.io.IOException)16 XMLOutputter (org.jdom2.output.XMLOutputter)14 ProcessingInstruction (org.jdom2.ProcessingInstruction)13 XmlFile (jmri.jmrit.XmlFile)11 Document (com.google.cloud.language.v1beta2.Document)10 ApiException (com.google.api.gax.grpc.ApiException)9 Document (com.google.cloud.language.v1.Document)9 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 StatusRuntimeException (io.grpc.StatusRuntimeException)9 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 FileOutputStream (java.io.FileOutputStream)7 EncodingType (com.google.cloud.language.v1.EncodingType)6 FileNotFoundException (java.io.FileNotFoundException)6 JDOMException (org.jdom2.JDOMException)6