Example usage for org.apache.commons.lang StringUtils remove

List of usage examples for org.apache.commons.lang StringUtils remove

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils remove.

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

From source file:jetbrick.tools.chm.reader.JavaInfoReader.java

private void addClassFieldMethod(ClassInfo classinfo) throws IOException {
    File file = new File(Config.apiLocation, classinfo.getUrl());
    String html = FileUtils.readFileToString(file, Config.encoding);

    Pattern p = Config.style.getJavaFieldRegex();
    Matcher m = p.matcher(html);/*from ww  w . j av  a 2s .co  m*/

    while (m.find()) {
        String name = m.group(2);
        String url = m.group(1);

        url = StringUtils.remove(url, "../");
        url = StringUtils.remove(url, "./");

        String anchor = StringUtils.substringAfter(url, "#");
        String linkUrl = StringUtils.substringBefore(url, "#") + "#"
                + AnchorNameManager.getNewAnchorName(anchor);

        if (Config.style.isMethod(url)) {
            MethodInfo info = new MethodInfo();
            info.setName(name);
            info.setFullName(Config.style.getMethodFullName(url));
            info.setUrl(linkUrl);
            classinfo.addMethod(info);
        } else {
            FieldInfo info = new FieldInfo();
            info.setName(name);
            info.setUrl(linkUrl);
            classinfo.addField(info);
        }
    }
}

From source file:easycare.load.util.db.loader.UserDataLoader.java

@Transactional
public void buildAllUsers(ContextOfCurrentLoad context) {

    log.info("starting to load users ");
    Session session = (Session) em.getDelegate();
    ScrollableResults scrollableResults = session
            .createQuery("from Organisation where name != 'ResMed' order by accountNumber").scroll();

    int numberOfOrganisationsWithAddedUsers = 0;
    while (scrollableResults.next()) {

        Organisation organisation = (Organisation) scrollableResults.get(0);
        String organisationNumber = StringUtils.remove(organisation.getAccountNumber(), "APT");

        loadOrgUsers(context, organisation, organisationNumber);

        if (++numberOfOrganisationsWithAddedUsers % SMALL_CHUNK == 0) {
            em.flush();/*  w ww  .j  a  v a  2s. c  o  m*/
            em.clear();
            log.debug("finished small chunk of orgs with users up to " + numberOfOrganisationsWithAddedUsers
                    + "org");
        }
        log.info("Finished users for org " + organisation);
    }
    log.info("Finished to load users ");
}

From source file:de.alpharogroup.xsl.transform.XsltTransformerUtilsTest.java

@Test
public void testGetTransformerFile() throws TransformerConfigurationException,
        TransformerFactoryConfigurationError, TransformerException, IOException {
    final File resDestDir = PathFinder.getSrcTestResourcesDir();
    final String[] dirsAndFilename = { "de", "alpharogroup", "xsl", "transform", "birthdates.xml" };
    final File xmlFile = PathFinder.getRelativePathTo(resDestDir, Arrays.asList(dirsAndFilename));
    final File xsltFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "de.alpharogroup.xsl.transform",
            "functions.xsl");
    final File outputFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "de.alpharogroup.xsl.transform",
            "output.xml");
    XsltTransformerUtils.transform(xmlFile, xsltFile, new FileOutputStream(outputFile));
    String actual = ReadFileUtils.readFromFile(outputFile);
    actual = StringUtils.remove(actual, '\r');
    actual = StringUtils.remove(actual, '\n');
    expected = StringUtils.remove(expected, '\r');
    expected = StringUtils.remove(expected, '\n');
    AssertJUnit.assertTrue("", expected.equals(actual));
}

From source file:net.sourceforge.jaulp.xsl.transform.XsltTransformerUtilsTest.java

@Test(enabled = true)
public void testTransformSourceSourceOutputStream() throws TransformerException, IOException {
    final File resDestDir = PathFinder.getSrcTestResourcesDir();
    String[] dirsAndFilename = { "net", "sourceforge", "jaulp", "xsl", "transform", "birthdates.xml" };
    File xmlFile = PathFinder.getRelativePath(resDestDir, dirsAndFilename);
    File xsltFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "net.sourceforge.jaulp.xsl.transform",
            "functions.xsl");
    InputStream is = StreamUtils.getInputStream(xsltFile);
    Source xsltSource = new StreamSource(is);

    InputStream xmlIs = StreamUtils.getInputStream(xmlFile);
    File outputFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "net.sourceforge.jaulp.xsl.transform",
            "data_02_output.xml");
    OutputStream output = StreamUtils.getOutputStream(outputFile, true);
    Source xmlSource = new StreamSource(xmlIs);
    XsltTransformerUtils.transform(xmlSource, xsltSource, output);
    String actual = ReadFileUtils.readFromFile(outputFile);
    actual = StringUtils.remove(actual, '\r');
    actual = StringUtils.remove(actual, '\n');
    expected = StringUtils.remove(expected, '\r');
    expected = StringUtils.remove(expected, '\n');
    AssertJUnit.assertTrue("", expected.equals(actual));
}

