Example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR

List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Prototype

String LINE_SEPARATOR

To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Click Source Link

Document

The line.separator System Property.

Usage

From source file:org.jasig.resource.aggr.ResourcesAggregatorImpl.java

/**
 * Aggregate the specified Deque of elements into a single element. The provided MessageDigest is used for
 * building the file name based on the hash of the file contents. The callback is used for type specific
 * operations./*from  ww w  .  j  av a 2s  . c o  m*/
 */
protected <T extends BasicInclude> T aggregateList(final MessageDigest digest, final Deque<T> elements,
        final List<File> skinDirectories, final File outputRoot, final File alternateOutput,
        final String extension, final AggregatorCallback<T> callback) throws IOException {

    if (null == elements || elements.size() == 0) {
        return null;
    }

    // reference to the head of the list
    final T headElement = elements.getFirst();
    if (elements.size() == 1 && this.resourcesDao.isAbsolute(headElement)) {
        return headElement;
    }

    final File tempFile = File.createTempFile("working.", extension);
    final File aggregateOutputFile;
    try {
        //Make sure we're working with a clean MessageDigest
        digest.reset();
        TrimmingWriter trimmingWriter = null;
        try {
            final BufferedOutputStream bufferedFileStream = new BufferedOutputStream(
                    new FileOutputStream(tempFile));
            final MessageDigestOutputStream digestStream = new MessageDigestOutputStream(bufferedFileStream,
                    digest);
            final OutputStreamWriter aggregateWriter = new OutputStreamWriter(digestStream, this.encoding);
            trimmingWriter = new TrimmingWriter(aggregateWriter);

            for (final T element : elements) {
                final File resourceFile = this.findFile(skinDirectories, element.getValue());

                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(resourceFile);
                    final BOMInputStream bomIs = new BOMInputStream(new BufferedInputStream(fis));
                    if (bomIs.hasBOM()) {
                        logger.debug("Stripping UTF-8 BOM from: " + resourceFile);
                    }
                    final Reader resourceIn = new InputStreamReader(bomIs, this.encoding);
                    if (element.isCompressed()) {
                        IOUtils.copy(resourceIn, trimmingWriter);
                    } else {
                        callback.compress(resourceIn, trimmingWriter);
                    }
                } catch (IOException e) {
                    throw new IOException(
                            "Failed to read '" + resourceFile + "' for skin: " + skinDirectories.get(0), e);
                } finally {
                    IOUtils.closeQuietly(fis);
                }
                trimmingWriter.write(SystemUtils.LINE_SEPARATOR);
            }
        } finally {
            IOUtils.closeQuietly(trimmingWriter);
        }

        if (trimmingWriter.getCharCount() == 0) {
            return null;
        }

        // temp file is created, get checksum
        final String checksum = Base64.encodeBase64URLSafeString(digest.digest());
        digest.reset();

        // create a new file name
        final String newFileName = checksum + extension;

        // Build the new file name and path
        if (alternateOutput == null) {
            final String elementRelativePath = FilenameUtils.getFullPath(headElement.getValue());
            final File directoryInOutputRoot = new File(outputRoot, elementRelativePath);
            // create the same directory structure in the output root
            directoryInOutputRoot.mkdirs();

            aggregateOutputFile = new File(directoryInOutputRoot, newFileName).getCanonicalFile();
        } else {
            aggregateOutputFile = new File(alternateOutput, newFileName).getCanonicalFile();
        }

        //Move the aggregate file into the correct location
        FileUtils.deleteQuietly(aggregateOutputFile);
        FileUtils.moveFile(tempFile, aggregateOutputFile);
    } finally {
        //Make sure the temp file gets deleted
        FileUtils.deleteQuietly(tempFile);
    }

    final String newResultValue = RelativePath.getRelativePath(outputRoot, aggregateOutputFile);

    this.logAggregation(elements, newResultValue);

    return callback.getAggregateElement(newResultValue, elements);
}

