⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringtest.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
package test.xmldb.levelzero;

import junit.framework.*;
import test.xmldb.*;

import java.io.BufferedReader;
import java.io.FileReader;

import org.xml.sax.InputSource;
import org.apache.xerces.parsers.DOMParser;
import org.apache.log4j.Logger;

import org.xmldb.api.modules.XMLResource;
/**
 * @author  Per Nyfelt
 */
public class StringTest extends XMLDBTestCase implements LevelZeroTestConstants {

    Logger logger = Logger.getLogger(StringTest.class);

    /** Creates new StringTest */
    public StringTest(String name) {
        super(name);
    }

    public static Test suite() {
        return new TestSuite(StringTest.class);
    }

   /**
     * test all scenarios for using XML as text (String)
     */
    public void testString() {
        try {
            logger.debug("\nLevelZeroTest.testString() - started\n");

            // read in the text file so we have something to compare with
            BufferedReader in = new BufferedReader(new FileReader(xmlFileName));
            InputSource source = new InputSource(in);
            DOMParser parser = new DOMParser();
            parser.parse(source);
            String xmlString = toString(parser.getDocument()).trim();
            XMLResource res = insertStringDocument(id, super.toString(document));

            String result = retrieveTextDocument(id).trim();

            super.assertNotNull("LevelZeroTest.testString() - result", result);
            super.assertEquals("LevelZeroTest.testString() - length", xmlString.length(), result.length());

            // this fails right now since there is no clear method cleaning out previous
            // content and append is the standard behavious for XMLContainer
            updateStringDocument(id);

        } catch (Exception e) {
            e.printStackTrace();
            fail( e.getMessage( ) );
        }
   }

   private XMLResource insertStringDocument(String id, String document) throws Exception {
        XMLResource res = (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
        super.assertEquals("LevelZeroTest.testString() - id",res.getId(), id);
        super.assertSame(res.getParentCollection(),col);
        res.setContent(document);
        col.storeResource(res);
        return res;
   }

   private String retrieveTextDocument(String id) throws Exception {
        XMLResource resource = (XMLResource) col.getResource(id);
        return (String)resource.getContent();
    }

   private void updateStringDocument(String id) throws Exception {
        XMLResource resource = (XMLResource) col.getResource(id);
        String document = (String)resource.getContent();

        //change the XML content
        document = document.toLowerCase();

        resource.setContent(document);
        col.storeResource(resource);
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -