Package java.lang

Examples of java.lang.StringBuffer


    {
        boolean tInSingleQuote = false;
        boolean tInDoubleQuote = false;
        boolean tInComment = false;

        StringBuffer tResult = new StringBuffer();
        for (int i=0; i<aToParse.length(); i++) {
            char c = aToParse.charAt(i);

            if (tInSingleQuote) {
                tResult.append(c);
                if (c=='\'') {
                    tInSingleQuote=false;
                }
            } else if (tInDoubleQuote) {
                tResult.append(c);
                if (c == '\"') {
                    tInDoubleQuote=false;
                }
            } else if(tInComment) {
                if(c=='\n') {
                    tResult.append('\n');
                    tInComment = false;
                }
            } else if (aToParse.startsWith("\n--", i)) {
                // Sonderfall: bei "\n--" entfernen wir auch "\n".
                tInComment = true;
            } else if(aToParse.startsWith("--", i)) {
                tInComment = true;
            } else if(c == '\'') {
                tInSingleQuote = true;
                tResult.append(c);
            } else if(c == '\"') {
                tInDoubleQuote = true;
                tResult.append(c);
            } else {
                tResult.append(c);
            }
        }

        if(tInSingleQuote) throw new ParseException();
        if(tInDoubleQuote) throw new ParseException();

        return tResult.toString();
    }
View Full Code Here


    StreamSource oStreamSrcXML;
    StringWriter oStrWritter;
    File oXMLFile,oXSLFile;
    InputStream oXMLStream = null;
    String sTransformed;
    StringBuffer oPostTransform;
    String sKey;
    String sMedia;
    String sXSLFile;
    Object sVal;
    Page oCurrentPage;

    int iCloseHead, iOpenBody, iCloseBody;
    int iReaded;
    char CharBuffer[] = new char[8192];
    String sCharBuffer;
    long lElapsed = 0;

    final String sSep = System.getProperty("file.separator");

    if (DebugFile.trace) {
      lElapsed = System.currentTimeMillis();

      DebugFile.writeln("Begin Pageset.buildPageForEdit(" + sBasePath + "," + sOutputPath + "," + sCtrlPath + "," + sMenuPath + ")");
      DebugFile.incIdent();
    }

    FileSystem oFS = new FileSystem();

    if (!sBasePath.endsWith(sSep)) sBasePath += sSep;

    String sWebServer = oEnvironmentProps.getProperty("webserver", "");

    if (DebugFile.trace && sWebServer.length()==0) DebugFile.writeln("WARNING: webserver property not set at EnvironmentProperties");

    if (!sWebServer.endsWith("/")) sWebServer+="/";


    // Posicionarse en el nodo de contenedores
    Node oContainers = oMSite.seekChildByName(oMSite.getRootNode().getFirstChild(), "containers");

    if (oContainers==null) {
      if (DebugFile.trace)
        DebugFile.writeln("ERROR: <containers> node not found.");

      throw new DOMException(DOMException.NOT_FOUND_ERR, "<containers> node not found");
    }

    // Cagar el stream de datos XML una sola vez
    if (DebugFile.trace)
      DebugFile.writeln("new FileInputStream(" + (sURI.startsWith("file://") ? sURI.substring(7) : sURI) + ")");

    // Para cada contenedor (página) realizar la transformación XSLT

      oCurrentPage = this.page(sPageGUID);

    oXMLFile = new File (sURI.startsWith("file://") ? sURI.substring(7) : sURI);
    if (!oXMLFile.exists()) {
        if (DebugFile.trace) DebugFile.decIdent();
      throw new FileNotFoundException("PageSet.buildPageForEdit() File not found "+sURI);
    }

      oXMLStream = new FileInputStream(oXMLFile);
      oStreamSrcXML = new StreamSource(oXMLStream);

      // Asignar cada stream de salida a su stream temporal
      oStrWritter = new StringWriter();
      oStreamResult = new StreamResult(oStrWritter);

      // Transformacion XSLT
      try {

        // Obtener la hoja de estilo desde el cache
        sXSLFile = sBasePath + "xslt" + sSep + "templates" + sSep + oMSite.name() + sSep + oCurrentPage.template();
      oXSLFile = new File (sXSLFile);
      if (!oXSLFile.exists()) {
          if (DebugFile.trace) DebugFile.decIdent();
        throw new FileNotFoundException("PageSet.buildPageForEdit() File not found "+sXSLFile+" maybe there is a mismatch between the microsite name and the directory name where it is placed, or between the template name and the actual .xsl file name");
      }

        oTransformer = StylesheetCache.newTransformer(sXSLFile);

        sMedia = oTransformer.getOutputProperty(OutputKeys.MEDIA_TYPE);

        if (DebugFile.trace) DebugFile.writeln(OutputKeys.MEDIA_TYPE + "=" + sMedia);

        if (null==sMedia)
          sMedia = "html";
        else
          sMedia = sMedia.substring(sMedia.indexOf('/')+1);

        if (null==oCurrentPage.getTitle())
          throw new NullPointerException("Page title is null");

        if (DebugFile.trace)
          DebugFile.writeln("Page.filePath(" + sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia + ")");

        oCurrentPage.filePath(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia);

        // Set environment parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oEnvironmentProps);

        // Set user defined parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oUserProps);

        // Paso el title de la pagina como parametro
        oTransformer.setParameter ("param_page", oCurrentPage.getTitle());

        // Realizar la transformación
        oTransformer.transform (oStreamSrcXML, oStreamResult);

      }
      catch (TransformerConfigurationException e) {
         oLastXcpt = e;
         sMedia = null;

         SourceLocator sl = e.getLocator();

         if (DebugFile.trace) {
           if (sl == null) {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage());
           }
           else {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage() + " line=" + String.valueOf(sl.getLineNumber()) + " column=" + String.valueOf(sl.getColumnNumber()));
           }
         }
      }
      catch (TransformerException e) {
        oLastXcpt = e;
        sMedia = null;

        if (DebugFile.trace) DebugFile.writeln("ERROR TransformerException " + e.getMessageAndLocation());
      }

      oTransformer = null;
      oStreamResult = null;

      // Asignar un String con el fuente XML transformado
      sTransformed = oStrWritter.toString();

      if (DebugFile.trace) DebugFile.writeln("transformation length=" + String.valueOf(sTransformed.length()));

      // Buscar el fin de tag </head>
      if (sTransformed.length()>0) {
        iCloseHead = sTransformed.indexOf("</head");
        if (iCloseHead<0) iCloseHead = sTransformed.indexOf("</HEAD");

    if (iCloseHead<0) {
          if (DebugFile.trace) {
            DebugFile.writeln("Stylesheet lacks </head> tag");
            DebugFile.decIdent();
          }     
      throw new TransformerException("Stylesheet lacks </head> tag");
    } // fi

        // Buscar el inicio de tag <body>
        iOpenBody = sTransformed.indexOf("<body", iCloseHead);
        if (iOpenBody<0) iOpenBody = sTransformed.indexOf("<BODY", iCloseHead);

    if (iOpenBody<0) {
          if (DebugFile.trace) {
            DebugFile.writeln("Stylesheet lacks <body> tag");
            DebugFile.decIdent();
          }     
      throw new TransformerException("Stylesheet lacks <body> tag");
    } // fi
   
        iCloseBody = sTransformed.indexOf(">", iOpenBody+5);
        for (char s = sTransformed.charAt(iCloseBody+1); s=='\r' || s=='\n' || s==' ' || s=='\t'; s = sTransformed.charAt(++iCloseBody)) ;

        // Crear un buffer intermedio para mayor velocidad de concatenado
        oPostTransform = new StringBuffer(sTransformed.length()+4096);

        // Incrustar las llamadas al Integrador en el lugar apropiado del fuente
        oPostTransform.append(sTransformed.substring(0, iCloseHead));
        oPostTransform.append("\n<script language=\"JavaScript\" type=\"text/javascript\" src=\"" + sMenuPath + "\"></script>");
        oPostTransform.append("\n<script language=\"JavaScript\" type=\"text/javascript\" src=\"" + sIntegradorPath + "\"></script>\n");
        oPostTransform.append(sTransformed.substring(iCloseHead, iCloseHead+7));
        oPostTransform.append(sTransformed.substring(iOpenBody, iCloseBody));

        // Cargar el código fuente del control de visulización del Integrador
        try {
          sCharBuffer = oFS.readfilestr(sCtrlPath, "UTF-8");

          if (DebugFile.trace) DebugFile.writeln(String.valueOf(sCharBuffer.length()) + " characters readed");
        }
        catch (com.enterprisedt.net.ftp.FTPException ftpe) {
          throw new IOException (ftpe.getMessage());
        }

        try {
          if (DebugFile.trace) DebugFile.writeln("Gadgets.replace(" + sCtrlPath + ",http://demo.hipergate.com/," + sWebServer + ")");

          Gadgets.replace(sCharBuffer, "http://demo.hipergate.com/", sWebServer);

        } catch (org.apache.oro.text.regex.MalformedPatternException e) { }

        oPostTransform.append("<!--Begin " + sCtrlPath + "-->\n");

        oPostTransform.append(sCharBuffer);
        sCharBuffer = null;

        oPostTransform.append("\n<!--End " + sCtrlPath + "-->\n");

        oPostTransform.append(sTransformed.substring(iCloseBody));
      }
      else {
        oPostTransform = new StringBuffer("Page " + oCurrentPage.getTitle() + " could not be rendered.");
        if (oLastXcpt!=null) oPostTransform.append("<BR>" + oLastXcpt.getMessageAndLocation());
      }

      // Escribir el resultado con las llamadas incrustadas en el archivo de salida

      if (sSelPageOptions.length()==0)
        oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, oPostTransform.toString(), "UTF-8");
      else
        try {

          oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, Gadgets.replace(oPostTransform.toString(), ":selPageOptions", sSelPageOptions), "UTF-8");

        } catch (Exception e) {/* Ignore MalformedPatternException, is never thrown */ }

      // Desreferenciar los buffers intermedios para liberar memoria lo antes posible
      oPostTransform = null;
