Example usage for java.io OutputStream toString

List of usage examples for java.io OutputStream toString

Introduction

In this page you can find the example usage for java.io OutputStream toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.groupon.odo.Proxy.java

/**
 * @param httpServletResponse/*from ww w.j  a v  a  2 s .  c  o  m*/
 * @param outStream
 * @param jsonpCallback
 * @throws IOException
 */
private void writeResponseOutput(HttpServletResponse httpServletResponse, OutputStream outStream,
        String jsonpCallback) throws IOException {
    RequestInformation requestInfo = requestInformation.get();

    // check to see if this is chunked
    boolean chunked = false;
    if (httpServletResponse.containsHeader(HttpUtilities.STRING_TRANSFER_ENCODING) && httpServletResponse
            .getHeader(HttpUtilities.STRING_TRANSFER_ENCODING).compareTo("chunked") == 0) {
        httpServletResponse.setHeader(HttpUtilities.STRING_CONNECTION, HttpUtilities.STRING_CHUNKED);
        chunked = true;
    }

    // reattach JSONP if needed
    if (requestInfo.outputString != null && jsonpCallback != null) {
        requestInfo.outputString = jsonpCallback + "(" + requestInfo.outputString + ");";
    }

    // don't do this if we got a HTTP 304 since there is no data to send back
    if (httpServletResponse.getStatus() != HttpServletResponse.SC_NOT_MODIFIED) {
        logger.info("Chunked: {}, {}", chunked, httpServletResponse.getBufferSize());
        if (!chunked) {
            // change the content length header to the new length
            if (requestInfo.outputString != null) {
                httpServletResponse.setContentLength(requestInfo.outputString.getBytes().length);
            } else {
                httpServletResponse.setContentLength(((ByteArrayOutputStream) outStream).toByteArray().length);
            }
        }

        OutputStream outputStreamClientResponse = httpServletResponse.getOutputStream();

        if (requestInfo.outputString != null) {
            outputStreamClientResponse.write(requestInfo.outputString.getBytes());
        } else {
            outputStreamClientResponse.write(((ByteArrayOutputStream) outStream).toByteArray());
        }
        httpServletResponse.flushBuffer();

        logger.info("Done writing");
    }

    // outstr might still be null.. let's try to set it from outStream
    if (requestInfo.outputString == null) {
        try {
            requestInfo.outputString = outStream.toString();
        } catch (Exception e) {
            // can ignore any issues.. worst case outstr is still null
        }
    }
}

From source file:org.ebayopensource.turmeric.eclipse.buildsystem.utils.ProjectPropertiesFileUtil.java

/**
 * Creates the interface project properties file. The name of the file is
 * "service_intf_project.properties". This file has information like source
 * type of the project, package to name space mapping etc.
 *
 * @param soaIntfProject the soa intf project
 * @param monitor the monitor//from www .  j a va 2  s .co m
 * @return the i file
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws CoreException the core exception
 */
