Search in sources :

Example 6 with Document

use of org.apache.type_test.types1.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 7 with Document

use of org.apache.type_test.types1.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 8 with Document

use of org.apache.type_test.types1.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 9 with Document

use of org.apache.type_test.types1.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSyntaxExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSyntaxExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeSyntax(document, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 10 with Document

use of org.apache.type_test.types1.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextExceptionTest.

@Test
@SuppressWarnings("all")
public void annotateTextExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.annotateText(document, features, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1beta2.AnnotateTextRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) Features(com.google.cloud.language.v1beta2.AnnotateTextRequest.Features) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)109 Element (org.jdom2.Element)74 SAXBuilder (org.jdom2.input.SAXBuilder)34 File (java.io.File)32 Test (org.junit.Test)29 DocType (org.jdom2.DocType)23 IOException (java.io.IOException)22 XMLOutputter (org.jdom2.output.XMLOutputter)20 JDOMException (org.jdom2.JDOMException)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 FileOutputStream (java.io.FileOutputStream)9 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 ArrayList (java.util.ArrayList)7 EncodingType (com.google.cloud.language.v1.EncodingType)6