View Full Code Here

    StreamResult oStreamResult;
    StreamSource oStreamSrcXML;
    StringWriter oStrWritter;
    InputStream oXMLStream = null;
    String sTransformed;
    StringBuffer oPostTransform;
    String sKey;
    String sMedia;
    Object sVal;
    Page oCurrentPage;

    int iCloseHead, iOpenBody, iCloseBody;
    int iReaded;
    char CharBuffer[] = new char[8192];
    String sCharBuffer;
    long lElapsed = 0;

    final String sSep = System.getProperty("file.separator");

    if (DebugFile.trace) {
      lElapsed = System.currentTimeMillis();

      DebugFile.writeln("Begin Pageset.buildSiteForEdit(" + sBasePath + "," + sOutputPath + "," + sCtrlPath + "," + sMenuPath + ")");
      DebugFile.incIdent();
    }

    FileSystem oFS = new FileSystem();

    Vector vPages = pages();

    if (!sBasePath.endsWith(sSep)) sBasePath += sSep;

    String sWebServer = oEnvironmentProps.getProperty("webserver", "");

    if (DebugFile.trace && sWebServer.length()==0) DebugFile.writeln("WARNING: webserver property not set at EnvironmentProperties");

    if (!sWebServer.endsWith("/")) sWebServer+="/";


    // Posicionarse en el nodo de contenedores
    Node oContainers = oMSite.seekChildByName(oMSite.getRootNode().getFirstChild(), "containers");

    if (oContainers==null) {
      if (DebugFile.trace)
        DebugFile.writeln("ERROR: <containers> node not found.");

      throw new DOMException(DOMException.NOT_FOUND_ERR, "<containers> node not found");
    }

    // Cagar el stream de datos XML una sola vez
    if (DebugFile.trace)
      DebugFile.writeln("new FileInputStream(" + (sURI.startsWith("file://") ? sURI.substring(7) : sURI) + ")");


    // Para cada contenedor (página) realizar la transformación XSLT
    for (int c=0; c<vPages.size(); c++) {

      oCurrentPage = (Page) vPages.get(c);

      oXMLStream = new FileInputStream(sURI.startsWith("file://") ? sURI.substring(7) : sURI);
      oStreamSrcXML = new StreamSource(oXMLStream);

      // Asignar cada stream de salida a su stream temporal
      oStrWritter = new StringWriter();
      oStreamResult = new StreamResult(oStrWritter);

      // Transformacion XSLT
      try {

        // Obtener la hoja de estilo desde el cache
        oTransformer = StylesheetCache.newTransformer(sBasePath + "xslt" + sSep + "templates" + sSep + oMSite.name() + sSep + oCurrentPage.template());

        sMedia = oTransformer.getOutputProperty(OutputKeys.MEDIA_TYPE);

        if (DebugFile.trace) DebugFile.writeln(OutputKeys.MEDIA_TYPE + "=" + sMedia);

        if (null==sMedia)
          sMedia = "html";
        else
          sMedia = sMedia.substring(sMedia.indexOf('/')+1);

        if (null==oCurrentPage.getTitle())
          throw new NullPointerException("Page " + String.valueOf(c) + " title is null");

        if (DebugFile.trace)
          DebugFile.writeln("Page.filePath(" + sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia + ")");

        oCurrentPage.filePath(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia);

        // Set environment parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oEnvironmentProps);

        // Set user defined parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oUserProps);

        // Paso el title de la pagina como parametro
        oTransformer.setParameter ("param_page", ((Page)(vPages.get(c))).getTitle());

        // Realizar la transformación
        oTransformer.transform (oStreamSrcXML, oStreamResult);

      }
      catch (TransformerConfigurationException e) {
         oLastXcpt = e;
         sMedia = null;

         SourceLocator sl = e.getLocator();

         if (DebugFile.trace) {
           if (sl == null) {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage());
           }
           else {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage() + " line=" + String.valueOf(sl.getLineNumber()) + " column=" + String.valueOf(sl.getColumnNumber()));
           }
         }
      }
      catch (TransformerException e) {
        oLastXcpt = e;
        sMedia = null;

        if (DebugFile.trace) DebugFile.writeln("ERROR TransformerException " + e.getMessageAndLocation());
      }

      oTransformer = null;
      oStreamResult = null;

      // Asignar un String con el fuente XML transformado
      sTransformed = oStrWritter.toString();

      if (DebugFile.trace) DebugFile.writeln("transformation length=" + String.valueOf(sTransformed.length()));

      // Buscar el fin de tag </head>
      if (sTransformed.length()>0) {
        iCloseHead = sTransformed.indexOf("</head");
        if (iCloseHead<0) iCloseHead = sTransformed.indexOf("</HEAD");

        // Buscar el inicio de tag <body>
        iOpenBody = sTransformed.indexOf("<body", iCloseHead);
        if (iOpenBody<0) iOpenBody = sTransformed.indexOf("<BODY", iCloseHead);

        iCloseBody = sTransformed.indexOf(">", iOpenBody+5);
        for (char s = sTransformed.charAt(iCloseBody+1); s=='\r' || s=='\n' || s==' ' || s=='\t'; s = sTransformed.charAt(++iCloseBody)) ;

        // Crear un buffer intermedio para mayor velocidad de concatenado
        oPostTransform = new StringBuffer(sTransformed.length()+4096);

        // Incrustar las llamadas al Integrador en el lugar apropiado del fuente
        oPostTransform.append(sTransformed.substring(0, iCloseHead));
        oPostTransform.append("\n<script language=\"JavaScript\" src=\"" + sMenuPath + "\"></script>");
        oPostTransform.append("\n<script language=\"JavaScript\" src=\"" + sIntegradorPath + "\"></script>\n");
        oPostTransform.append(sTransformed.substring(iCloseHead, iCloseHead+7));
        oPostTransform.append(sTransformed.substring(iOpenBody, iCloseBody));

        // Cargar el código fuente del control de visulización del Integrador
        try {
          sCharBuffer = oFS.readfilestr(sCtrlPath, "UTF-8");

          if (DebugFile.trace) DebugFile.writeln(String.valueOf(sCharBuffer.length()) + " characters readed");
        }
        catch (com.enterprisedt.net.ftp.FTPException ftpe) {
          throw new IOException (ftpe.getMessage());
        }

        try {
          if (DebugFile.trace) DebugFile.writeln("Gadgets.replace(" + sCtrlPath + ",http://demo.hipergate.com/," + sWebServer + ")");

          Gadgets.replace(sCharBuffer, "http://demo.hipergate.com/", sWebServer);
        } catch (org.apache.oro.text.regex.MalformedPatternException e) { }

        oPostTransform.append("<!--Begin " + sCtrlPath + "-->\n");

        oPostTransform.append(sCharBuffer);
        sCharBuffer = null;

        oPostTransform.append("\n<!--End " + sCtrlPath + "-->\n");

        oPostTransform.append(sTransformed.substring(iCloseBody));
      }
      else {
        oPostTransform = new StringBuffer("Page " + ((Page)vPages.get(c)).getTitle() + " could not be rendered.");
        if (oLastXcpt!=null) oPostTransform.append("<BR>" + oLastXcpt.getMessageAndLocation());
      }

      // Escribir el resultado con las llamadas incrustadas en el archivo de salida
      if (DebugFile.trace) DebugFile.writeln("new FileWriter(" + sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia + ")");


      if (sSelPageOptions.length()==0)
        oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, oPostTransform.toString(), "UTF-8");
      else
        try {
          oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, Gadgets.replace(oPostTransform.toString(), ":selPageOptions", sSelPageOptions), "UTF-8");

        } catch (Exception e) {/* Ignore MalformedPatternException, is never thrown */ }

      // Desreferenciar los buffers intermedios para liberar memoria lo antes posible
      oPostTransform = null;