From source file:de.alpharogroup.xsl.transform.XsltTransformerExtensionsTest.java

@Test
public void testGetTransformerFile() throws TransformerConfigurationException,
        TransformerFactoryConfigurationError, TransformerException, IOException {
    final File resDestDir = PathFinder.getSrcTestResourcesDir();
    final String[] dirsAndFilename = { "de", "alpharogroup", "xsl", "transform", "birthdates.xml" };
    final File xmlFile = PathFinder.getRelativePathTo(resDestDir, Arrays.asList(dirsAndFilename));
    final File xsltFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "de.alpharogroup.xsl.transform",
            "functions.xsl");
    final File outputFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "de.alpharogroup.xsl.transform",
            "output.xml");
    XsltTransformerExtensions.transform(xmlFile, xsltFile, new FileOutputStream(outputFile));
    String actual = ReadFileExtensions.readFromFile(outputFile);
    actual = StringUtils.remove(actual, '\r');
    actual = StringUtils.remove(actual, '\n');
    expected = StringUtils.remove(expected, '\r');
    expected = StringUtils.remove(expected, '\n');
    AssertJUnit.assertTrue("", expected.equals(actual));
}

From source file:com.hangum.tadpole.engine.query.sql.TadpoleSystem_SchemaHistory.java

/**
 * save schema_history /*from   ww  w  .  j  a  v  a2s .  c  o m*/
 * 
 * @param user_seq
 * @param userDB
 * @param strSQL
 */
public static SchemaHistoryDAO save(int user_seq, UserDBDAO userDB, String strSQL) {
    SchemaHistoryDAO schemaDao = new SchemaHistoryDAO();

    try {
        //
        //
        //
        String strWorkSQL = strSQL.replaceAll("(\r\n|\n|\r)", ""); // ? .
        strWorkSQL = strWorkSQL.replaceAll("\\p{Space}", " "); // ?  .
        if (logger.isDebugEnabled())
            logger.debug("[start sql]\t" + strWorkSQL);

        String[] arrSQL = StringUtils.split(strWorkSQL);
        if (arrSQL.length != 5)
            return null;
        String strWorkType = arrSQL[0];

        // object type
        String strObjecType = arrSQL[1];

        // objectId
        String strObjectId = StringUtils.remove(arrSQL[2], "(");

        if (StringUtils.equalsIgnoreCase("or", strObjecType)) {
            strObjecType = arrSQL[3];
            strObjectId = StringUtils.remove(arrSQL[4], "(");
        }

        schemaDao = new SchemaHistoryDAO();
        schemaDao.setDb_seq(userDB.getSeq());
        schemaDao.setUser_seq(user_seq);

        schemaDao.setWork_type(strWorkType);
        schemaDao.setObject_type(strObjecType);
        schemaDao.setObject_id(strObjectId);

        schemaDao.setCreate_date(new Timestamp(System.currentTimeMillis()));

        schemaDao.setIpaddress(RWT.getRequest().getRemoteAddr());

        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
        SchemaHistoryDAO schemaHistoryDao = (SchemaHistoryDAO) sqlClient.insert("sqlHistoryInsert", schemaDao); //$NON-NLS-1$

        insertResourceData(schemaHistoryDao, strSQL);
    } catch (Exception e) {
        logger.error("Schema histor save error", e);
    }

    return schemaDao;
}

From source file:edu.ku.brc.af.ui.ESTermParser.java