From source file:org.jboss.windup.config.spring.namespace.java.JavaHintBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(JavaPatternHintProcessor.class);
    beanBuilder.addPropertyValue("regexPattern", element.getAttribute("regex"));

    if (element.hasAttribute("hint")) {
        beanBuilder.addPropertyValue("hint", element.getAttribute("hint"));
    } else {/*from  ww  w.j  a v a2 s  . co m*/
        String markdown = element.getTextContent();

        String lines[] = markdown.split("\\r?\\n");
        StringBuilder markdownRebuilder = new StringBuilder();

        for (String line : lines) {
            line = StringUtils.trim(line);
            if (line != null) {
                markdownRebuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
            }
        }
        beanBuilder.addPropertyValue("hint", markdownRebuilder.toString());
    }

    if (element.hasAttribute("source-type")) {
        beanBuilder.addPropertyValue("sourceType", element.getAttribute("source-type"));
    }
    if (element.hasAttribute("effort")) {
        beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort")));
    }

    return beanBuilder.getBeanDefinition();
}

From source file:org.jboss.windup.config.spring.namespace.simple.RegexHintBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(RegexPatternHintProcessor.class);
    beanBuilder.addPropertyValue("regexPattern", element.getAttribute("regex"));

    if (element.hasAttribute("hint")) {
        beanBuilder.addPropertyValue("hint", element.getAttribute("hint"));
    } else {// w  w  w .  jav a  2 s .  c  om
        String markdown = element.getTextContent();

        String lines[] = markdown.split("\\r?\\n");
        StringBuilder markdownRebuilder = new StringBuilder();

        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];

            line = StringUtils.trim(line);
            if (line != null) {
                markdownRebuilder.append(line);
            }
            //test to see if it is last line...
            if (i < lines.length - 1) {
                markdownRebuilder.append(SystemUtils.LINE_SEPARATOR);
            }
        }
        beanBuilder.addPropertyValue("hint", markdownRebuilder.toString());
    }

    if (element.hasAttribute("effort")) {
        beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort")));
    }

    return beanBuilder.getBeanDefinition();
}

From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenDependencyUpdateTrigger.java

@Override
public void run() {
    long start = System.currentTimeMillis();
    ProjectBuildingRequest projectBuildingRequest = null;

    Node node = super.job.getLastBuiltOn();

    if (node == null) {
        // FIXME schedule the first buid ??
        //job.scheduleBuild( arg0, arg1 )
        LOGGER.info("no previous build found for " + job.getDisplayName() + " so skip maven update trigger");
        return;/*from  w  w  w.j  a v a2 s  .  co m*/
    }

    ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        PluginWrapper pluginWrapper = Hudson.getInstance().getPluginManager()
                .getPlugin("maven-dependency-update-trigger");

        boolean isMaster = node == Hudson.getInstance();

        AbstractProject<?, ?> abstractProject = (AbstractProject<?, ?>) super.job;

        FilePath workspace = node.getWorkspaceFor((TopLevelItem) super.job);

        FilePath moduleRoot = abstractProject.getScm().getModuleRoot(workspace);

        String rootPomPath = moduleRoot.getRemote() + "/" + getRootPomPath();

        File localRepoFile = getLocalRepo(workspace);
        String localRepoPath = localRepoFile == null ? "" : localRepoFile.toString();

        String projectWorkspace = moduleRoot.getRemote();

        Maven.MavenInstallation mavenInstallation = getMavenInstallation();

        mavenInstallation = mavenInstallation.forNode(node, null);

        String mavenHome = mavenInstallation.getHomeDir().getPath();

        String jdkHome = "";

        JDK jdk = getJDK();

        if (jdk != null) {

            jdk = jdk.forNode(node, null);

            jdkHome = jdk == null ? "" : jdk.getHome();

        }

        if (MavenDependencyUpdateTrigger.debug) {
            LOGGER.info("MavenUpdateChecker with jdkHome:" + jdkHome);
        }

        long lastBuildTime = getLastBuildStartTime(abstractProject);
        MavenUpdateChecker checker = new MavenUpdateChecker(rootPomPath, localRepoPath, this.checkPlugins,
                projectWorkspace, isMaster, mavenHome, jdkHome, lastBuildTime);
        if (isMaster) {
            checker.setClassLoaderParent((PluginFirstClassLoader) pluginWrapper.classLoader);
        }

        VirtualChannel virtualChannel = node.getChannel();
        FilePath alternateSettings = getAlternateSettings(virtualChannel);
        checker.setAlternateSettings(alternateSettings);

        FilePath globalSettings = getGlobalSettings(virtualChannel);
        checker.setGlobalSettings(globalSettings);

        checker.setUserProperties(getUserProperties());

        checker.setActiveProfiles(getActiveProfiles());

        LOGGER.info(
                "run MavenUpdateChecker for project " + job.getName() + " on node " + node.getDisplayName());

        MavenUpdateCheckerResult mavenUpdateCheckerResult = virtualChannel.call(checker);

        if (debug) {
            StringBuilder debugLines = new StringBuilder(
                    "MavenUpdateChecker for project " + job.getName() + " on node " + node.getDisplayName())
                            .append(SystemUtils.LINE_SEPARATOR);
            for (String line : mavenUpdateCheckerResult.getDebugLines()) {
                debugLines.append(line).append(SystemUtils.LINE_SEPARATOR);
            }
            LOGGER.info(debugLines.toString());
        }

        if (mavenUpdateCheckerResult.getFileUpdatedNames().size() > 0) {
            StringBuilder stringBuilder = new StringBuilder(
                    "MavenUpdateChecker for project " + job.getName() + " on node " + node.getDisplayName());
            stringBuilder.append(" , snapshotDownloaded so triggering a new build : ")
                    .append(SystemUtils.LINE_SEPARATOR);
            for (String fileName : mavenUpdateCheckerResult.getFileUpdatedNames()) {
                stringBuilder.append(" * " + fileName).append(SystemUtils.LINE_SEPARATOR);
            }
            job.scheduleBuild(0,
                    new MavenDependencyUpdateTriggerCause(mavenUpdateCheckerResult.getFileUpdatedNames()));
            LOGGER.info(stringBuilder.toString());
        }

        long end = System.currentTimeMillis();
        LOGGER.info("time to run MavenUpdateChecker for project " + job.getName() + " on node "
                + node.getDisplayName() + " : " + (end - start) + " ms");
    } catch (Exception e) {
        LOGGER.warning("ignore " + e.getMessage());
    } finally {
        Thread.currentThread().setContextClassLoader(origClassLoader);
    }
}

From source file:org.kuali.kpme.tklm.leave.batch.LeaveCalendarDelinquencyJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    Set<String> principalIds = new HashSet<String>();

    DateTime asOfDate = new LocalDate().toDateTimeAtStartOfDay();
    List<CalendarEntry> calendarEntries = getCalendarEntryService()
            .getCurrentCalendarEntriesNeedsScheduled(getCalendarEntriesPollingWindow(), asOfDate);

    for (CalendarEntry calendarEntry : calendarEntries) {
        String hrCalendarId = calendarEntry.getHrCalendarId();
        DateTime currentBeginDate = calendarEntry.getBeginPeriodFullDateTime();

        if (currentBeginDate.isBefore(asOfDate)
                || DateUtils.isSameDay(currentBeginDate.toDate(), asOfDate.toDate())) {
            CalendarEntry previousCalendarEntry = getCalendarEntryService()
                    .getPreviousCalendarEntryByCalendarId(hrCalendarId, calendarEntry);

            if (previousCalendarEntry != null) {
                String calendarName = previousCalendarEntry.getCalendarName();
                LocalDate previousBeginDate = previousCalendarEntry.getBeginPeriodFullDateTime().toLocalDate();
                List<PrincipalHRAttributes> principalHRAttributes = getPrincipalHRAttributesService()
                        .getActiveEmployeesForLeaveCalendar(calendarName, previousBeginDate);

                for (PrincipalHRAttributes principalHRAttribute : principalHRAttributes) {
                    String principalId = principalHRAttribute.getPrincipalId();

                    if (!principalIds.contains(principalId)) {
                        List<LeaveCalendarDocumentHeader> leaveCalendarDocumentHeaders = getLeaveCalendarDocumentHeaderService()
                                .getSubmissionDelinquentDocumentHeaders(principalId, currentBeginDate);

                        if (!leaveCalendarDocumentHeaders.isEmpty()) {
                            principalIds.add(principalId);
                        }//w  w  w .j  av a  2 s  .c  o  m
                    }
                }
            }
        }
    }

    for (String principalId : principalIds) {
        String subject = "Delinquent Leave Calendar Reminder";
        StringBuilder message = new StringBuilder();
        message.append("You currently have one or more DELINQUENT Leave Calendars.");
        message.append(SystemUtils.LINE_SEPARATOR);
        message.append(SystemUtils.LINE_SEPARATOR);
        message.append(
                "Please review/enter your time-off for any prior unapproved months and submit your calendar(s).");

        getKpmeNotificationService().sendNotification(subject, message.toString(), principalId);
    }
}