View Full Code Here

    oStmt.close();

    oStmt = oConn.createStatement();
    oRSet = oStmt.executeQuery("SELECT * FROM " + DB.k_addresses + " WHERE 1=0");
    ResultSetMetaData oMDat = oRSet.getMetaData();
    StringBuffer oColumnList = new StringBuffer(512);
    int iColumnCount = oMDat.getColumnCount();

    for (int c=1; c<=iColumnCount; c++) {
      if (c>1) oColumnList.append(',');
      oColumnList.append("a." + oMDat.getColumnName(c).toLowerCase());
    } // next (c)

    oRSet.close();
    oStmt.close();

    DBSubset oAddrs = new DBSubset(DB.k_addresses + " a," + DB.k_x_company_addr + " x",
                                   oColumnList.toString(), "a." + DB.gu_address + "=x." + DB.gu_address + " AND x." + DB.gu_company + "=? ORDER BY a." + DB.ix_address, 10);

    oAddrs.load(oConn, new Object[]{sCompanyGUID});

    String sAddresses = "\n  <company>" + sCompanyGUID + "</company>\n  <catalog>" + sCategoryGUID + "</catalog>\n  <addresses>\n" + oAddrs.toXML("    ", "address") + "\n  </addresses>";

View Full Code Here

    Element oBaseObject = (Element) oXMLDoc.seekChildByName(oTopNode, "basefilter");
    String sFilter = oXMLDoc.getTextValue(oBaseObject);

    int iLength = sFilter.length();
    StringBuffer oFilter = new StringBuffer(iLength);
    int iClose;
    int iDot;
    String sItem;

    for (int c=0; c<iLength; c++) {
      if (sFilter.charAt(c)=='$' && c<iLength-1) {
        if (sFilter.charAt(c+1)=='{') {
          iDot = sFilter.indexOf('.', c);
          iClose = sFilter.indexOf('}', iDot);
          sItem = sFilter.substring(iDot+1, iClose);

          if (sFilter.substring(c+2,iDot).equals("cookie"))
            oFilter.append(Cookies.getCookie(oReq, sItem, ""));
          else if (sFilter.substring(c+2,iDot).equals("param"))
            oFilter.append(oReq.getParameter(sItem));

          c = iClose;
        }
      } // fi(sFilter[c]=='{')
      else
        oFilter.append(sFilter.charAt(c));
      } // next (c)

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End QueryByForm.getBaseFilter() : " + oFilter.toString());
    }

    return oFilter.toString();
  } // getBaseFilter()