public static IFile createPropsFile(SOAIntfProject soaIntfProject, IProgressMonitor monitor)
        throws IOException, CoreException {
    IFile file = soaIntfProject.getEclipseMetadata().getProject()
            .getFile(SOAProjectConstants.PROPS_FILE_SERVICE_INTERFACE);
    OutputStream output = null;
    try {
        output = new ByteArrayOutputStream();
        final Properties properties = new Properties();
        final SOAIntfMetadata metadata = soaIntfProject.getMetadata();
        addServiceMetadataProperties(properties, metadata);
        if (metadata.getServiceNonXSDProtocols() == null) {
            boolean protoBufCreated = ProjectProtoBufFileUtil.createServiceProtoBufFile(soaIntfProject,
                    metadata.getServiceLocation());
            if (protoBufCreated == true) {
                properties.setProperty(SOAProjectConstants.PROP_KEY_NON_XSD_FORMATS,
                        SOAProjectConstants.SVC_PROTOCOL_BUF);
            }
        }
        if (SOAProjectConstants.InterfaceSourceType.WSDL.equals(metadata.getSourceType())
                || SOAProjectConstants.InterfaceWsdlSourceType.EXISTIING.equals(metadata.getWsdlSourceType())) {
            properties.setProperty(SOAProjectConstants.PROPS_INTF_SOURCE_TYPE,
                    SOAProjectConstants.PROPS_INTF_SOURCE_TYPE_WSDL);
            if (metadata.getNamespaceToPackageMappings().isEmpty() == false) {
                final Collection<String> data = new ArrayList<String>();
                for (final String namespace : metadata.getNamespaceToPackageMappings().keySet()) {
                    final String pakcage = metadata.getNamespaceToPackageMappings().get(namespace);
                    data.add(namespace + SOAProjectConstants.DELIMITER_PIPE + pakcage);
                }
                final String ns2pkg = StringUtils.join(data, SOAProjectConstants.DELIMITER_COMMA);
                properties.setProperty(SOAProjectConstants.PROPS_KEY_NAMESPACE_TO_PACKAGE, ns2pkg);
            }
        } else {
            properties.setProperty(SOAProjectConstants.PROPS_INTF_SOURCE_TYPE,
                    SOAProjectConstants.PROPS_INTF_SOURCE_TYPE_JAVA);
        }
        if (!metadata.getTypeFolding() && StringUtils.isNotBlank(metadata.getTypeNamespace())) {
            properties.setProperty(SOAProjectConstants.PROPS_KEY_TYPE_NAMESPACE, metadata.getTypeNamespace());
        }
        if (StringUtils.isNotBlank(metadata.getServiceDomainName())) {
            properties.setProperty(SOAProjectConstants.PROPS_SERVICE_DOMAIN_NAME,
                    metadata.getServiceDomainName());
        }

        if (StringUtils.isNotBlank(metadata.getServiceNamespacePart())) {
            properties.setProperty(SOAProjectConstants.PROPS_SERVICE_NAMESPACE_PART,
                    metadata.getServiceNamespacePart());
        }

        properties.setProperty(SOAProjectConstants.PROPS_KEY_TYPE_FOLDING,
                Boolean.toString(metadata.getTypeFolding()));
        properties.setProperty(SOAProjectConstants.PROPS_SUPPORT_ZERO_CONFIG, Boolean.TRUE.toString());

        ISOAConfigurationRegistry configReg = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem()
                .getConfigurationRegistry();
        if (configReg != null && StringUtils.isNotBlank(configReg.getEnvironmentMapperImpl())) {
            properties.setProperty(SOAProjectConstants.PROPS_ENV_MAPPER, configReg.getEnvironmentMapperImpl());
        }

        properties.setProperty(SOAProjectConstants.PROPS_KEY_SIPP_VERSION,
                SOAProjectConstants.PROPS_DEFAULT_SIPP_VERSION);

        //short package name for shared consumer
        final String intfPkgName = StringUtils.substringBeforeLast(metadata.getServiceInterface(),
                SOAProjectConstants.DELIMITER_DOT);
        properties.setProperty(SOAProjectConstants.PROPS_KEY_SHORT_PATH_FOR_SHARED_CONSUMER,
                intfPkgName + SOAProjectConstants.DELIMITER_DOT + SOAProjectConstants.GEN);

        properties.store(output, SOAProjectConstants.PROPS_COMMENTS);

        WorkspaceUtil.writeToFile(output.toString(), file, monitor);
    } finally {
        IOUtils.closeQuietly(output);
    }
    return file;
}

From source file:org.exoplatform.calendar.ws.CalendarRestApi.java

/**
 * Returns an iCalendar formated file which is exported from the calendar with specified id if:
 * - the calendar is public/*from  w ww.  ja  v a  2  s .  c om*/
 * - the authenticated user is the owner of the calendar
 * - the authenticated user belongs to the group of the calendar
 * - the calendar has been shared with the authenticated user or with a group of the authenticated user
 * 
 * @param id   
 *        identity of the calendar to retrieve ICS file
 * 
 * @request GET: http://localhost:8080/portal/rest/v1/calendar/calendars/demo-defaultCalendarId/ics
 * 
 * @format text/calendar
 * 
 * @response ICS file of calendar, or HTTP status code: 404 if not found
 * 
 * @return  ICS file or Http status code
 * 
 * @authentication
 *  
 * @anchor CalendarRestApi.exportCalendarToIcs
 */
