Example usage for org.apache.solr.common.util XML escapeCharData

List of usage examples for org.apache.solr.common.util XML escapeCharData

Introduction

In this page you can find the example usage for org.apache.solr.common.util XML escapeCharData.

Prototype

public static void escapeCharData(String str, Writer out) throws IOException 

Source Link

Usage

From source file:co.diji.solr.XMLWriter.java

License:Apache License

/**Write a complete tag w/ attributes and cdata (the cdata is not enclosed in $lt;!CDATA[]!>
 * @param tag/*from ww  w . j  a  v  a  2  s.  c  om*/
 * @param attributes
 * @param cdata
 * @param escapeCdata
 * @param escapeAttr
 * @throws IOException
 */
public void writeCdataTag(String tag, Map<String, String> attributes, String cdata, boolean escapeCdata,
        boolean escapeAttr) throws IOException {
    writer.write('<');
    writer.write(tag);
    if (!attributes.isEmpty()) {
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
            writeAttr(entry.getKey(), entry.getValue(), escapeAttr);
        }
    }
    writer.write('>');
    if (cdata != null && cdata.length() > 0) {
        if (escapeCdata) {
            XML.escapeCharData(cdata, writer);
        } else {
            writer.write(cdata, 0, cdata.length());
        }
    }
    writer.write("</");
    writer.write(tag);
    writer.write('>');
}

From source file:co.diji.solr.XMLWriter.java

License:Apache License

public void writePrim(String tag, String name, String val, boolean escape) throws IOException {
    // OPT - we could use a temp char[] (or a StringBuilder) and if the
    // size was small enough to fit (if escape==false we can calc exact size)
    // then we could put things directly in the temp buf.
    // need to see what percent of CPU this takes up first though...
    // Could test a reusable StringBuilder...

    // is this needed here???
    // Only if a fieldtype calls writeStr or something
    // with a null val instead of calling writeNull
    /***//w  w  w  .java 2 s .  c  o  m
    if (val==null) {
      if (name==null) writer.write("<null/>");
      else writer.write("<null name=\"" + name + "/>");
    }
    ***/

    int contentLen = val.length();

    startTag(tag, name, contentLen == 0);
    if (contentLen == 0)
        return;

    if (escape) {
        XML.escapeCharData(val, writer);
    } else {
        writer.write(val, 0, contentLen);
    }

    writer.write("</");
    writer.write(tag);
    writer.write('>');
}

From source file:net.yacy.cora.federate.solr.responsewriter.EnhancedXMLResponseWriter.java

License:Open Source License

private static void writeTag(final Writer writer, final String tag, final String nameAttr, final String val,
        final boolean escape) throws IOException {
    int contentLen = val.length();
    if (contentLen == 0) {
        startTagClose(writer, tag, nameAttr);
        return;//from w  w w  .  ja  v a2s  .  c o m
    }
    startTagOpen(writer, tag, nameAttr);
    if (escape) {
        XML.escapeCharData(val, writer);
    } else {
        writer.write(val, 0, contentLen);
    }
    writer.write("</");
    writer.write(tag);
    writer.write('>');
    writer.write(lb);
}

From source file:net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter.java

License:Open Source License

