List of usage examples for java.io StringReader close
public void close()
From source file:org.sakaiproject.bbb.impl.util.XmlUtil.java
public static Props convertXmlToProps(String inputString) throws Exception { BeanReader beanReader = getBeanReader(); StringReader reader = null; Props props = null;/*from w w w. j ava 2s. c o m*/ try { reader = new StringReader(inputString); props = (Props) beanReader.parse(reader); } finally { if (reader != null) { reader.close(); } } if (props == null) props = new Props(); return props; }
From source file:elaborate.util.StringUtil.java
public static String html2xml(String editBody) { StringReader in = new StringReader(editBody); StringWriter out = new StringWriter(); TIDY.parse(in, out);//from w w w . j a v a2s . c o m try { in.close(); out.close(); } catch (IOException e) { throw new RuntimeException(e); } return out.toString().replaceAll("\r\n", "").replaceAll("\n", ""); }
From source file:org.kalypso.ogc.sensor.request.RequestFactory.java
/** * Parse an href (usually a Zml-Href) that might contain the request specification * //from w w w . j a v a 2 s . c o m * @throws SensorException * if the href does not contain a valid request */ public static Request parseRequest(final String href) throws SensorException { if (href == null || href.length() == 0) return null; // final int i1 = href.indexOf( ZmlURLConstants.TAG_REQUEST1 ); // if( i1 == -1 ) // return null; // final int i2 = href.indexOf( ZmlURLConstants.TAG_REQUEST2, i1 ); // if( i2 == -1 ) final String strRequestXml = XMLStringUtilities.getXMLPart(href, ZmlURLConstants.TAG_REQUEST); if (strRequestXml == null) return null; // throw new SensorException( "URL-fragment does not contain a valid request definition. URL: " + href ); // final String strRequestXml = href.substring( i1, i2 + ZmlURLConstants.TAG_REQUEST2.length() ); StringReader sr = null; try { sr = new StringReader(strRequestXml); final Request xmlReq = (Request) JC.createUnmarshaller().unmarshal(new InputSource(sr)); sr.close(); return xmlReq; } catch (final JAXBException e) { e.printStackTrace(); throw new SensorException(e); } finally { IOUtils.closeQuietly(sr); } }
From source file:Main.java
public static Object toObject(Class className, String strXml) { Object object = null;// w ww .j ava 2s . c o m StringReader reader = null; try { reader = new StringReader(strXml); JAXBContext context = JAXBContext.newInstance(className); Unmarshaller unmarshaller = context.createUnmarshaller(); object = unmarshaller.unmarshal(reader); } catch (Exception e) { } finally { if (reader != null) { reader.close(); reader = null; } } return object; }
From source file:com.ikon.module.common.CommonNotificationModule.java
/** * Send twitter subscription message/* w w w . ja v a2 s. c o m*/ */ public static void sendTwitterSubscription(String user, String nodePath, String eventType, String comment, Set<String> users) throws TemplateException, TwitterException, DatabaseException, HttpException, IOException { log.debug("sendTwitterSubscription({}, {}, {}, {}, {})", new Object[] { user, nodePath, eventType, comment, users }); Twitter twitter = new Twitter(Config.SUBSCRIPTION_TWITTER_USER, Config.SUBSCRIPTION_TWITTER_PASSWORD); StringWriter swStatus = new StringWriter(); Configuration cfg = TemplateUtils.getConfig(); Map<String, String> model = new HashMap<String, String>(); model.put("documentUrl", MailUtils.getTinyUrl(Config.APPLICATION_URL + "?docPath=" + nodePath)); model.put("documentPath", nodePath); model.put("documentName", PathUtils.getName(nodePath)); model.put("userId", user); model.put("eventType", eventType); model.put("subscriptionComment", comment); if (TemplateUtils.templateExists(Config.SUBSCRIPTION_TWITTER_STATUS)) { Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_TWITTER_STATUS); tpl.process(model, swStatus); } else { StringReader sr = new StringReader(Config.SUBSCRIPTION_TWITTER_STATUS); Template tpl = new Template("SubscriptionTwitterStatus", sr, cfg); tpl.process(model, swStatus); sr.close(); } for (Iterator<String> itUsers = users.iterator(); itUsers.hasNext();) { String itUser = itUsers.next(); Collection<TwitterAccount> twitterAccounts = TwitterAccountDAO.findByUser(itUser, true); for (Iterator<TwitterAccount> itTwitter = twitterAccounts.iterator(); itTwitter.hasNext();) { TwitterAccount ta = itTwitter.next(); log.info("Twitter Notify from {} to {} ({}) - {}", new Object[] { twitter.getUserId(), ta.getTwitterUser(), itUser, swStatus.toString() }); twitter.sendDirectMessage(ta.getTwitterUser(), swStatus.toString()); } } }
From source file:com.ikon.module.common.CommonNotificationModule.java
/** * Clean preview cache for this document * @throws SMTPException //from ww w . java 2s .c om */ public static void sendNotification(String user, String nodePath, String from, List<String> to, String message, boolean attachment) throws TemplateException, MessagingException, PathNotFoundException, AccessDeniedException, RepositoryException, DatabaseException, IOException, MessagingException, RepositoryException, SMTPException { log.debug("sendNotification({}, {}, {}, {}, {}, {})", new Object[] { user, nodePath, from, to, message, attachment }); StringWriter swSubject = new StringWriter(); StringWriter swBody = new StringWriter(); Configuration cfg = TemplateUtils.getConfig(); Map<String, String> model = new HashMap<String, String>(); model.put("documentUrl", Config.APPLICATION_URL + "?docPath=" + URLEncoder.encode(nodePath, "UTF-8")); model.put("documentPath", nodePath); model.put("documentName", PathUtils.getName(nodePath)); model.put("userId", user); model.put("notificationMessage", message); if (TemplateUtils.templateExists(Config.NOTIFICATION_MESSAGE_SUBJECT)) { Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAGE_SUBJECT); tpl.process(model, swSubject); } else { StringReader sr = new StringReader(Config.NOTIFICATION_MESSAGE_SUBJECT); Template tpl = new Template("NotificationMessageSubject", sr, cfg); tpl.process(model, swSubject); sr.close(); } if (TemplateUtils.templateExists(Config.NOTIFICATION_MESSAGE_BODY)) { Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAGE_BODY); tpl.process(model, swBody); } else { StringReader sr = new StringReader(Config.NOTIFICATION_MESSAGE_BODY); Template tpl = new Template("NotificationMessageBody", sr, cfg); tpl.process(model, swBody); sr.close(); } if (attachment) { SMTPUtils.sendMails((String) from, to, swSubject.toString(), noHTMLTags(swBody.toString()), nodePath); } else { SMTPUtils.sendMails((String) from, to, swSubject.toString(), noHTMLTags(swBody.toString()), null); } }
From source file:com.ikon.module.common.CommonNotificationModule.java
/** * Send mail subscription message//from w ww .ja v a 2s . c om * @throws DatabaseException * @throws AccessDeniedException * @throws PathNotFoundException * @throws SMTPException */ public static void sendMailSubscription(String user, String nodePath, String eventType, String comment, Set<String> mails) throws TemplateException, MessagingException, IOException, DatabaseException, RepositoryException, PathNotFoundException, AccessDeniedException, SMTPException { log.debug("sendMailSubscription({}, {}, {}, {}, {})", new Object[] { user, nodePath, eventType, comment, mails }); if (comment == null) { comment = ""; } StringWriter swSubject = new StringWriter(); StringWriter swBody = new StringWriter(); Configuration cfg = TemplateUtils.getConfig(); Map<String, String> model = new HashMap<String, String>(); model.put("documentUrl", Config.APPLICATION_URL + "?docPath=" + URLEncoder.encode(nodePath, "UTF-8")); model.put("documentPath", nodePath); model.put("documentName", PathUtils.getName(nodePath)); model.put("userId", user); model.put("eventType", eventType); model.put("subscriptionComment", comment); if (TemplateUtils.templateExists(Config.SUBSCRIPTION_MESSAGE_SUBJECT)) { Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_MESSAGE_SUBJECT); tpl.process(model, swSubject); } else { StringReader sr = new StringReader(Config.SUBSCRIPTION_MESSAGE_SUBJECT); Template tpl = new Template("SubscriptionMessageSubject", sr, cfg); tpl.process(model, swSubject); sr.close(); } if (TemplateUtils.templateExists(Config.SUBSCRIPTION_MESSAGE_BODY)) { Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_MESSAGE_BODY); tpl.process(model, swBody); } else { StringReader sr = new StringReader(Config.SUBSCRIPTION_MESSAGE_BODY); Template tpl = new Template("SubscriptionMessageBody", sr, cfg); tpl.process(model, swBody); sr.close(); } SMTPUtils.sendMails(null, mails, swSubject.toString(), noHTMLTags(swBody.toString()), null); }
From source file:com.openkm.module.common.CommonNotificationModule.java
/** * Send mail subscription message/*from ww w .j a v a 2s. c o m*/ */ public static void sendMailSubscription(String user, String nodeUuid, String nodePath, String eventType, String comment, Set<String> mails) throws TemplateException, MessagingException, IOException { log.debug("sendMailSubscription({}, {}, {}, {}, {}, {})", new Object[] { user, nodeUuid, nodePath, eventType, comment, mails }); if (comment == null) { comment = ""; } StringWriter swSubject = new StringWriter(); StringWriter swBody = new StringWriter(); Configuration cfg = TemplateUtils.getConfig(); Map<String, String> model = new HashMap<String, String>(); model.put("documentUrl", Config.APPLICATION_URL + "?uuid=" + nodeUuid); model.put("documentPath", nodePath); model.put("documentName", PathUtils.getName(nodePath)); model.put("userId", user); model.put("eventType", eventType); model.put("subscriptionComment", comment); if (TemplateUtils.templateExists(Config.SUBSCRIPTION_MESSAGE_SUBJECT)) { Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_MESSAGE_SUBJECT); tpl.process(model, swSubject); } else { StringReader sr = new StringReader(Config.SUBSCRIPTION_MESSAGE_SUBJECT); Template tpl = new Template("SubscriptionMessageSubject", sr, cfg); tpl.process(model, swSubject); sr.close(); } if (TemplateUtils.templateExists(Config.SUBSCRIPTION_MESSAGE_BODY)) { Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_MESSAGE_BODY); tpl.process(model, swBody); } else { StringReader sr = new StringReader(Config.SUBSCRIPTION_MESSAGE_BODY); Template tpl = new Template("SubscriptionMessageBody", sr, cfg); tpl.process(model, swBody); sr.close(); } MailUtils.sendMessage(mails, swSubject.toString(), swBody.toString()); }
From source file:com.openkm.module.common.CommonNotificationModule.java
public static void sendNotification(String user, ArrayList<CommonNotificationModule.NodeInfo> nodesInfo, String from, List<String> to, String message, boolean attachment) throws TemplateException, MessagingException, PathNotFoundException, AccessDeniedException, RepositoryException, DatabaseException, IOException { log.debug("sendNotification({}, {}, {}, {}, {}, {})", new Object[] { user, nodesInfo, from, to, message, attachment }); StringWriter swSubject = new StringWriter(); StringWriter swBody = new StringWriter(); Configuration cfg = TemplateUtils.getConfig(); List<String> docsPath = new ArrayList<String>(); Collection<Map<String, String>> col = new ArrayList<Map<String, String>>(); for (CommonNotificationModule.NodeInfo ni : nodesInfo) { Map<String, String> docInfo = new HashMap<String, String>(); docInfo.put("url", Config.APPLICATION_URL + "?uuid=" + ni.getUuid()); docInfo.put("path", ni.getPath()); docInfo.put("name", PathUtils.getName(ni.getPath())); col.add(docInfo);/*from www . ja v a2 s . c o m*/ // Used to send attachments docsPath.add(ni.getPath()); } Map<String, Object> model = new HashMap<String, Object>(); model.put("userId", user); model.put("notificationMessage", message); model.put("documentList", col); if (TemplateUtils.templateExists(Config.NOTIFICATION_MESSAGE_SUBJECT)) { Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAGE_SUBJECT); tpl.process(model, swSubject); } else { StringReader sr = new StringReader(Config.NOTIFICATION_MESSAGE_SUBJECT); Template tpl = new Template("NotificationMessageSubject", sr, cfg); tpl.process(model, swSubject); sr.close(); } if (TemplateUtils.templateExists(Config.NOTIFICATION_MESSAGE_BODY)) { Template tpl = cfg.getTemplate(Config.NOTIFICATION_MESSAGE_BODY); tpl.process(model, swBody); } else { StringReader sr = new StringReader(Config.NOTIFICATION_MESSAGE_BODY); Template tpl = new Template("NotificationMessageBody", sr, cfg); tpl.process(model, swBody); sr.close(); } if (attachment) { MailUtils.sendDocuments((String) from, to, swSubject.toString(), swBody.toString(), docsPath); } else { MailUtils.sendMessage((String) from, to, swSubject.toString(), swBody.toString()); } }
From source file:org.sakaiproject.sitestats.impl.parser.DigesterUtil.java
public static ReportParams convertXmlToReportParams(String inputString) throws Exception { BeanReader beanReader = getBeanReader(); StringReader reader = null; ReportParams reportParams = null;//from w w w .j a v a 2 s . c o m try { reader = new StringReader(inputString); reportParams = (ReportParams) beanReader.parse(reader); } finally { if (reader != null) { reader.close(); } } return reportParams; }