@GET
@RolesAllowed("users")
@Path("/calendars/{id}/ics")
@Produces(TEXT_ICS)
public Response exportCalendarToIcs(@PathParam("id") String id, @Context Request request) {
    try {
        Calendar cal = calendarServiceInstance().getCalendarById(id);
        if (cal == null)
            return Response.status(HTTPStatus.NOT_FOUND).cacheControl(nc).build();

        if (cal.getPublicUrl() != null || this.hasViewCalendarPermission(cal, currentUserId())) {
            int type = calendarServiceInstance().getTypeOfCalendar(currentUserId(), id);
            String username = currentUserId();
            if (type == -1) {
                //this is a workaround
                //calendarService can't find type of calendar correctly 
                type = Calendar.TYPE_PRIVATE;
                username = cal.getCalendarOwner();
            }

            CalendarImportExport iCalExport = calendarServiceInstance()
                    .getCalendarImportExports(CalendarService.ICALENDAR);
            ArrayList<String> calIds = new ArrayList<String>();
            calIds.add(id);
            OutputStream out = iCalExport.exportCalendar(username, calIds, String.valueOf(type),
                    Utils.UNLIMITED);
            byte[] data = out.toString().getBytes();

            byte[] hashCode = digest(data).getBytes();
            EntityTag tag = new EntityTag(new String(hashCode));
            ResponseBuilder preCondition = request.evaluatePreconditions(tag);
            if (preCondition != null) {
                return preCondition.build();
            }

            InputStream in = new ByteArrayInputStream(data);
            return Response.ok(in, TEXT_ICS_TYPE)
                    .header("Content-Disposition", "attachment;filename=\"" + cal.getName() + Utils.ICS_EXT)
                    .cacheControl(cc).tag(tag).build();
        } else {
            return Response.status(HTTPStatus.NOT_FOUND).cacheControl(nc).build();
        }
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug(e.getMessage());
    }
    return Response.status(HTTPStatus.UNAVAILABLE).cacheControl(nc).build();

}

From source file:org.sdm.spa.actors.transport.BbcpCopier.java

@Override
protected CopyResult copyTo(String srcFile, ConnectionDetails destDetails, String destFile, boolean recursive)
        throws SshException {
    cmdLineOptions = ""; // Review - don't forcefully rewrite.
    // If user wants to overwrite he can set it as command line option, but
    // if you//from w  w w.ja  va 2  s  . c o m
    // set it, he can't override it with any command line
    // option*********#DONE
    String osname = (System.getProperty("os.name")).toLowerCase();
    String userhome = (System.getProperty("user.home")).toLowerCase();
    if (osname.contains("windows")) {
        throw new SshException("BBCP is not supported on Windows machines");
    }

    int exitCode = 0;
    String cmdWithPath;
    File srcFile_Obj = null;
    boolean flag = false;
    String[] srcFileList = null;
    String[] srcFile_list = null;
    StringBuffer warn = new StringBuffer(100);

    OutputStream streamOut = new ByteArrayOutputStream();
    OutputStream streamErr = new ByteArrayOutputStream();
    StringBuffer cmd = new StringBuffer(100);
    SshExec localSshObj = new SshExec(System.getProperty("user.name"), "localhost");
    localSshObj.setTimeout(timeout, false, false);
    localSshObj.setPseudoTerminal(true);
    localSshObj.setForcedCleanUp(forcedCleanup);
    System.out.println("Initial str : " + srcFile);
    if (srcFile.contains(",")) {
        // Anand: list of files
        System.out.println("list of files************");
        srcFileList = srcFile.split(",");
        srcFile_list = new String[srcFileList.length];
        for (int count = 0; count < srcFileList.length; count++) {
            System.out.println("before : " + srcFileList[count]);

            if ((srcFileList[count].trim()).startsWith("/")) {
                srcFile_list[count] = srcFileList[count].trim();
            } else {
                srcFile_list[count] = userhome + "/" + srcFileList[count].trim();
            }
            srcFile_Obj = new File(srcFileList[count]);
            if (srcFile_Obj.isDirectory()) {
                flag = true;
            }
            System.out.println("after : " + srcFile_list[count]);
        }
    } else {
        System.out.println("single files************");
        // Anand: single file
        srcFile_list = new String[1];
        srcFile = srcFile.trim();
        if (srcFile.startsWith("/")) {
            srcFile_list[0] = srcFile;
        } else {
            srcFile_list[0] = userhome + "/" + srcFile;
        }
        srcFile_Obj = new File(srcFile);
        if (srcFile_Obj.isDirectory()) {
            flag = true;
        }
    }

    // build bbcp command
    cmd.append("bbcp ");
    cmd.append(cmdLineOptions);
    cmd.append(" ");
    if (recursive || flag) {
        cmd.append("-r ");
    }
    if (!protocolPathSrc.equals("")) {
        cmd.append("-S \"ssh -l %U %H ");
        cmd.append(protocolPathSrc);
        cmd.append("bbcp\" ");
    }
    if (!protocolPathDest.equals("")) {
        cmd.append("-T \"ssh -l %U %H ");
        cmd.append(protocolPathDest);
        cmd.append("bbcp\" ");
    }
    // all files are in the srcFile_list (single file too)
    for (int i = 0; i < srcFile_list.length; i++) {
        if (srcFile_list[i].contains("*") || (srcFile_list[i].contains("*"))) {
            // no quotes if file contains wildcard
            cmd.append(srcFile_list[i]);
            cmd.append(" ");
        } else {
            // quotes if file does not contain wildcard - it might contain
            // space in file name
            cmd.append("\"");
            cmd.append(srcFile_list[i]);
            cmd.append("\"");
            cmd.append(" ");
        }
    }
    cmd.append(destDetails.toString());
    cmd.append(":");
    cmd.append(destFile);

    if (protocolPathSrc.equals("")) {
        cmdWithPath = getCmdWithDefaultPath(cmd);
    } else {
        cmdWithPath = protocolPathSrc + cmd;
    }
    System.out.println("BBCP Command to be executed is : " + cmdWithPath);
    if (isDebugging)
        log.debug("copy cmd=" + cmdWithPath);
    try {
        exitCode = localSshObj.executeCmd(cmdWithPath, streamOut, streamErr, destDetails.toString());
    } catch (ExecException e) {
        return new CopyResult(1, e.toString(), "");
    }
    if (exitCode > 0) {
        log.error("Output on stdout:" + streamOut);
        log.error("Output on stderr:" + streamErr);
    }
    String message = streamErr.toString();
    if (message == null || message.trim().equals("")) {
        message = streamOut.toString();
    }
    return new CopyResult(exitCode, message, warn.toString());
}