@Override
public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp)
        throws IOException {
    assert rsp.getValues().get("responseHeader") != null;
    assert rsp.getValues().get("response") != null;

    long start = System.currentTimeMillis();

    SimpleOrderedMap<Object> responseHeader = (SimpleOrderedMap<Object>) rsp.getResponseHeader();
    DocList response = ((ResultContext) rsp.getValues().get("response")).docs;
    @SuppressWarnings("unchecked")
    SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) rsp.getValues().get("highlighting");
    Map<String, LinkedHashSet<String>> snippets = OpensearchResponseWriter.highlighting(highlighting);
    Map<Object, Object> context = request.getContext();

    // parse response header
    ResHead resHead = new ResHead();
    NamedList<?> val0 = (NamedList<?>) responseHeader.get("params");
    resHead.rows = Integer.parseInt((String) val0.get(CommonParams.ROWS));
    resHead.offset = response.offset(); // equal to 'start'
    resHead.numFound = response.matches();
    //resHead.df = (String) val0.get("df");
    //resHead.q = (String) val0.get("q");
    //resHead.wt = (String) val0.get("wt");
    //resHead.status = (Integer) responseHeader.get("status");
    //resHead.QTime = (Integer) responseHeader.get("QTime");
    //resHead.maxScore = response.maxScore();

    // write header
    writer.write(XML_START);/*  w w  w .  j a va  2s.  co m*/
    String query = request.getParams().get("originalQuery");
    String site = getContextString(context, "site", "");
    String sort = getContextString(context, "sort", "");
    String client = getContextString(context, "client", "");
    String ip = getContextString(context, "ip", "");
    String access = getContextString(context, "access", "");
    String entqr = getContextString(context, "entqr", "");
    OpensearchResponseWriter.solitaireTag(writer, "TM", Long.toString(System.currentTimeMillis() - start));
    OpensearchResponseWriter.solitaireTag(writer, "Q", query);
    paramTag(writer, "sort", sort);
    paramTag(writer, "output", "xml_no_dtd");
    paramTag(writer, "ie", "UTF-8");
    paramTag(writer, "oe", "UTF-8");
    paramTag(writer, "client", client);
    paramTag(writer, "q", query);
    paramTag(writer, "site", site);
    paramTag(writer, "start", Integer.toString(resHead.offset));
    paramTag(writer, "num", Integer.toString(resHead.rows));
    paramTag(writer, "ip", ip);
    paramTag(writer, "access", access); // p - search only public content, s - search only secure content, a - search all content, both public and secure
    paramTag(writer, "entqr", entqr); // query expansion policy; (entqr=1) -- Uses only the search appliance's synonym file, (entqr=1) -- Uses only the search appliance's synonym file, (entqr=3) -- Uses both standard and local synonym files.

    // body introduction
    final int responseCount = response.size();
    writer.write("<RES SN=\"" + (resHead.offset + 1) + "\" EN=\"" + (resHead.offset + responseCount) + "\">");
    writer.write(lb); // The index (1-based) of the first and last search result returned in this result set.
    writer.write("<M>" + resHead.numFound + "</M>");
    writer.write(lb); // The estimated total number of results for the search.
    writer.write("<FI/>");
    writer.write(lb); // Indicates that document filtering was performed during this search.
    int nextStart = resHead.offset + responseCount;
    int nextNum = Math.min(resHead.numFound - nextStart, responseCount < resHead.rows ? 0 : resHead.rows);
    int prevStart = resHead.offset - resHead.rows;
    if (prevStart >= 0 || nextNum > 0) {
        writer.write("<NB>");
        if (prevStart >= 0) {
            writer.write("<PU>");
            XML.escapeCharData("/gsa/search?q=" + request.getParams().get(CommonParams.Q) + "&site=" + site
                    + "&lr=&ie=UTF-8&oe=UTF-8&output=xml_no_dtd&client=" + client + "&access=" + access
                    + "&sort=" + sort + "&start=" + prevStart + "&sa=N", writer); // a relative URL pointing to the NEXT results page.
            writer.write("</PU>");
        }
        if (nextNum > 0) {
            writer.write("<NU>");
            XML.escapeCharData("/gsa/search?q=" + request.getParams().get(CommonParams.Q) + "&site=" + site
                    + "&lr=&ie=UTF-8&oe=UTF-8&output=xml_no_dtd&client=" + client + "&access=" + access
                    + "&sort=" + sort + "&start=" + nextStart + "&num=" + nextNum + "&sa=N", writer); // a relative URL pointing to the NEXT results page.
            writer.write("</NU>");
        }
        writer.write("</NB>");
    }
    writer.write(lb);

    // parse body
    SolrIndexSearcher searcher = request.getSearcher();
    DocIterator iterator = response.iterator();
    String urlhash = null;
    for (int i = 0; i < responseCount; i++) {
        int id = iterator.nextDoc();
        Document doc = searcher.doc(id, SOLR_FIELDS);
        List<IndexableField> fields = doc.getFields();

        // pre-scan the fields to get the mime-type            
        String mime = "";
        for (IndexableField value : fields) {
            String fieldName = value.name();
            if (CollectionSchema.content_type.getSolrFieldName().equals(fieldName)) {
                mime = value.stringValue();
                break;
            }
        }

        // write the R header for a search result
        writer.write("<R N=\"" + (resHead.offset + i + 1) + "\"" + (i == 1 ? " L=\"2\"" : "")
                + (mime != null && mime.length() > 0 ? " MIME=\"" + mime + "\"" : "") + ">");
        writer.write(lb);
        //List<String> texts = new ArrayList<String>();
        List<String> descriptions = new ArrayList<String>();
        List<String> collections = new ArrayList<String>();
        int size = 0;
        boolean title_written = false; // the solr index may contain several; we take only the first which should be the visible tag in <title></title>
        String title = null;
        for (IndexableField value : fields) {
            String fieldName = value.name();

            // apply generic matching rule
            String stag = field2tag.get(fieldName);
            if (stag != null) {
                OpensearchResponseWriter.solitaireTag(writer, stag, value.stringValue());
                continue;
            }

            // if the rule is not generic, use the specific here
            if (CollectionSchema.id.getSolrFieldName().equals(fieldName)) {
                urlhash = value.stringValue();
                continue;
            }
            if (CollectionSchema.sku.getSolrFieldName().equals(fieldName)) {
                OpensearchResponseWriter.solitaireTag(writer, GSAToken.U.name(), value.stringValue());
                OpensearchResponseWriter.solitaireTag(writer, GSAToken.UE.name(), value.stringValue());
                continue;
            }
            if (CollectionSchema.title.getSolrFieldName().equals(fieldName) && !title_written) {
                title = value.stringValue();
                OpensearchResponseWriter.solitaireTag(writer, GSAToken.T.name(), highlight(title, query));
                //texts.add(value.stringValue());
                title_written = true;
                continue;
            }
            if (CollectionSchema.description_txt.getSolrFieldName().equals(fieldName)) {
                descriptions.add(value.stringValue());
                //texts.adds(description);
                continue;
            }
            if (CollectionSchema.last_modified.getSolrFieldName().equals(fieldName)) {
                Date d = new Date(Long.parseLong(value.stringValue()));
                writer.write("<FS NAME=\"date\" VALUE=\"" + HeaderFramework.formatGSAFS(d) + "\"/>\n");
                //OpensearchResponseWriter.solitaireTag(writer, GSAToken.CACHE_LAST_MODIFIED.getSolrFieldName(), HeaderFramework.formatRFC1123(d));
                //texts.add(value.stringValue());
                continue;
            }
            if (CollectionSchema.load_date_dt.getSolrFieldName().equals(fieldName)) {
                Date d = new Date(Long.parseLong(value.stringValue()));
                OpensearchResponseWriter.solitaireTag(writer, GSAToken.CRAWLDATE.name(),
                        HeaderFramework.formatRFC1123(d));
                //texts.add(value.stringValue());
                continue;
            }
            if (CollectionSchema.size_i.getSolrFieldName().equals(fieldName)) {
                size = value.stringValue() != null && value.stringValue().length() > 0
                        ? Integer.parseInt(value.stringValue())
                        : -1;
                continue;
            }
            if (CollectionSchema.collection_sxt.getSolrFieldName().equals(fieldName)) {
                collections.add(value.stringValue());
                continue;
            }
            //System.out.println("superfluous field: " + fieldName + ": " + value.stringValue()); // this can be avoided setting the enableLazyFieldLoading = false in solrconfig.xml
        }
        // compute snippet from texts
        LinkedHashSet<String> snippet = urlhash == null ? null : snippets.get(urlhash);
        OpensearchResponseWriter.removeSubsumedTitle(snippet, title);
        OpensearchResponseWriter.solitaireTag(writer, GSAToken.S.name(),
                snippet == null || snippet.size() == 0 ? (descriptions.size() > 0 ? descriptions.get(0) : "")
                        : OpensearchResponseWriter.getLargestSnippet(snippet));
        OpensearchResponseWriter.solitaireTag(writer, GSAToken.GD.name(),
                descriptions.size() > 0 ? descriptions.get(0) : "");
        String cols = collections.toString();
        if (collections.size() > 0)
            OpensearchResponseWriter.solitaireTag(writer, "COLS" /*SPECIAL!*/,
                    collections.size() > 1 ? cols.substring(1, cols.length() - 1).replaceAll(" ", "")
                            : collections.get(0));
        writer.write("<HAS><L/><C SZ=\"");
        writer.write(Integer.toString(size / 1024));
        writer.write("k\" CID=\"");
        writer.write(urlhash);
        writer.write("\" ENC=\"UTF-8\"/></HAS>\n");
        if (YaCyVer == null)
            YaCyVer = yacyVersion.thisVersion().getName() + "/"
                    + Switchboard.getSwitchboard().peers.mySeed().hash;
        OpensearchResponseWriter.solitaireTag(writer, GSAToken.ENT_SOURCE.name(), YaCyVer);
        OpensearchResponseWriter.closeTag(writer, "R");
    }
    writer.write("</RES>");
    writer.write(lb);
    writer.write(XML_STOP);
}

