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

📄 query2html.java

📁 编辑视频文件
💻 JAVA
字号:
/* * File:     Query2HTML.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.search.content.query.viewer;import mpi.search.SearchLocale;import mpi.search.content.query.model.AnchorConstraint;import mpi.search.content.query.model.Constraint;import mpi.search.content.query.model.ContentQuery;import mpi.search.content.query.model.DependentConstraint;import mpi.search.content.query.model.RestrictedAnchorConstraint;import java.util.HashMap;import java.util.Iterator;/** * $Id: Query2HTML.java,v 1.3 2007/02/06 16:36:07 klasal Exp $ * * @author $author$ * @version $Revision: 1.3 $ */public class Query2HTML {    /** Holds value of property DOCUMENT ME! */    public static final String bodyStyle = "body { font-weight:normal; margin-top: 5px; }\n";    /** Holds value of property DOCUMENT ME! */    public static final String constraintStyle = ".constraint { border-width:1px; border-style:solid; border-color:gray; padding:10px;font-size:medium;}\n";    /** Holds value of property DOCUMENT ME! */    public static final String patternStyle = ".pattern { background:#FFFFFF; white-space:pre; font-weight:bold;}\n";    /** Holds value of property DOCUMENT ME! */    static final String css = "<style type=\"text/css\">" + bodyStyle +        constraintStyle + patternStyle + "<style>";    /**     * appends single constraint as HTML to StringBuffer (without opening and closing BODY-tag)     *     * @param sb buffer to append on     * @param constraint to be rendered in HTML     */    public static void appendConstraint(StringBuffer sb, Constraint constraint) {        if (constraint instanceof DependentConstraint) {            sb.append(SearchLocale.getString("Search.Query.With").toUpperCase() +                " " + SearchLocale.getString("Search.Query.Constraint"));        } else {            sb.append(SearchLocale.getString("Search.Query.Find").toUpperCase());        }        sb.append("<BR><div class=\"constraint\">");        if (constraint instanceof RestrictedAnchorConstraint) {            sb.append(((RestrictedAnchorConstraint) constraint).getComment());        } else {            sb.append(SearchLocale.getString(constraint.getQuantifier()));            sb.append(" " + SearchLocale.getString("Search.Annotation_SG") +                " ");            String[] tierNames = constraint.getTierNames();            if (tierNames.length > 0) {                if (!tierNames[0].equals(Constraint.ALL_TIERS)) {                    sb.append(SearchLocale.getString("Search.Constraint.OnTier") +                        " ");                    for (int j = 0; j < tierNames.length; j++) {                        sb.append("<b>" + tierNames[j] + " </b>");                    }                }            }            if (!constraint.getPattern().equals("")) {                if (constraint instanceof AnchorConstraint) {                    sb.append(SearchLocale.getString("Search.Constraint.That") +                        " ");                }                sb.append(SearchLocale.getString("Search.Constraint.Matches") +                    " ");                if (constraint.isCaseSensitive()) {                    sb.append(SearchLocale.getString(                            "Search.Constraint.CaseSensitive") + " ");                }                sb.append(constraint.isRegEx()                    ? (SearchLocale.getString(                        "Search.Constraint.RegularExpression") + " ")                    : (SearchLocale.getString("Search.Constraint.String") +                    " "));                sb.append(                    "<span class=\"pattern\" style=\"white-space:pre;\"><b> " +                    constraint.getPattern() + " </b></span>");            }            sb.append("<BR>");            if (constraint instanceof AnchorConstraint) {                if ((constraint.getLowerBoundary() > Long.MIN_VALUE) ||                        (constraint.getUpperBoundary() < Long.MAX_VALUE)) {                    if (constraint.getPattern().equals("")) {                        sb.append(SearchLocale.getString(                                "Search.Constraint.That"));                    } else {                        sb.append(SearchLocale.getString("Search.And"));                    }                    sb.append(" " +                        SearchLocale.getString(constraint.getUnit()) + " " +                        SearchLocale.getString("Search.Interval") + " [" +                        constraint.getLowerBoundary() + " ms ; " +                        constraint.getUpperBoundaryAsString() + " ms]\n");                }            } else {                if (constraint.getMode().equals(Constraint.STRUCTURAL)) {                    sb.append(SearchLocale.getString(                            "Search.Constraint.Distance") + " " +                        constraint.getLowerBoundaryAsString() + " " +                        SearchLocale.getString("Search.To") + " " +                        constraint.getUpperBoundaryAsString() + " " +                        constraint.getUnit() + " ");                } else {                    if (constraint.getPattern().equals("")) {                        sb.append(SearchLocale.getString(                                "Search.Constraint.That") + " ");                    } else {                        sb.append(SearchLocale.getString("Search.And") + " ");                    }                    String unit = SearchLocale.getString(constraint.getUnit());                    boolean constraintWithDistance = Constraint.WITHIN_OVERALL_DISTANCE.equals(constraint.getUnit()) ||                        Constraint.WITHIN_DISTANCE_TO_LEFT_BOUNDARY.equals(constraint.getUnit()) ||                        Constraint.WITHIN_DISTANCE_TO_RIGHT_BOUNDARY.equals(constraint.getUnit()) ||                        Constraint.BEFORE_LEFT_DISTANCE.equals(constraint.getUnit()) ||                        Constraint.AFTER_RIGHT_DISTANCE.equals(constraint.getUnit());                    if (constraintWithDistance) {                        unit = unit.replaceFirst("\\.\\.\\.",                                constraint.getUpperBoundaryAsString() + " ms");                    }                    sb.append(unit);                }                sb.append("\n");            }            sb.append("\n");            HashMap attributes = constraint.getAttributes();            if (attributes != null) {                Iterator iter = attributes.keySet().iterator();                while (iter.hasNext()) {                    String key = (String) iter.next();                    String attributeValue = (String) attributes.get(key);                    if (!attributeValue.equals("*") &&                            !attributeValue.equals("") &&                            !attributeValue.equals("ANY")) {                        sb.append(" " + key + "=");                        if (attributeValue.equals(">0")) {                            sb.append("[^0]");                        } else if (attributeValue.equals(">1")) {                            sb.append("[^01]");                        } else {                            sb.append(attributeValue);                        }                    }                }            }        }        sb.append("</div>\n");    }    /**     * appends all constraints of a query as tree like structure     *     * @param sb Buffer to append on     * @param query     */    public static void appendQuery(StringBuffer sb, ContentQuery query) {        Constraint anchorConstraint = query.getAnchorConstraint();        appendConstraint(sb, anchorConstraint);        appendDescendantConstraints(sb, anchorConstraint);    }    /**     * translates whole Query into HTML, including HTML start- and end-tags as well as css     *     * @param query to be rendered     *     * @return complete html document     */    public static String translate(ContentQuery query) {        StringBuffer sb = new StringBuffer();        sb.append("<html><head>" + css + "</head><body>");        Query2HTML.appendQuery(sb, query);        sb.append("</body></html>");        return sb.toString();    }    /**     * translates single constraint into HTML, including HTML start- and end-tags as well as css     *     * @param constraint to be rendered     *     * @return complete html document     */    public static String translate(Constraint constraint) {        StringBuffer sb = new StringBuffer();        sb.append("<html><head>" + css + "</head><body>");        appendConstraint(sb, constraint);        sb.append("</body></html>");        return sb.toString();    }    /**     * appends recursively descendants of a constraint (not the constraint itself) in a tree like structure     * @param sb     * @param parentConstraint     */    private static void appendDescendantConstraints(StringBuffer sb,        Constraint parentConstraint) {        if (parentConstraint.getChildCount() > 0) {            sb.append("<ul>");            for (int i = 0; i < parentConstraint.getChildCount(); i++) {                Constraint childConstraint = (Constraint) parentConstraint.getChildAt(i);                sb.append("<li>");                appendConstraint(sb, childConstraint);                appendDescendantConstraints(sb, childConstraint);                sb.append("</li>");            }            sb.append("</ul>");        }    }}

⌨️ 快捷键说明

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