From source file:org.exoplatform.calendar.service.impl.JCRDataStorage.java

/**
 * {@inheritDoc}//w w  w. j  av a2 s .c o  m
 */
@Deprecated
public void updateCalDav(String username, String calendarId, CalendarImportExport imp) throws Exception {
    calendarId = calendarId.substring(0, calendarId.lastIndexOf("."));
    String id = calendarId.split(Utils.SPLITTER)[0];
    String type = calendarId.split(Utils.SPLITTER)[1];
    Node rssHome = getRssHome(username);
    if (rssHome.hasNode(Utils.CALDAV_NODE)) {
        NodeIterator iter = rssHome.getNode(Utils.CALDAV_NODE).getNodes();
        while (iter.hasNext()) {
            Node rssCal = iter.nextNode();
            Node nodeContent = rssCal.getNode(Utils.JCR_CONTENT);
            OutputStream out = imp.exportCalendar(username, Arrays.asList(new String[] { id }), type, -1);
            if (out != null) {
                ByteArrayInputStream is = new ByteArrayInputStream(out.toString().getBytes());
                nodeContent.setProperty(Utils.JCR_DATA, is);
            } else {
                removeFeed(username, id);
            }
        }
        rssHome.getSession().save();
    }
}

From source file:org.exoplatform.calendar.service.impl.JCRDataStorage.java

/**
 * {@inheritDoc}/*from w  w w.  j  a v a 2  s . c om*/
 */
@Deprecated
public void updateCalDav(String username, String calendarId, CalendarImportExport imp, int number)
        throws Exception {
    calendarId = calendarId.substring(0, calendarId.lastIndexOf("."));
    String id = calendarId.split(Utils.SPLITTER)[0];
    String type = calendarId.split(Utils.SPLITTER)[1];
    Node rssHome = getRssHome(username);
    if (rssHome.hasNode(Utils.CALDAV_NODE)) {
        NodeIterator iter = rssHome.getNode(Utils.CALDAV_NODE).getNodes();
        while (iter.hasNext()) {
            Node rssCal = iter.nextNode();
            Node nodeContent = rssCal.getNode(Utils.JCR_CONTENT);
            OutputStream out = imp.exportCalendar(username, Arrays.asList(new String[] { id }), type, number);
            if (out != null) {
                ByteArrayInputStream is = new ByteArrayInputStream(out.toString().getBytes());
                nodeContent.setProperty(Utils.JCR_DATA, is);
            } else {
                removeFeed(username, id);
            }
        }
        rssHome.getSession().save();
    }
}

From source file:org.exoplatform.calendar.service.impl.JCRDataStorage.java

/**
 * {@inheritDoc}/*from   w  ww.  j  a v a2s  .  c o m*/
 */