From source file:net.yacy.cora.federate.solr.responsewriter.OpensearchResponseWriter.java

License:Open Source License

@Override
public void write(final Writer writer, final SolrQueryRequest request, final SolrQueryResponse rsp)
        throws IOException {

    NamedList<?> values = rsp.getValues();

    assert values.get("responseHeader") != null;
    assert values.get("response") != null;

    SimpleOrderedMap<Object> responseHeader = (SimpleOrderedMap<Object>) rsp.getResponseHeader();
    DocList response = ((ResultContext) values.get("response")).docs;
    @SuppressWarnings("unchecked")
    SimpleOrderedMap<Object> facetCounts = (SimpleOrderedMap<Object>) values.get("facet_counts");
    @SuppressWarnings("unchecked")
    SimpleOrderedMap<Object> facetFields = facetCounts == null || facetCounts.size() == 0 ? null
            : (SimpleOrderedMap<Object>) facetCounts.get("facet_fields");
    @SuppressWarnings("unchecked")
    SimpleOrderedMap<Object> highlighting = (SimpleOrderedMap<Object>) values.get("highlighting");
    Map<String, LinkedHashSet<String>> snippets = highlighting(highlighting);

    // parse response header
    ResHead resHead = new ResHead();
    NamedList<?> val0 = (NamedList<?>) responseHeader.get("params");
    resHead.rows = Integer.parseInt((String) val0.get("rows"));
    resHead.offset = response.offset(); // equal to 'start'
    resHead.numFound = response.matches();
    //resHead.df = (String) val0.get("df");
    //resHead.q = (String) val0.get("q");
    //resHead.wt = (String) val0.get("wt");
    //resHead.status = (Integer) responseHeader.get("status");
    //resHead.QTime = (Integer) responseHeader.get("QTime");
    //resHead.maxScore = response.maxScore();

    // write header
    writer.write(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<?xml-stylesheet type='text/xsl' href='/yacysearch.xsl' version='1.0'?>\n"
            + "<rss version=\"2.0\"\n" + "    xmlns:yacy=\"http://www.yacy.net/\"\n"
            + "    xmlns:opensearch=\"http://a9.com/-/spec/opensearch/1.1/\"\n"
            + "    xmlns:media=\"http://search.yahoo.com/mrss/\"\n"
            + "    xmlns:atom=\"http://www.w3.org/2005/Atom\"\n"
            + "    xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
            + "    xmlns:geo=\"http://www.w3.org/2003/01/geo/wgs84_pos#\"\n" + ">\n").toCharArray());
    openTag(writer, "channel");
    solitaireTag(writer, "opensearch:totalResults", Integer.toString(resHead.numFound));
    solitaireTag(writer, "opensearch:startIndex", Integer.toString(resHead.offset));
    solitaireTag(writer, "opensearch:itemsPerPage", Integer.toString(resHead.rows));
    solitaireTag(writer, RSSMessage.Token.title.name(), this.title);
    writer.write(/* w  w  w.j  a va2 s  .co m*/
            "<atom:link rel=\"search\" href=\"/opensearchdescription.xml\" type=\"application/opensearchdescription+xml\"/>");
    solitaireTag(writer, "description", "Search Result");
    //solitaireTag(writer, "link", "");
    //solitaireTag(writer, "image", "");

    // parse body
    final int responseCount = response.size();
    SolrIndexSearcher searcher = request.getSearcher();
    DocIterator iterator = response.iterator();
    String urlhash = null;
    for (int i = 0; i < responseCount; i++) {
        openTag(writer, "item");
        int id = iterator.nextDoc();
        Document doc = searcher.doc(id, SOLR_FIELDS);
        List<IndexableField> fields = doc.getFields();
        int fieldc = fields.size();
        List<String> texts = new ArrayList<String>();
        List<String> descriptions = new ArrayList<String>();
        String title = "";
        for (int j = 0; j < fieldc; j++) {
            IndexableField value = fields.get(j);
            String fieldName = value.name();

            // apply generic matching rule
            String stag = field2tag.get(fieldName);
            if (stag != null) {
                solitaireTag(writer, stag, value.stringValue());
                continue;
            }

            // take apart the url
            if (CollectionSchema.sku.getSolrFieldName().equals(fieldName)) {
                String u = value.stringValue();
                solitaireTag(writer, RSSMessage.Token.link.name(), u);
                try {
                    MultiProtocolURL url = new MultiProtocolURL(u);
                    solitaireTag(writer, YaCyMetadata.host.getURIref(), url.getHost());
                    solitaireTag(writer, YaCyMetadata.path.getURIref(), url.getPath());
                    solitaireTag(writer, YaCyMetadata.file.getURIref(), url.getFileName());
                } catch (final MalformedURLException e) {
                }
                continue;
            }

            // if the rule is not generic, use the specific here
            if (CollectionSchema.id.getSolrFieldName().equals(fieldName)) {
                urlhash = value.stringValue();
                solitaireTag(writer, RSSMessage.Token.guid.name(), urlhash, "isPermaLink=\"false\"");
                continue;
            }
            if (CollectionSchema.title.getSolrFieldName().equals(fieldName)) {
                title = value.stringValue();
                texts.add(title);
                continue;
            }
            if (CollectionSchema.last_modified.getSolrFieldName().equals(fieldName)) {
                Date d = new Date(Long.parseLong(value.stringValue()));
                solitaireTag(writer, RSSMessage.Token.pubDate.name(), HeaderFramework.formatRFC1123(d));
                continue;
            }
            if (CollectionSchema.description_txt.getSolrFieldName().equals(fieldName)) {
                String description = value.stringValue();
                descriptions.add(description);
                solitaireTag(writer, DublinCore.Description.getURIref(), description);
                texts.add(description);
                continue;
            }
            if (CollectionSchema.text_t.getSolrFieldName().equals(fieldName)) {
                texts.add(value.stringValue());
                continue;
            }
            if (CollectionSchema.size_i.getSolrFieldName().equals(fieldName)) {
                int size = value.numericValue().intValue();
                solitaireTag(writer, YaCyMetadata.size.getURIref(), Integer.toString(size));
                solitaireTag(writer, YaCyMetadata.sizename.getURIref(), RSSMessage.sizename(size));
                continue;
            }
            if (CollectionSchema.h1_txt.getSolrFieldName().equals(fieldName)
                    || CollectionSchema.h2_txt.getSolrFieldName().equals(fieldName)
                    || CollectionSchema.h3_txt.getSolrFieldName().equals(fieldName)
                    || CollectionSchema.h4_txt.getSolrFieldName().equals(fieldName)
                    || CollectionSchema.h5_txt.getSolrFieldName().equals(fieldName)
                    || CollectionSchema.h6_txt.getSolrFieldName().equals(fieldName)) {
                // because these are multi-valued fields, there can be several of each
                texts.add(value.stringValue());
                continue;
            }
        }

        // compute snippet from texts
        solitaireTag(writer, RSSMessage.Token.title.name(),
                title.length() == 0 ? (texts.size() == 0 ? "" : texts.get(0)) : title);
        LinkedHashSet<String> snippet = urlhash == null ? null : snippets.get(urlhash);
        String tagname = RSSMessage.Token.description.name();
        if (snippet == null || snippet.size() == 0) {
            writer.write("<");
            writer.write(tagname);
            writer.write('>');
            for (String d : descriptions) {
                XML.escapeCharData(d, writer);
            }
            writer.write("</");
            writer.write(tagname);
            writer.write(">\n");
        } else {
            removeSubsumedTitle(snippet, title);
            solitaireTag(writer, tagname, getLargestSnippet(snippet)); // snippet may be size=0
        }

        solitaireTag(writer, DublinCore.Subject.getURIref(),
                doc.get(CollectionSchema.keywords.getSolrFieldName()));

        closeTag(writer, "item");
    }

    openTag(writer, "yacy:navigation");

    // the facets can be created with the options &facet=true&facet.mincount=1&facet.field=host_s&facet.field=url_file_ext_s&facet.field=url_protocol_s&facet.field=author_sxt
    @SuppressWarnings("unchecked")
    NamedList<Integer> domains = facetFields == null ? null
            : (NamedList<Integer>) facetFields.get(CollectionSchema.host_s.getSolrFieldName());
    @SuppressWarnings("unchecked")
    NamedList<Integer> filetypes = facetFields == null ? null
            : (NamedList<Integer>) facetFields.get(CollectionSchema.url_file_ext_s.getSolrFieldName());
    @SuppressWarnings("unchecked")
    NamedList<Integer> protocols = facetFields == null ? null
            : (NamedList<Integer>) facetFields.get(CollectionSchema.url_protocol_s.getSolrFieldName());
    @SuppressWarnings("unchecked")
    NamedList<Integer> authors = facetFields == null ? null
            : (NamedList<Integer>) facetFields.get(CollectionSchema.author_sxt.getSolrFieldName());
    @SuppressWarnings("unchecked")
    NamedList<Integer> collections = facetFields == null ? null
            : (NamedList<Integer>) facetFields.get(CollectionSchema.collection_sxt.getSolrFieldName());

    if (domains != null) {
        openTag(writer,
                "yacy:facet name=\"domains\" displayname=\"Domains\" type=\"String\" min=\"0\" max=\"0\" mean=\"0\"");
        for (Map.Entry<String, Integer> entry : domains)
            facetEntry(writer, "site", entry.getKey(), Integer.toString(entry.getValue()));
        closeTag(writer, "yacy:facet");
    }
    if (filetypes != null) {
        openTag(writer,
                "yacy:facet name=\"filetypes\" displayname=\"Filetypes\" type=\"String\" min=\"0\" max=\"0\" mean=\"0\"");
        for (Map.Entry<String, Integer> entry : filetypes)
            facetEntry(writer, "filetype", entry.getKey(), Integer.toString(entry.getValue()));
        closeTag(writer, "yacy:facet");
    }
    if (protocols != null) {
        openTag(writer,
                "yacy:facet name=\"protocols\" displayname=\"Protocols\" type=\"String\" min=\"0\" max=\"0\" mean=\"0\"");
        for (Map.Entry<String, Integer> entry : protocols)
            facetEntry(writer, "protocol", entry.getKey(), Integer.toString(entry.getValue()));
        closeTag(writer, "yacy:facet");
    }
    if (authors != null) {
        openTag(writer,
                "yacy:facet name=\"authors\" displayname=\"Authors\" type=\"String\" min=\"0\" max=\"0\" mean=\"0\"");
        for (Map.Entry<String, Integer> entry : authors)
            facetEntry(writer, "author", entry.getKey(), Integer.toString(entry.getValue()));
        closeTag(writer, "yacy:facet");
    }
    if (collections != null) {
        openTag(writer,
                "yacy:facet name=\"collections\" displayname=\"Collections\" type=\"String\" min=\"0\" max=\"0\" mean=\"0\"");
        for (Map.Entry<String, Integer> entry : collections)
            facetEntry(writer, "collection", entry.getKey(), Integer.toString(entry.getValue()));
        closeTag(writer, "yacy:facet");
    }
    closeTag(writer, "yacy:navigation");

    closeTag(writer, "channel");
    writer.write("</rss>\n".toCharArray());
}