View Full Code Here

  public static String HTMLEncode(String text) {
    if (text == null) return "";

    char c;
    int len = text.length();
    StringBuffer results = new StringBuffer(len);

    for (int i = 0; i < len; ++i) {
      c = text.charAt(i);
      switch (c) {
            case '&':
              results.append("&amp;");
              break;
            case '<':
              results.append("&lt;");
              break;
            case '>':
              results.append("&gt;");
              break;
            case 39:
              results.append("&#39;");
              break;
            case '"':
              results.append("&quot;");
              break;
            case '¡':
              results.append("&iexcl;");
              break;
            case '¤':
              results.append("&curren;");
              break;
            case '¥':
              results.append("&yen;");
              break;
            case '|':
              results.append("&brvbar;");
              break;
            case '§':
              results.append("&sect;");
              break;
            case '¨':
              results.append("&uml;");
              break;
            case '©':
              results.append("&copy;");
              break;
            case 'ª':
              results.append("&ordf;");
              break;
            case '«':
              results.append("&laquo;");
              break;
            case '»':
              results.append("&raquo;");
              break;
            case '€':
              results.append("&euro;");
              break;
            case '£':
              results.append("&pound;");
              break;
            case '­':
              results.append("&shy;");
              break;
            case '®':
              results.append("&reg;");
              break;
            case '¯':
              results.append("&macr;");
              break;
            case '°':
              results.append("&deg;");
              break;
            case '±':
              results.append("&plusmn;");
              break;
            case '¹':
              results.append("&sup1;");
              break;
            case '²':
              results.append("&sup2;");
              break;
            case '³':
              results.append("&sup3;");
              break;
            case '´':
              results.append("&acute;");
              break;
            case 'µ':
              results.append("&micro;");
              break;
            case '¶':
              results.append("&para;");
              break;
            case '·':
              results.append("&middot;");
              break;
            case '¸':
              results.append("&cedil;");
              break;
            case 'º':
              results.append("&ordm;");
              break;
            case '¿':
              results.append("&iquest;");
              break;
            case 'ñ':
              results.append("&ntilde;");
              break;
            case 'Ñ':
              results.append("&Ntilde;");
              break;
            case 'á':
              results.append("&aacute;");
              break;
            case 'é':
              results.append("&eacute;");
              break;
            case 'í':
              results.append("&iacute;");
              break;
            case 'ó':
              results.append("&oacute;");
              break;
            case 'ú':
              results.append("&uacute;");
              break;
            case 'ü':
              results.append("&uuml;");
              break;
            case 'Á':
              results.append("&Aacute;");
              break;
            case 'À':
              results.append("&Agrave;");
              break;
            case 'Ä':
              results.append("&Auml;");
              break;
            case 'Â':
              results.append("&Acirc;");
              break;
            case 'Å':
              results.append("&Aring;");
              break;
            case 'É':
              results.append("&Eacute;");
              break;
            case 'È':
              results.append("&Egrave;");
              break;
            case 'Ë':
              results.append("&Euml;");
              break;
            case 'Ê':
              results.append("&Ecirc;");
              break;
            case 'Í':
              results.append("&Iacute;");
              break;
            case 'Ì':
              results.append("&Igrave;");
              break;
            case 'Ï':
              results.append("&Iuml;");
              break;
            case 'Î':
              results.append("&Icirc;");
              break;
            case 'Ó':
              results.append("&Oacute;");
              break;
            case 'Ò':
              results.append("&Ograve;");
              break;
            case 'Ö':
              results.append("&Ouml;");
              break;
            case 'Ô':
              results.append("&Ocirc;");
              break;
            case 'Ú':
              results.append("&Uacute;");
              break;
            case 'Ù':
              results.append("&Ugrave;");
              break;
            case 'Ü':
              results.append("&Uuml;");
              break;
            case 'Û':
              results.append("&Ucirc;");
              break;
            case '½':
              results.append("&frac12;");
              break;
            case '¾':
              results.append("&frac34;");
              break;
            case '¼':
              results.append("&frac14;");
              break;
            case 'Ç':
              results.append("&Ccedil;");
              break;
            case 'ç':
              results.append("&ccedil;");
              break;
            case 'ð':
              results.append("&eth;");
              break;
            case '¢':
              results.append("&cent;");
              break;
            case 'Þ':
              results.append("&THORN;");
              break;
            case 'þ':
              results.append("&thorn;");
              break;
            case 'Ð':
              results.append("&ETH;");
              break;
            case '×':
              results.append("&times;");
              break;
            case '÷':
              results.append("&divide;");
              break;
            case 'Æ':
              results.append("&AElig;");
              break;

              /*
                           uml    => chr 168, #umlaut (dieresis)
                           laquo  => chr 171, #angle quotation mark, left
                           not    => chr 172, #not sign
                           shy    => chr 173, #soft hyphen
                           reg    => chr 174, #registered sign
                           macr   => chr 175, #macron
                           deg    => chr 176, #degree sign
                           sup2   => chr 178, #superscript two
                           sup3   => chr 179, #superscript three
                           acute  => chr 180, #acute accent
                           micro  => chr 181, #micro sign
                           para   => chr 182, #pilcrow (paragraph sign)
                           cedil  => chr 184, #cedilla
                           sup1   => chr 185, #superscript one
                           raquo  => chr 187, #angle quotation mark, right
                           iquest => chr 191, #inverted question mark
                           Auml   => chr 196, #capital A, dieresis or umlaut mark
                           Aring  => chr 197, #capital A, ring
                           Ccedil => chr 199, #capital C, cedilla
                           Egrave => chr 200, #capital E, grave accent
                           Eacute => chr 201, #capital E, acute accent
                           Ecirc  => chr 202, #capital E, circumflex accent
                           Euml   => chr 203, #capital E, dieresis or umlaut mark
                           Igrave => chr 204, #capital I, grave accent
                           Iacute => chr 205, #capital I, acute accent
                           Icirc  => chr 206, #capital I, circumflex accent
                           Iuml   => chr 207, #capital I, dieresis or umlaut mark
                           Ouml   => chr 214, #capital O, dieresis or umlaut mark
                           Oslash => chr 216, #capital O, slash
                           Ugrave => chr 217, #capital U, grave accent
                           Uacute => chr 218, #capital U, acute accent
                           Ucirc  => chr 219, #capital U, circumflex accent
                           Uuml   => chr 220, #capital U, dieresis or umlaut mark
                           Yacute => chr 221, #capital Y, acute accent
                           szlig  => chr 223, #small sharp s, German (sz ligature)
                           agrave => chr 224, #small a, grave accent
                           aacute => chr 225, #small a, acute accent
                           acirc  => chr 226, #small a, circumflex accent
                           atilde => chr 227, #small a, tilde
                           auml   => chr 228, #small a, dieresis or umlaut mark
                           aring  => chr 229, #small a, ring
                           aelig  => chr 230, #small ae diphthong (ligature)
                           ccedil => chr 231, #small c, cedilla
                           egrave => chr 232, #small e, grave accent
                           eacute => chr 233, #small e, acute accent
                           ecirc  => chr 234, #small e, circumflex accent
                           euml   => chr 235, #small e, dieresis or umlaut mark
                           igrave => chr 236, #small i, grave accent
                           iacute => chr 237, #small i, acute accent
                           icirc  => chr 238, #small i, circumflex accent
                           iuml   => chr 239, #small i, dieresis or umlaut mark
                           eth    => chr 240, #small eth, Icelandic
                           ntilde => chr 241, #small n, tilde
                           ograve => chr 242, #small o, grave accent
                           oacute => chr 243, #small o, acute accent
                           ocirc  => chr 244, #small o, circumflex accent
                           otilde => chr 245, #small o, tilde
                           ouml   => chr 246, #small o, dieresis or umlaut mark
                           divide => chr 247, #divide sign
                           oslash => chr 248, #small o, slash
                           ugrave => chr 249, #small u, grave accent
                           uacute => chr 250, #small u, acute accent
                           ucirc  => chr 251, #small u, circumflex accent
                           uuml   => chr 252, #small u, dieresis or umlaut mark
                           yacute => chr 253, #small y, acute accent
                           thorn  => chr 254, #small thorn, Icelandic
                           yuml   => chr 255, #small y, dieresis or umlaut mark

                             <!ENTITY Atilde CDATA "&#195;" -- latin capital letter A with tilde,
                                                               U+00C3 ISOlat1 -->
                             <!ENTITY Aring  CDATA "&#197;" -- latin capital letter A with ring above
                                                               = latin capital letter A ring,
                                                               U+00C5 ISOlat1 -->
                             <!ENTITY AElig  CDATA "&#198;" -- latin capital letter AE
                                                               = latin capital ligature AE,
                                                               U+00C6 ISOlat1 -->
                             <!ENTITY Egrave CDATA "&#200;" -- latin capital letter E with grave,
                                                               U+00C8 ISOlat1 -->
                             <!ENTITY Eacute CDATA "&#201;" -- latin capital letter E with acute,
                                                               U+00C9 ISOlat1 -->
                             <!ENTITY Ecirc  CDATA "&#202;" -- latin capital letter E with circumflex,
                                                               U+00CA ISOlat1 -->
                             <!ENTITY Euml   CDATA "&#203;" -- latin capital letter E with diaeresis,
                                                               U+00CB ISOlat1 -->
                             <!ENTITY Igrave CDATA "&#204;" -- latin capital letter I with grave,
                                                               U+00CC ISOlat1 -->
                             <!ENTITY Iacute CDATA "&#205;" -- latin capital letter I with acute,
                                                               U+00CD ISOlat1 -->
                             <!ENTITY Icirc  CDATA "&#206;" -- latin capital letter I with circumflex,
                                                               U+00CE ISOlat1 -->
                             <!ENTITY Iuml   CDATA "&#207;" -- latin capital letter I with diaeresis,
                                                               U+00CF ISOlat1 -->
                             <!ENTITY ETH    CDATA "&#208;" -- latin capital letter ETH, U+00D0 ISOlat1 -->
                             <!ENTITY Ograve CDATA "&#210;" -- latin capital letter O with grave,
                                                               U+00D2 ISOlat1 -->
                             <!ENTITY Oacute CDATA "&#211;" -- latin capital letter O with acute,
                                                               U+00D3 ISOlat1 -->
                             <!ENTITY Ocirc  CDATA "&#212;" -- latin capital letter O with circumflex,
                                                               U+00D4 ISOlat1 -->
                             <!ENTITY Otilde CDATA "&#213;" -- latin capital letter O with tilde,
                                                               U+00D5 ISOlat1 -->
                             <!ENTITY Ouml   CDATA "&#214;" -- latin capital letter O with diaeresis,
                                                               U+00D6 ISOlat1 -->
                             <!ENTITY times  CDATA "&#215;" -- multiplication sign, U+00D7 ISOnum -->
                             <!ENTITY Oslash CDATA "&#216;" -- latin capital letter O with stroke
                                                               = latin capital letter O slash,
                                                               U+00D8 ISOlat1 -->
                             <!ENTITY Ugrave CDATA "&#217;" -- latin capital letter U with grave,
                                                               U+00D9 ISOlat1 -->
                             <!ENTITY Uacute CDATA "&#218;" -- latin capital letter U with acute,
                                                               U+00DA ISOlat1 -->
                             <!ENTITY Ucirc  CDATA "&#219;" -- latin capital letter U with circumflex,
                                                               U+00DB ISOlat1 -->
                             <!ENTITY Uuml   CDATA "&#220;" -- latin capital letter U with diaeresis,
                                                               U+00DC ISOlat1 -->
                             <!ENTITY Yacute CDATA "&#221;" -- latin capital letter Y with acute,
                                                               U+00DD ISOlat1 -->
                             <!ENTITY THORN  CDATA "&#222;" -- latin capital letter THORN,
                                                               U+00DE ISOlat1 -->
                             <!ENTITY szlig  CDATA "&#223;" -- latin small letter sharp s = ess-zed,
                                                               U+00DF ISOlat1 -->
                             <!ENTITY agrave CDATA "&#224;" -- latin small letter a with grave
                                                               = latin small letter a grave,
                                                               U+00E0 ISOlat1 -->
                             <!ENTITY aacute CDATA "&#225;" -- latin small letter a with acute,
                                                               U+00E1 ISOlat1 -->
                             <!ENTITY acirc  CDATA "&#226;" -- latin small letter a with circumflex,
                                                               U+00E2 ISOlat1 -->
                             <!ENTITY atilde CDATA "&#227;" -- latin small letter a with tilde,
                                                               U+00E3 ISOlat1 -->
                             <!ENTITY auml   CDATA "&#228;" -- latin small letter a with diaeresis,
                                                               U+00E4 ISOlat1 -->
                             <!ENTITY aring  CDATA "&#229;" -- latin small letter a with ring above
                                                               = latin small letter a ring,
                                                               U+00E5 ISOlat1 -->
                             <!ENTITY aelig  CDATA "&#230;" -- latin small letter ae
                                                               = latin small ligature ae, U+00E6 ISOlat1 -->
                             <!ENTITY egrave CDATA "&#232;" -- latin small letter e with grave,
                                                               U+00E8 ISOlat1 -->
                             <!ENTITY ecirc  CDATA "&#234;" -- latin small letter e with circumflex,
                                                               U+00EA ISOlat1 -->
                             <!ENTITY euml   CDATA "&#235;" -- latin small letter e with diaeresis,
                                                               U+00EB ISOlat1 -->
                             <!ENTITY igrave CDATA "&#236;" -- latin small letter i with grave,
                                                               U+00EC ISOlat1 -->
                             <!ENTITY iacute CDATA "&#237;" -- latin small letter i with acute,
                                                               U+00ED ISOlat1 -->
                             <!ENTITY icirc  CDATA "&#238;" -- latin small letter i with circumflex,
                                                               U+00EE ISOlat1 -->
                             <!ENTITY iuml   CDATA "&#239;" -- latin small letter i with diaeresis,
                                                               U+00EF ISOlat1 -->
                             <!ENTITY ograve CDATA "&#242;" -- latin small letter o with grave,
                                                               U+00F2 ISOlat1 -->
                             <!ENTITY oacute CDATA "&#243;" -- latin small letter o with acute,
                                                               U+00F3 ISOlat1 -->
                             <!ENTITY ocirc  CDATA "&#244;" -- latin small letter o with circumflex,
                                                               U+00F4 ISOlat1 -->
                             <!ENTITY otilde CDATA "&#245;" -- latin small letter o with tilde,
                                                               U+00F5 ISOlat1 -->
                             <!ENTITY ouml   CDATA "&#246;" -- latin small letter o with diaeresis,
                                                               U+00F6 ISOlat1 -->
                             <!ENTITY divide CDATA "&#247;" -- division sign, U+00F7 ISOnum -->
                             <!ENTITY oslash CDATA "&#248;" -- latin small letter o with stroke,
                                                               = latin small letter o slash,
                                                               U+00F8 ISOlat1 -->
                             <!ENTITY ugrave CDATA "&#249;" -- latin small letter u with grave,
                                                               U+00F9 ISOlat1 -->
                             <!ENTITY uacute CDATA "&#250;" -- latin small letter u with acute,
                                                               U+00FA ISOlat1 -->
                             <!ENTITY ucirc  CDATA "&#251;" -- latin small letter u with circumflex,
                                                               U+00FB ISOlat1 -->
                             <!ENTITY uuml   CDATA "&#252;" -- latin small letter u with diaeresis,
                                                               U+00FC ISOlat1 -->
                             <!ENTITY yacute CDATA "&#253;" -- latin small letter y with acute,
                                                               U+00FD ISOlat1 -->
                             <!ENTITY thorn  CDATA "&#254;" -- latin small letter thorn,
                                                               U+00FE ISOlat1 -->
                             <!ENTITY yuml   CDATA "&#255;" -- latin small letter y with diaeresis,
                                                               U+00FF ISOlat1 -->

              */
            default:
              if (c<256)
                results.append(c);
              else
                results.append("&#"+String.valueOf(c)+";");
          } // end switch (c)
    } // end for (i)

    return results.toString();
  } // HTMLEncode