@Deprecated
public void updateRss(String username, String calendarId, CalendarImportExport imp) throws Exception {
    calendarId = calendarId.substring(0, calendarId.lastIndexOf("."));
    String id = calendarId.split(Utils.SPLITTER)[0];
    String type = calendarId.split(Utils.SPLITTER)[1];
    Node rssHome = getRssHome(username);
    if (rssHome.hasNode(Utils.RSS_NODE)) {
        NodeIterator iter = rssHome.getNode(Utils.RSS_NODE).getNodes();
        while (iter.hasNext()) {
            Node rssCal = iter.nextNode();
            if (rssCal.getPath().contains(calendarId)) {
                OutputStream out = imp.exportCalendar(username, Arrays.asList(new String[] { id }), type, -1);
                if (out != null) {
                    ByteArrayInputStream is = new ByteArrayInputStream(out.toString().getBytes());
                    rssCal.setProperty(Utils.EXO_DATA, is);
                    rssCal.save();
                } else {
                    removeFeed(username, id);
                    /*
                     * rssCal.remove() ; rssHome.getSession().save() ;
                     */
                }
                break;
            }
        }
    }
}

From source file:org.exoplatform.calendar.service.impl.JCRDataStorage.java

/**
 * {@inheritDoc}/*w  ww. ja  v  a  2s .  c  o  m*/
 */
@Deprecated
public void updateRss(String username, String calendarId, CalendarImportExport imp, int number)
        throws Exception {
    calendarId = calendarId.substring(0, calendarId.lastIndexOf("."));
    String id = calendarId.split(Utils.SPLITTER)[0];
    String type = calendarId.split(Utils.SPLITTER)[1];
    Node rssHome = getRssHome(username);
    if (rssHome.hasNode(Utils.RSS_NODE)) {
        NodeIterator iter = rssHome.getNode(Utils.RSS_NODE).getNodes();
        while (iter.hasNext()) {
            Node rssCal = iter.nextNode();
            if (rssCal.getPath().contains(calendarId)) {
                OutputStream out = imp.exportCalendar(username, Arrays.asList(new String[] { id }), type,
                        number);
                if (out != null) {
                    ByteArrayInputStream is = new ByteArrayInputStream(out.toString().getBytes());
                    rssCal.setProperty(Utils.EXO_DATA, is);
                    rssCal.save();
                } else {
                    removeFeed(username, id);
                }
                break;
            }
        }
    }
}

From source file:org.exoplatform.calendar.service.impl.JCRDataStorage.java

/**
 * {@inheritDoc}/*from  ww w  .jav a2 s . c o  m*/
 */
@Deprecated
public int generateRss(String username, List<String> calendarIds, RssData rssData,
        CalendarImportExport importExport) throws Exception {

    Node rssHomeNode = getRssHome(username);
    Node iCalHome = null;
    try {
        iCalHome = rssHomeNode.getNode(Utils.RSS_NODE);
    } catch (Exception e) {
        iCalHome = rssHomeNode.addNode(Utils.RSS_NODE, Utils.NT_UNSTRUCTURED);
    }
    try {
        SyndFeed feed = new SyndFeedImpl();
        feed.setFeedType(rssData.getVersion());
        feed.setTitle(rssData.getTitle());
        feed.setLink(rssData.getLink());
        feed.setDescription(rssData.getDescription());
        List<SyndEntry> entries = new ArrayList<SyndEntry>();
        SyndEntry entry;
        SyndContent description;
        String portalName = PortalContainer.getCurrentPortalContainerName();
        for (String calendarId : calendarIds) {
            OutputStream out = importExport.exportCalendar(username, Arrays.asList(new String[] { calendarId }),
                    "0", -1);
            if (out != null) {
                ByteArrayInputStream is = new ByteArrayInputStream(out.toString().getBytes());
                try {
                    iCalHome.getNode(calendarId + Utils.ICS_EXT).setProperty(Utils.EXO_DATA, is);
                } catch (Exception e) {
                    Node ical = iCalHome.addNode(calendarId + Utils.ICS_EXT, Utils.EXO_ICAL_DATA);
                    ical.setProperty(Utils.EXO_DATA, is);
                }
                StringBuffer path = new StringBuffer(Utils.SLASH);
                path.append(iCalHome.getName()).append(Utils.SLASH)
                        .append(iCalHome.getNode(calendarId + Utils.ICS_EXT).getName());
                String url = getEntryUrl(portalName, rssHomeNode.getSession().getWorkspace().getName(),
                        username, path.toString(), rssData.getUrl());
                Calendar exoCal = getUserCalendar(username, calendarId);
                entry = new SyndEntryImpl();
                entry.setTitle(exoCal.getName());
                entry.setLink(url);
                entry.setAuthor(username);
                description = new SyndContentImpl();
                description.setType(Utils.MIMETYPE_TEXTPLAIN);
                description.setValue(exoCal.getDescription());
                entry.setDescription(description);
                entries.add(entry);
                entry.getEnclosures();
            }
        }
        if (!entries.isEmpty()) {
            feed.setEntries(entries);
            feed.setEncoding("UTF-8");
            SyndFeedOutput output = new SyndFeedOutput();
            String feedXML = output.outputString(feed);
            feedXML = StringUtils.replace(feedXML, "&amp;", "&");
            storeXML(feedXML, rssHomeNode, rssData);
            rssHomeNode.getSession().save();
        } else {
            log.info("No data to make rss!");
            return -1;
        }
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug(e);
        return -1;
    }
    return 1;
}