From source file:net.yacy.cora.federate.solr.responsewriter.OpensearchResponseWriter.java

License:Open Source License

public static void solitaireTag(final Writer writer, final String tagname, String value) throws IOException {
    if (value == null || value.length() == 0)
        return;/* w w w  . j a va2s .  c om*/
    writer.write("<");
    writer.write(tagname);
    writer.write('>');
    XML.escapeCharData(value, writer);
    writer.write("</");
    writer.write(tagname);
    writer.write(">\n");
}

From source file:net.yacy.cora.federate.solr.responsewriter.OpensearchResponseWriter.java

License:Open Source License

private static void facetEntry(final Writer writer, final String modifier, final String propname, String value)
        throws IOException {
    writer.write("<yacy:element name=\"");
    XML.escapeCharData(propname, writer);
    writer.write("\" count=\"");
    XML.escapeCharData(value, writer);// w w w  .j a  v a2s. co  m
    writer.write("\" modifier=\"");
    writer.write(modifier);
    writer.write("%3A");
    XML.escapeCharData(propname, writer);
    writer.write("\" />\n");
}

From source file:org.codelibs.elasticsearch.solr.solr.XMLWriter.java

License:Apache License

/**
 * Write a complete tag w/ attributes and cdata (the cdata is not enclosed
 * in $lt;!CDATA[]!&gt;//  ww w. jav a  2s. com
 *
 * @param tag
 * @param attributes
 * @param cdata
 * @param escapeCdata
 * @param escapeAttr
 * @throws IOException
 */