View Full Code Here

  public static String HTMLDencode(String text) {
    if (text == null) return "";

    char c,d;
    int len = text.length();
    StringBuffer results = new StringBuffer(len);

    final String[] aEnts = {"amp;", "lt;", "gt;", "quot;", "iexcl;", "curren;", "yen;", "brvbar;", "sect;",
                           "uml;", "copy;", "ordf;", "laquo;", "raquo;", "euro;", "pound;", "shy;", "reg;",
                           "macr;", "deg;", "plusmn;", "sup1;", "sup2;", "sup3;", "acute;", "micro;", "para;",
                           "middot;", "cedil;", "ordm;", "iquest;", "ntilde;", "Ntilde;", "aacute;", "eacute;", "iacute;",
                           "oacute;", "uacute;", "uuml;", "Aacute;", "Agrave;", "Auml;", "Acirc;", "Aring;", "Eacute;",
                           "Egrave;", "Euml;", "Ecirc;", "Iacute;", "Igrave;", "Iuml;", "Icirc;", "Oacute;", "Ograve;",
                           "Ouml;", "Ocirc;", "Uacute;", "Ugrave;", "Uuml;", "Ucirc;", "frac12;", "frac34;", "frac14;",
                           "Ccedil;", "ccedil;", "eth;", "cent;", "THORN;""thorn;", "ETH;", "times;", "divide;",
                           "AElig;"
                           };

    final String[] aChars= {"&", "<", ">", "\"", "¡", "¤", "¥", "|", "§",
                            "¨", "©", "ª", "«" , "»", "€", "£", "­", "®",
                            "¯", "°", "±", "¹" , "²", "³", "´", "µ", "¶",
                            "·", "¸", "º", "¿" , "ñ", "Ñ", "á", "é", "í",
                            "ó", "ú", "ü", "Á" , "À", "Ä", "Â", "Å", "É",
                            "È", "Ë", "Ê", "Í" , "Ì", "Ï", "Î", "Ó", "Ò",
                            "Ö", "Ô", "Ú", "Ù" , "Ü", "Û", "½", "¾", "¼",
                            "Ç", "ç", "ð", "¢" , "Þ", "þ", "Ð", "×", "÷",
                            "Æ"
                           };

    final int iEnts = aEnts.length;

    for (int i = 0; i < len; ++i) {
      c = text.charAt(i);
      if (c=='&' && i<len-3) {
        try {
          if (text.charAt(i+1)=='#') {
            int semicolon = text.indexOf(59, i+1);
            if (semicolon>0) {
              results.append( (char) Integer.parseInt(text.substring(i + 2, semicolon)));
              i = semicolon+1;
            }
            else {
              results.append(c);
            }
          }
          else {
            for (int e=0; e<iEnts; e++) {
              if (text.substring(i+1, i+aEnts[e].length()).equals(aEnts[e]))
                results.append(aChars[e]);
            }
          }
        } catch (StringIndexOutOfBoundsException siob) {
          return results.toString();
        }
      }
      else {
        results.append(c);
      }
    } // next (i)

    return results.toString();
  } // HTMLDencode
