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

📄 eaf24.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     EAF24.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.eudico.server.corpora.clomimpl.dobes;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import java.util.Locale;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;/**   <p>   You can call this class a factory: it instantiates a DOM object.   You can also call it an API for a specific DOM object.   <p>   You explicitely have to add the ANNOTATION_DOCUMENT to the EAF DOM:   <code>   Element e = newAnnotationDocument(new Date()+"", "gregor", "version 1.0");   daf.appendChild(e);   </code>   <p>   To write the DOM to file, use   getDocumentElement(), which returns all including Elements.   <code>   System.out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");   System.out.println("<!DOCTYPE Trans SYSTEM \"EAFv2.0.dtd\">");   System.out.println(""+daf.getDocumentElement());   </code>   The arguments of the newELEMENT() methods must not be null, if not otheriwse   stated. A RuntimeException will be thrown if an argument is null.   This is much better than to silently write incomplete data.   @version jun 2004 Support for Controlled Vocabulary elements added   @version Feb 2006 support for LinkedFileDescriptors and stereotype Included_In added   @version Jan 2007 support for Annotator attribute added to the tier element                     added element PROPERTY within the HEADER element*/public class EAF24 {    /**        Three Time Units     */    public final static String TIME_UNIT_MILLISEC = "milliseconds";    /** Holds value of property DOCUMENT ME! */    public final static String TIME_UNIT_NTSC = "NTSC-frames";    /** Holds value of property DOCUMENT ME! */    public final static String TIME_UNIT_PAL = "PAL-frames";    /**       The DOM document variable doc is a private,       all newELEMENT method calls will modify it.     */    private Document doc;    /**       Remember to append a ANNOTATION_DOCUMENT Element to the doc variable using       appendChild();    */    public EAF24() throws Exception {        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();        DocumentBuilder db = dbf.newDocumentBuilder();        this.doc = db.newDocument();    }    /**       EAF is per se a subtype of org.w3c.dom.Document.       It is not inheriting from Document, because only two methods have to be       supported.     */    /** see org.w3c.dom.Element.getDocumentElement() */    public final Element getDocumentElement() {        return this.doc.getDocumentElement();    }    /** see org.w3c.dom.Element.appendChild() */    public final Node appendChild(Node e) {        return this.doc.appendChild(e);    }    /**       All methods "newELEMENT()" are returning an obkect of type org.w3c.dom.Element       with name ELEMENT.       Technically speaking, they encapsulate       the two methods Element.setAttribute() and Element.createTextNode() and do some       housekeeping.    */    /**       Use result in <your daf variable>.appendChild();       @return a new Element ANNOTATION_DOCUMENT.       @param creationDate Creation date of this annotation       @param author Author of this annotation.       @param version --->documentation missing<---     */    public final Element newAnnotationDocument(String creationDate,        String author, String version) {        if (creationDate == null) {            throw new RuntimeException("EAF");        }        if (author == null) {            throw new RuntimeException("EAF");        }        if (version == null) {            throw new RuntimeException("EAF");        }        Element result = this.doc.createElement("ANNOTATION_DOCUMENT");        result.setAttribute("xmlns:xsi",            "http://www.w3.org/2001/XMLSchema-instance");        result.setAttribute("xsi:noNamespaceSchemaLocation",            "http://www.mpi.nl/tools/elan/EAFv2.4.xsd");        result.setAttribute("DATE", creationDate);        result.setAttribute("AUTHOR", author);        result.setAttribute("VERSION", version);        result.setAttribute("FORMAT", "2.4");        return result;    }    /**       Use result in annotationDocument.appendChild();       @return a new Element HEADER.       @param mediaFile --->documentation missing<---       @param timeUnits --->documentation missing<---     */    public final Element newHeader(String mediaFile, String timeUnits) {        if (mediaFile == null) {            throw new RuntimeException("EAF");        }        if (timeUnits == null) {            throw new RuntimeException("EAF");        }        Element result = this.doc.createElement("HEADER");        result.setAttribute("MEDIA_FILE", mediaFile);        result.setAttribute("TIME_UNITS", timeUnits);        return result;    }    /**       @return a new Element HEADER with a default time unit of milliseconds.       @param mediaFile same meaning as above     */    public final Element newHeader(String mediaFile) {        if (mediaFile == null) {            throw new RuntimeException("EAF");        }        return newHeader(mediaFile, EAF24.TIME_UNIT_MILLISEC);    }    /**     * Since eaf 2.1: support MediaDescriptors. For compatibility with     * ELAN 1.4.1 still maintain mediaFile for some time     */    public final Element newMediaDescriptor(String mediaURL, String mimeType,        String timeOrigin, String extractedFrom) {        if (mediaURL == null) {            throw new RuntimeException("EAF");        }        if (mimeType == null) {            throw new RuntimeException("EAF");        }        Element mdElement = this.doc.createElement("MEDIA_DESCRIPTOR");        mdElement.setAttribute("MEDIA_URL", mediaURL);        mdElement.setAttribute("MIME_TYPE", mimeType);        if (timeOrigin != null) {            mdElement.setAttribute("TIME_ORIGIN", String.valueOf(timeOrigin));        }        if (extractedFrom != null) {            mdElement.setAttribute("EXTRACTED_FROM", extractedFrom);        }        return mdElement;    }    /**     * Introduced in eaf 2.3, descriptor of (non a/v) linked files.     *     * @param linkURL the url of the file     * @param mimeType the mimetype of the file     * @param origin the time origin or offset     * @param associatedWith the file this link is associated with     * @return an linked file element     */    public final Element newLinkedFileDescriptor(String linkURL,        String mimeType, String origin, String associatedWith) {        if (linkURL == null) {            throw new RuntimeException("EAF");        }        Element lfdElement = this.doc.createElement("LINKED_FILE_DESCRIPTOR");        lfdElement.setAttribute("LINK_URL", linkURL);        if (mimeType == null) {            lfdElement.setAttribute("MIME_TYPE", "unknown");        } else {            lfdElement.setAttribute("MIME_TYPE", mimeType);        }        if (origin != null) {            lfdElement.setAttribute("TIME_ORIGIN", origin);        }        if (associatedWith != null) {            lfdElement.setAttribute("ASSOCIATED_WITH", associatedWith);        }        return lfdElement;    }    /**     * Introduced in EAF version 2.4. Document level property with an optional     * name attribute and string contents.     *     * @param name the name attribute     * @param value the content     * @return the property element     */    public final Element newProperty(String name, String value) {        Element propElement = this.doc.createElement("PROPERTY");        if ((name != null) && (name.length() > 0)) {            propElement.setAttribute("NAME", name);        }        if ((value != null) && (value.length() > 0)) {            propElement.appendChild(doc.createTextNode(value));        }        return propElement;    }    /**       Use result in annotationDocument.appendChild();       @return a new Element TIME_ORDER.     */    public final Element newTimeOrder() {        Element result = this.doc.createElement("TIME_ORDER");        return result;    }    /**

⌨️ 快捷键说明

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