From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java

private void generateLeaveCalendarChangedNotification(String principalId, String targetPrincipalId,
        String documentId, String hrCalendarEntryId) {
    if (!StringUtils.equals(principalId, targetPrincipalId)) {
        EntityNamePrincipalName person = KimApiServiceLocator.getIdentityService()
                .getDefaultNamesForPrincipalId(principalId);
        if (person != null && person.getDefaultName() != null) {
            String subject = "Leave Calendar Modification Notice";
            StringBuilder message = new StringBuilder();
            message.append("Your Leave Calendar was changed by ");
            message.append(person.getDefaultName().getCompositeNameUnmasked());
            message.append(" on your behalf.");
            message.append(SystemUtils.LINE_SEPARATOR);
            message.append(getLeaveCalendarURL(documentId, hrCalendarEntryId));

            HrServiceLocator.getKPMENotificationService().sendNotification(subject, message.toString(),
                    targetPrincipalId);/*from   w  ww . j a v a2s .  c o  m*/
        }
    }
}

From source file:org.kuali.kpme.tklm.time.detail.web.TimeDetailAction.java

private void generateTimesheetChangedNotification(String principalId, String targetPrincipalId,
        String documentId) {/* www.j  av a2  s  .co  m*/
    if (!StringUtils.equals(principalId, targetPrincipalId)) {
        EntityNamePrincipalName person = KimApiServiceLocator.getIdentityService()
                .getDefaultNamesForPrincipalId(principalId);
        if (person != null && person.getDefaultName() != null) {
            String subject = "Timesheet Modification Notice";
            StringBuilder message = new StringBuilder();
            message.append("Your Timesheet was changed by ");
            message.append(person.getDefaultName().getCompositeNameUnmasked());
            message.append(" on your behalf.");
            message.append(SystemUtils.LINE_SEPARATOR);
            message.append(getTimesheetURL(documentId));

            HrServiceLocator.getKPMENotificationService().sendNotification(subject, message.toString(),
                    targetPrincipalId);
        }
    }
}

From source file:org.marketcetera.event.DepthOfBook.java

@Override
public String toString() {
    StringBuilder output = new StringBuilder();
    output.append("Depth of book for ").append(getSymbol()).append(" at ") //$NON-NLS-1$//$NON-NLS-2$
            .append(DateUtils.dateToString(getTimestampAsDate())).append(SystemUtils.LINE_SEPARATOR);
    output.append(OrderBook.printBook(bids.iterator(), asks.iterator(), true));
    return output.toString();
}

From source file:org.marketcetera.event.impl.DepthOfBookEventImpl.java

@Override
public String toString() {
    StringBuilder output = new StringBuilder();
    output.append("Depth of book for ").append(getInstrument()).append(" at ") //$NON-NLS-1$//$NON-NLS-2$
            .append(DateUtils.dateToString(getTimestamp())).append(SystemUtils.LINE_SEPARATOR);
    output.append(OrderBook.printBook(bids.iterator(), asks.iterator(), true));
    return output.toString();
}

From source file:org.marketcetera.marketdata.OrderBook.java

@Override
public String toString() {
    StringBuilder book = new StringBuilder();
    book.append(getInstrument()).append(SystemUtils.LINE_SEPARATOR);
    book.append(printBook(getBidBook().iterator(), getAskBook().iterator(), false));
    return book.toString();
}