View Full Code Here

   */
  public static String URLEncode (String sStr) {
    if (sStr==null) return null;

    int iLen = sStr.length();
    StringBuffer sEscaped = new StringBuffer(iLen+100);
    char c;
    for (int p=0; p<iLen; p++) {
      c = sStr.charAt(p);
      switch (c) {
        case ' ':
          sEscaped.append("%20");
          break;
        case '/':
          sEscaped.append("%2F");
          break;
        case '"':
          sEscaped.append("%22");
          break;
        case '#':
          sEscaped.append("%23");
          break;
        case '%':
          sEscaped.append("%25");
          break;
        case '&':
          sEscaped.append("%26");
          break;
        case (char)39:
          sEscaped.append("%27");
          break;
        case '+':
          sEscaped.append("%2B");
          break;
        case ',':
          sEscaped.append("%2C");
          break;
        case '=':
          sEscaped.append("%3D");
          break;
        case '?':
          sEscaped.append("%3F");
          break;
        case 'á':
          sEscaped.append("%E1");
          break;
        case 'é':
          sEscaped.append("%E9");
          break;
        case 'í':
          sEscaped.append("%ED");
          break;
        case 'ó':
          sEscaped.append("%F3");
          break;
        case 'ú':
          sEscaped.append("%FA");
          break;
        case 'Á':
          sEscaped.append("%C1");
          break;
        case 'É':
          sEscaped.append("%C9");
          break;
        case 'Í':
          sEscaped.append("%CD");
          break;
        case 'Ó':
          sEscaped.append("%D3");
          break;
        case 'Ú':
          sEscaped.append("%DA");
          break;
        case 'à':
          sEscaped.append("%E0");
          break;
        case 'è':
          sEscaped.append("%E8");
          break;
        case 'ì':
          sEscaped.append("%EC");
          break;
        case 'ò':
          sEscaped.append("%F2");
          break;
        case 'ù':
          sEscaped.append("%F9");
          break;
        case 'À':
          sEscaped.append("%C0");
          break;
        case 'È':
          sEscaped.append("%C8");
          break;
        case 'Ì':
          sEscaped.append("%CC");
          break;
        case 'Ò':
          sEscaped.append("%D2");
          break;
        case 'Ù':
          sEscaped.append("%D9");
          break;
        case 'ñ':
          sEscaped.append("%F1");
          break;
        case 'Ñ':
          sEscaped.append("%D1");
          break;
        case 'ç':
          sEscaped.append("%E7");
          break;
        case 'Ç':
          sEscaped.append("%C7");
          break;
        case 'ô':
          sEscaped.append("%F4");
          break;
        case 'Ô':
          sEscaped.append("%D4");
          break;
        case 'ö':
          sEscaped.append("%F6");
          break;
        case 'Ö':
          sEscaped.append("%D6");
          break;
        case '`':
          sEscaped.append("%60");
          break;
        case '¨':
          sEscaped.append("%A8");
          break;
        default:
          sEscaped.append(c);
          break;
      }
    } // next

    return sEscaped.toString();
  } // URLEncode