@Override
public boolean parse(final String searchTermArg, final boolean parseAsSingleTerm) {
    instance.fields.clear();//from   w w  w .  j a  v  a 2  s  .c o m

    //DateWrapper scrDateFormat = AppPrefsCache.getDateWrapper("ui", "formatting", "scrdateformat");
    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    String searchTerm = searchTermArg;
    DateParser dd = new DateParser(instance.scrDateFormat.getSimpleDateFormat().toPattern());

    //----------------------------------------------------------------------------------------------
    // NOTE: If a full date was type in and it was parsed as such
    // and it couldn't be something else, then it only searches date fields.
    //----------------------------------------------------------------------------------------------

    int cnt = 0;

    if (searchTerm.length() > 0) {
        if (StringUtils.contains(searchTerm, '\\')) {
            return false;
        }

        String[] terms;

        boolean startWith = searchTerm.startsWith("*");
        boolean endsWith = searchTerm.endsWith("*");

        searchTerm = StringUtils.remove(searchTerm, '*');

        if (searchTerm.startsWith("\"") || searchTerm.startsWith("'") || searchTerm.startsWith("`")) {
            searchTerm = StringUtils.stripStart(searchTerm, "\"'`");
            searchTerm = StringUtils.stripEnd(searchTerm, "\"'`");
            terms = new String[] { searchTerm };

        } else if (parseAsSingleTerm) {
            terms = new String[] { searchTerm };

        } else {
            terms = StringUtils.split(searchTerm, ' ');
        }

        if (terms.length == 1) {
            terms[0] = (startWith ? "*" : "") + terms[0] + (endsWith ? "*" : "");
        } else {

            terms[0] = (startWith ? "*" : "") + terms[0];
            terms[terms.length - 1] = terms[terms.length - 1] + (endsWith ? "*" : "");
        }

        for (String term : terms) {
            if (StringUtils.isEmpty(term)) {
                continue;
            }

            SearchTermField stf = new SearchTermField(term);

            if (stf.isSingleChar()) {
                return false;
            }
            instance.fields.add(stf);

            cnt += !stf.isSingleChar() ? 1 : 0;

            //log.debug(term);
            String termStr = term;

            if (termStr.startsWith("*")) {
                stf.setOption(SearchTermField.STARTS_WILDCARD);
                termStr = termStr.substring(1);
                stf.setTerm(termStr);
            }

            if (termStr.endsWith("*")) {
                stf.setOption(SearchTermField.ENDS_WILDCARD);
                termStr = termStr.substring(0, termStr.length() - 1);
                stf.setTerm(termStr);
            }

            // First check to see if it is all numeric.
            if (StringUtils.isNumeric(termStr)) {
                stf.setOption(SearchTermField.IS_NUMERIC);
                if (StringUtils.contains(termStr, '.')) {
                    stf.setOption(SearchTermField.HAS_DEC_POINT);
                }

                if (!stf.isOn(SearchTermField.HAS_DEC_POINT) && termStr.length() == 4) {
                    int year = Integer.parseInt(termStr);
                    if (year > 1000 && year <= currentYear) {
                        stf.setOption(SearchTermField.IS_YEAR_OF_DATE);
                    }
                }
            } else {
                // Check to see if it is date
                Date searchDate = dd.parseDate(searchTermArg);
                if (searchDate != null) {
                    try {
                        termStr = dbDateFormat.format(searchDate);
                        stf.setTerm(termStr);
                        stf.setOption(SearchTermField.IS_DATE);

                    } catch (Exception ex) {
                        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ESTermParser.class, ex);
                        // should never get here
                    }
                }
            }
        }
    }

    return instance.fields.size() > 0 && cnt > 0;
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityGeoBoundsChecker2.java

/**
 * /*from  ww  w. j  ava 2 s. co m*/
 */