public void writeCdataTag(final String tag, final Map<String, String> attributes, final String cdata,
        final boolean escapeCdata, final boolean escapeAttr) throws IOException {
    writer.write('<');
    writer.write(tag);
    if (!attributes.isEmpty()) {
        for (final Map.Entry<String, String> entry : attributes.entrySet()) {
            this.writeAttr(entry.getKey(), entry.getValue(), escapeAttr);
        }
    }
    writer.write('>');
    if (cdata != null && cdata.length() > 0) {
        if (escapeCdata) {
            XML.escapeCharData(cdata, writer);
        } else {
            writer.write(cdata, 0, cdata.length());
        }
    }
    writer.write("</");
    writer.write(tag);
    writer.write('>');
}

From source file:org.codelibs.elasticsearch.solr.solr.XMLWriter.java

License:Apache License

public void writePrim(final String tag, final String name, final String val, final boolean escape)
        throws IOException {
    // OPT - we could use a temp char[] (or a StringBuilder) and if the
    // size was small enough to fit (if escape==false we can calc exact
    // size)/*from w w w.j a v a2  s  .co m*/
    // then we could put things directly in the temp buf.
    // need to see what percent of CPU this takes up first though...
    // Could test a reusable StringBuilder...

    // is this needed here???
    // Only if a fieldtype calls writeStr or something
    // with a null val instead of calling writeNull
    /***
     * if (val==null) { if (name==null) writer.write("<null/>"); else
     * writer.write("<null name=\"" + name + "/>"); }
     ***/

    final int contentLen = val.length();

    this.startTag(tag, name, contentLen == 0);
    if (contentLen == 0) {
        return;
    }

    if (escape) {
        XML.escapeCharData(val, writer);
    } else {
        writer.write(val, 0, contentLen);
    }

    writer.write("</");
    writer.write(tag);
    writer.write('>');
}