Exemplo n.º 1
0
  public static String saxElementToDebugString(String uri, String qName, Attributes attributes) {
    // Open start tag
    final StringBuilder sb = new StringBuilder("<");
    sb.append(qName);

    final Set<String> declaredPrefixes = new HashSet<String>();
    mapPrefixIfNeeded(declaredPrefixes, uri, qName, sb);

    // Attributes if any
    for (int i = 0; i < attributes.getLength(); i++) {
      mapPrefixIfNeeded(declaredPrefixes, attributes.getURI(i), attributes.getQName(i), sb);

      sb.append(' ');
      sb.append(attributes.getQName(i));
      sb.append("=\"");
      sb.append(attributes.getValue(i));
      sb.append('\"');
    }

    // Close start tag
    sb.append('>');

    // Content
    sb.append("[...]");

    // Close element with end tag
    sb.append("</");
    sb.append(qName);
    sb.append('>');

    return sb.toString();
  }
Exemplo n.º 2
0
  private String unirMapeos(LinkedHashMap<String, String> mapa, Object[] descripciones) {

    // mapa(llave,punto)
    // descripciones en el mismo orden que el mapeo
    String comillas = "\"";
    StringBuilder builder = new StringBuilder();

    Iterator<String> iterador = mapa.keySet().iterator();

    int indice = 0;

    while (iterador.hasNext()) {
      String llave = iterador.next();

      String puntaje = mapa.get(llave);

      String descripcion =
          descripciones[indice].toString().equals("null") ? "" : descripciones[indice].toString();

      builder.append(comillas + descripcion + comillas + "," + comillas + puntaje + comillas + ",");

      indice++;
    }
    return builder.toString();
  }
Exemplo n.º 3
0
  public void flushCharacters(boolean finalFlush, boolean topLevel) throws SAXException {

    if (currentCharacters.length() > 0) {

      final String currentString = currentCharacters.toString();
      final char[] chars = currentString.toCharArray();
      if (StringUtils.isBlank(currentString) || !topLevel) {
        // Just output whitespace as is
        super.characters(chars, 0, chars.length);
      } else {

        // The first element received determines the type of separator
        checkDelimiters(XMLConstants.XHTML_NAMESPACE_URI, spanQName, topLevel);

        // Wrap any other text within an xhtml:span
        super.startElement(
            XMLConstants.XHTML_NAMESPACE_URI,
            "span",
            spanQName,
            getAttributesWithClass(XMLUtils.EMPTY_ATTRIBUTES));
        super.characters(chars, 0, chars.length);
        super.endElement(XMLConstants.XHTML_NAMESPACE_URI, "span", spanQName);
      }

      isCharacters = false;
      currentCharacters.setLength(0);
    }

    if (finalFlush) checkDelimiters(XMLConstants.XHTML_NAMESPACE_URI, spanQName, topLevel);
  }
Exemplo n.º 4
0
  public void flushCharacters(boolean finalFlush, boolean topLevelCharacters) throws SAXException {

    final String currentString = currentCharacters.toString();

    if (topLevelCharacters && !isAroundTableOrListElement) {
      // We handle top-level characters specially and wrap them in a span so we can hide them
      generateTopLevelSpanWithCharacters(currentCharacters.toString());
    } else {
      // Just output characters as is in deeper levels, or when around at table or list element
      final char[] chars = currentString.toCharArray();
      super.characters(chars, 0, chars.length);
    }

    currentCharacters.setLength(0);

    if (finalFlush) generateFirstDelimitersIfNeeded();
  }
Exemplo n.º 5
0
 /** Encode a URI and local name to an exploded QName (also known as a "Clark name") String. */
 public static String buildExplodedQName(String uri, String localname) {
   if ("".equals(uri)) return localname;
   else {
     final StringBuilder sb = new StringBuilder(uri.length() + localname.length() + 2);
     sb.append('{');
     sb.append(uri);
     sb.append('}');
     sb.append(localname);
     return sb.toString();
   }
 }
Exemplo n.º 6
0
 public String toString() {
   int size = args.size();
   StringBuilder sb =
       new StringBuilder(name)
           .append('@')
           .append(hashCode())
           .append(':')
           .append(size)
           .append('\n');
   for (int i = 0; i < size; ++i) {
     sb.append(args.get(i).get(0)).append('\n');
   }
   return sb.toString();
 }
Exemplo n.º 7
0
  private String obtenerNombre(Element raiz) {

    String comillas = "\"";

    StringBuilder nombre = new StringBuilder(comillas);

    String[] vars = {"CliApePat", "CliApeMat", "CliNom"};

    for (String s : vars) {
      nombre.append(raiz.getElementsByTagName(s).item(0).getTextContent() + " ");
    }
    nombre.append(comillas);

    return nombre.toString();
  }
Exemplo n.º 8
0
 /**
  * Returns canonical link to a bitstream in the item.
  *
  * @param item The DSpace Item that the bitstream is part of
  * @param bitstream The bitstream to link to
  * @returns a String link to the bitstream
  */
 private String makeBitstreamLink(Item item, Bitstream bitstream) {
   String name = bitstream.getName();
   StringBuilder result = new StringBuilder(contextPath);
   result.append("/bitstream/item/").append(String.valueOf(item.getID()));
   // append name although it isn't strictly necessary
   try {
     if (name != null) {
       result.append("/").append(Util.encodeBitstreamName(name, "UTF-8"));
     }
   } catch (UnsupportedEncodingException uee) {
     // just ignore it, we don't have to have a pretty
     // name on the end of the url because the sequence id will
     // locate it. However it means that links in this file might
     // not work....
   }
   result.append("?sequence=").append(String.valueOf(bitstream.getSequenceID()));
   return result.toString();
 }
Exemplo n.º 9
0
  public void characters(char[] buf, int offset, int len) throws SAXException {
    String s = new String(buf, offset, len);

    // take care of basic entity references before printing
    s = s.replaceAll("&", "&amp;");
    s = s.replaceAll("<", "&lt;");
    s = s.replaceAll(">", "&gt;");
    //    	s = s.replaceAll( "'", "&apos;" );
    //    	s = s.replaceAll( "\"", "&quot;" );

    if (textBuffer == null) {
      textBuffer = new StringBuilder(s);
    } else {
      textBuffer.append(s);
    }

    if (error_codeFlag) error_code = textBuffer.toString();
    if (error_textFlag) error_text = textBuffer.toString();
  }
Exemplo n.º 10
0
  /**
   * Make an NCName out of a non-blank string. Any characters that do not belong in an NCName are
   * converted to '_'.
   *
   * @param name source
   * @return NCName
   */
  public static String makeNCName(String name) {

    if (StringUtils.isBlank(name))
      throw new IllegalArgumentException("Name must not be blank or empty");

    final Name10Checker name10Checker = Name10Checker.getInstance();
    if (name10Checker.isValidNCName(name)) {
      return name;
    } else {
      final StringBuilder sb = new StringBuilder();
      final char start = name.charAt(0);
      sb.append(name10Checker.isNCNameStartChar(start) ? start : '_');

      for (int i = 1; i < name.length(); i++) {
        final char ch = name.charAt(i);
        sb.append(name10Checker.isNCNameChar(ch) ? ch : '_');
      }

      return sb.toString();
    }
  }
Exemplo n.º 11
0
 private static String nZeros(int n) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < n; i++) sb.append('0');
   return sb.toString();
 }
Exemplo n.º 12
0
 private static void addxmltext(SolrInputDocument doc, String field, StringBuilder text) {
   if (text != null && text.length() > 0) {
     doc.addField(field, text.toString());
   }
 }