From source file:org.exoplatform.calendar.service.impl.JCRDataStorage.java

/**
 * {@inheritDoc}/*from   ww w . j a va  2  s  .c  om*/
 */
@Deprecated
public int generateCalDav(String username, List<String> calendarIds, RssData rssData,
        CalendarImportExport importExport) throws Exception {
    Node rssHomeNode = getRssHome(username);
    Node iCalHome = null;
    try {
        iCalHome = rssHomeNode.getNode(Utils.CALDAV_NODE);
    } catch (Exception e) {
        iCalHome = rssHomeNode.addNode(Utils.CALDAV_NODE, Utils.NT_UNSTRUCTURED);
    }
    try {
        SyndFeed feed = new SyndFeedImpl();
        feed.setFeedType(rssData.getVersion());
        feed.setTitle(rssData.getTitle());
        feed.setLink(rssData.getLink());
        feed.setDescription(rssData.getDescription());
        List<SyndEntry> entries = new ArrayList<SyndEntry>();
        SyndEntry entry;
        SyndContent description;
        for (String calendarId : calendarIds) {
            OutputStream out = importExport.exportCalendar(username, Arrays.asList(new String[] { calendarId }),
                    "0", -1);
            if (out != null) {
                ByteArrayInputStream is = new ByteArrayInputStream(out.toString().getBytes());
                Node ical = null;
                Node nodeContent = null;
                try {
                    ical = iCalHome.getNode(calendarId + Utils.ICS_EXT);
                    nodeContent = ical.getNode(Utils.JCR_CONTENT);
                } catch (Exception e) {
                    ical = iCalHome.addNode(calendarId + Utils.ICS_EXT, Utils.NT_FILE);
                    nodeContent = ical.addNode(Utils.JCR_CONTENT, Utils.NT_RESOURCE);
                }
                nodeContent.setProperty(Utils.JCR_LASTMODIFIED,
                        java.util.Calendar.getInstance().getTimeInMillis());
                nodeContent.setProperty(Utils.JCR_MIMETYPE, Utils.MIMETYPE_ICALENDAR);
                nodeContent.setProperty(Utils.JCR_DATA, is);
                if (!iCalHome.isNew())
                    iCalHome.save();
                else
                    iCalHome.getSession().save();
                String link = rssData.getLink() + ical.getPath();
                Calendar exoCal = getUserCalendar(username, calendarId);
                entry = new SyndEntryImpl();
                entry.setTitle(exoCal.getName());
                entry.setLink(link);
                description = new SyndContentImpl();
                description.setType(Utils.MIMETYPE_TEXTPLAIN);
                description.setValue(exoCal.getDescription());
                entry.setDescription(description);
                entry.setAuthor(username);
                entries.add(entry);
                entry.getEnclosures();
            }
        }
        if (!entries.isEmpty()) {
            feed.setEntries(entries);
            feed.setEncoding("UTF-8");
            SyndFeedOutput output = new SyndFeedOutput();
            String feedXML = output.outputString(feed);
            feedXML = StringUtils.replace(feedXML, "&amp;", "&");
            storeXML(feedXML, rssHomeNode, rssData);
            rssHomeNode.getSession().save();
        } else {
            log.info("No data to make caldav!");
            return -1;
        }

    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug(e);
        return -1;
    }
    return 1;
}