public void load() {
    File file = new File(XMLHelper.getConfigDirPath("st99_d00a.dat"));
    try {
        List<String> lines = (List<String>) FileUtils.readLines(file);
        for (int i = 0; i < lines.size(); i++) {
            String polygonId = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"');
            String stateId = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"');
            String stateNm = StringUtils.remove(StringUtils.deleteWhitespace(lines.get(i++)), '"');
            i += 2;

            StateInfo si = statesHash.get(stateNm);
            if (si == null) {
                String code = statesCodeHash.get(stateNm);
                si = new StateInfo(stateNm, code, stateId);
                statesHash.put(stateNm, si);
                codeToStateInfoHash.put(code, si);
            }
            statesIdHash.put(polygonId, si);
        }

        for (String polygonId : statesIdHash.keySet()) {
            System.out.println(String.format("%s - %s", polygonId, statesIdHash.get(polygonId).name));
        }

        file = new File(XMLHelper.getConfigDirPath("st99_d00.dat"));
        FileInputStream fis = new FileInputStream(file);
        BufferedReader bufRdr = new BufferedReader(new InputStreamReader(fis));

        StateInfo si = null;
        ArrayList<Position> points = null;

        String s;
        while ((s = bufRdr.readLine()) != null) {
            String[] tokens = StringUtils.split(s, ' ');
            if (tokens.length == 3) {
                //System.out.println(tokens[0]);
                /*if (points != null)
                {
                Polyline polygon = new Polyline(); 
                polygon.setPositions(points);
                si.addPolygon(polygon);
                }*/

                si = statesIdHash.get(tokens[0]);
                points = new ArrayList<Position>();

                //double lat = Double.valueOf(tokens[1]);
                //double lon = Double.valueOf(tokens[2]);
                //points.add(Position.fromDegrees(lat, lon, 0));

            } else if (tokens.length == 2) {
                double lat = Double.valueOf(tokens[1]);
                double lon = Double.valueOf(tokens[0]);
                points.add(Position.fromDegrees(lat, lon, 0));

            } else if (si != null) {
                Polyline polygon = new Polyline();
                polygon.setPositions(points);
                si.addPolygon(polygon);
                si = null;
            }
        }
        bufRdr.close();
        fis.close();

        for (StateInfo stateInfo : statesHash.values()) {
            System.out.println(String.format("%s - %d", stateInfo.name, stateInfo.polygons.size()));
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:gov.nih.nci.cacis.sa.transcend.client.TranscendSemanticAdapter.java

/**
 * AcceptSource operation accepts data from Clinical Source system and sends it to Mirth Connect for processing
 * //from  ww w.  j a  va 2s.  co m
 * @param parameter caCISRequest
 * @return CaCISResponse
 * @throws AcceptSourceFault Web Service Fault
 */
@WebResult(name = "caCISResponse", targetNamespace = "http://cacis.nci.nih.gov", partName = "parameter")
@WebMethod
public CaCISResponse acceptSource(
        @WebParam(partName = "parameter", name = "caCISRequest", targetNamespace = "http://cacis.nci.nih.gov") CaCISRequest parameter)
        throws AcceptSourceFault {

    LOG.debug("Executing operation acceptSource");

    final gov.nih.nci.cacis.sa.transcend.CaCISResponse response = new CaCISResponse();

    final String reqstr = getCaCISRequestxml(parameter);

    if (StringUtils.isEmpty(reqstr)) {
        throw new AcceptSourceFault("Error marshalling CaCISRequest!");
    }

    String mcResponse = webServiceMessageReceiver.processData(reqstr);

    if (LOG.isDebugEnabled()) {
        LOG.debug("TranscendSemanticAdapter..MC RESPONSE:" + mcResponse);
    }

    if (mcResponse != null && (mcResponse.indexOf("Error") > -1 || mcResponse.indexOf("Exception") > -1
            || mcResponse.indexOf("ERROR") > -1 || mcResponse.indexOf("error") > -1)) {
        mcResponse = StringUtils.remove(mcResponse, "SUCCESS:");
        mcResponse = StringUtils.remove(mcResponse, "FAILURE:");
        AcceptSourceFault fault;
        try {
            fault = new AcceptSourceFault("Error processing Data from Source System",
                    getCaCISFaultFromXml(mcResponse));
            throw fault;
        } catch (JAXBException ex) {
            final CaCISFault cf = new CaCISFault();
            final CaCISError ce = new CaCISError();
            final IntegrationError ie = IntegrationError._1000;
            ce.setErrorCode(String.valueOf(ie.getErrorCode()));
            ce.setErrorMessage(ie.getMessage((Object) null));
            ce.setErrorType(ErrorType.TRANSMISSION);
            ce.setDetail(stackTraceAsString(ex));
            cf.getCaCISError().add(ce);
            fault = new AcceptSourceFault("Error accepting Data from Source System!" + ex.getMessage(), cf);
            throw fault;
        }

    }
    response.setStatus(ResponseStatusType.SUCCESS);

    return response;

}

From source file:com.google.gdt.eclipse.designer.gxt.databinding.model.beans.BeanObserveInfo.java

public BeanPropertyObserveInfo resolvePropertyReference(String reference, Object errorSupport)
        throws Exception {
    for (BeanPropertyObserveInfo property : m_properties) {
        if (reference.equals(property.getReference())) {
            return property;
        }// ww  w . j  a v  a  2 s  .c  om
    }
    //
    if (errorSupport != null) {
        Boolean[] error = (Boolean[]) errorSupport;
        error[0] = true;
    }
    //
    String propertyName = StringUtils.remove(reference, '"');
    IReferenceProvider referenceProvider = new StringReferenceProvider(reference);
    IObservePresentation presentation = new SimpleObservePresentation(propertyName, propertyName,
            TypeImageProvider.OBJECT_IMAGE);
    IObserveDecorator decorator = IObserveDecorator.DEFAULT;
    //
    return new BeanPropertyObserveInfo(Object.class, null, referenceProvider, presentation, decorator);
}