View Full Code Here

    int iLen = sStrIn.length();

    if (iLen==0) return sStrIn;

    StringBuffer sStrBuff = new StringBuffer(iLen);
    String sStr = sStrIn.toUpperCase();

    for (int c=0; c<iLen; c++) {
      switch (sStr.charAt(c)) {
        case 'Á':
        case 'À':
        case 'Ä':
        case 'Â':
        case 'Å':
          sStrBuff.append('A');
          break;
        case 'É':
        case 'È':
        case 'Ë':
        case 'Ê':
          sStrBuff.append('E');
          break;
        case 'Í':
        case 'Ì':
        case 'Ï':
        case 'Î':
          sStrBuff.append('I');
          break;
        case 'Ó':
        case 'Ò':
        case 'Ö':
        case 'Ô':
        case 'Ø':
          sStrBuff.append('O');
          break;
        case 'Ú':
        case 'Ù':
        case 'Ü':
        case 'Û':
          sStrBuff.append('U');
          break;
        case 'Æ':
          sStrBuff.append('E');
          break;
        case 'Ñ':
          sStrBuff.append('N');
          break;
        case 'Ç':
          sStrBuff.append('C');
          break;
        case '°':
          sStrBuff.append('o');
          break;
        case 'ª':
          sStrBuff.append('a');
          break;
        case '\\':
        case '.':
        case '/':
          sStrBuff.append('_');
          break;
        case '&':
          sStrBuff.append('A');
          break;
        case ':':
          sStrBuff.append(';');
          break;
        case '<':
          sStrBuff.append('L');
          break;
        case '>':
          sStrBuff.append('G');
          break;
        case '"':
          sStrBuff.append((char)39);
          break;
        case '|':
          sStrBuff.append('P');
          break;
        case '¡':
          sStrBuff.append('E');
          break;
        case '¿':
        case '?':
          sStrBuff.append('Q');
          break;
        case '*':
          sStrBuff.append('W');
          break;
        case '%':
          sStrBuff.append('P');
          break;
        case 'ß':
          sStrBuff.append('B');
          break;
        case '¥':
          sStrBuff.append('Y');
          break;
        case (char)255:
          sStrBuff.append('_');
          break;
        default:
          sStrBuff.append(sStr.charAt(c));
      } // end switch
    } // next ()
    return sStrBuff.toString();
  } // ASCIIEncode
View Full Code Here

                                  "yýyÿy"};
    if (null==sText) return null;
    final int nSets = aSets.length;
    final int lText = sText.length();
    final String sLext = sText.toLowerCase();
    StringBuffer oText = new StringBuffer();
    for (int n=0; n<lText; n++) {
      char c = sLext.charAt(n);
      int iMatch = -1;
      for (int s=0; s<nSets && -1==iMatch; s++) {
        if (aSets[s].indexOf(c)>=0) iMatch=s;
      } // next(s)
     
      if (iMatch!=-1)
        oText.append("["+(sText.charAt(n)==c ? aSets[iMatch] : aSets[iMatch].toUpperCase())+"]");
      else
        oText.append(sText.charAt(n));
    } // next (n)
    return oText.toString();
  } // AccentsToPosixRegEx
View Full Code Here

TOP

Related Classes of java.lang.StringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.