public String getRSSItem(Document doc) { StringBuilder output = new StringBuilder(); output.append("<item>"); output.append(emitTag("guid", doc.get(DublinCore.SOURCE.getName()), "isPermalink", "true")); output.append(emitTag("title", doc.get(TikaCoreProperties.TITLE.getName()), null, null)); output.append(emitTag("link", doc.get(DublinCore.SOURCE.getName()), null, null)); output.append(emitTag("author", doc.get(TikaCoreProperties.CREATOR.getName()), null, null)); for (String topic : doc.getValues(TikaCoreProperties.SUBJECT.getName())) { output.append(emitTag("category", topic, null, null)); } output.append(emitTag("pubDate", rssDateFormat.format(ISO8601.parse(doc .get(TikaCoreProperties.CREATED.getName()))), null, null)); output.append(emitTag("description", doc.get(TikaCoreProperties.TITLE.getName()), null, null)); output.append("</item>"); return output.toString(); }
/** * * @param fileName * @param useMultiByte * @return */ public static String fileNameEncode( String fileName, boolean useMultiByte ) { if ( useMultiByte ) { return Text.escapeIllegalJcrChars( ISO9075.encode( fileName ) ); } else { return Text.escapeIllegalJcrChars( fileName ); } }
/** * * @param encodedFileName * @param useMultiByte * @return */ public static String fileNameDecode( String encodedFileName, boolean useMultiByte ) { if ( useMultiByte ) { return Text.unescapeIllegalJcrChars( ISO9075.decode( encodedFileName ) ); } else { return Text.unescapeIllegalJcrChars( encodedFileName ); } }
void setSearchRoots(String userSearchRoot, String groupSearchRoot) { this.userSearchRoot = userSearchRoot; this.groupSearchRoot = groupSearchRoot; authorizableSearchRoot = userSearchRoot; while (!Text.isDescendant(authorizableSearchRoot, groupSearchRoot)) { authorizableSearchRoot = Text.getRelativeParent(authorizableSearchRoot, 1); } }
/** * @param input Calendar value * @return ISO8601 string representation or null */ public static String calendarToString(Calendar input) { if (input == null) { return null; } return ISO8601.format(input); }
/** * Decode base64 encoded data. * * @param chars the base64 encoded data to be decoded * @param out stream where the decoded data should be written to * @throws java.io.IOException if an i/o error occurs */ public static void decode(char[] chars, OutputStream out) throws IOException { decode(chars, 0, chars.length, out); }
/** * Replace wildcards and return the expanded SQL statement. * * @param sql The SQL with embedded wildcards. * @return The SQL with no wildcards present. */ protected String createSchemaSql(String sql) { // replace prefix variable return Text.replace(sql, SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix); }
@Override @SuppressWarnings("unchecked") public T with(Node lockable, boolean isDeep) throws RepositoryException, InterruptedException { return (T) super.with(lockable, isDeep); }
/** * Escapes input text suitable for the output format. * <p> * By default does XML-escaping. Can be overridden for * other formats. * * @param input raw text. * @return text suitably escaped. */ protected String escape(String input) { return Text.encodeIllegalXMLCharacters(input); }
/** * Returns the singleton <code>TransientFileFactory</code> instance. */ public static TransientFileFactory getInstance() { synchronized (TransientFileFactory.class) { if (INSTANCE == null) { INSTANCE = new TransientFileFactory(); } return INSTANCE; } }
/** * Returns true if the specified character is invalid. * * @param c The character to check. */ public static boolean isInvalid(int c) { return !isValid(c); } // isInvalid(int):boolean
@Override public NodeIterator getNodes(String namePattern) throws RepositoryException { // Inspired by org.apache.jackrabbit.core.NodeImpl#getNodes(String) return ChildrenCollectorFilter.collectChildNodes(this, namePattern); }
/** * Replaces HTML characters in the given string that might need escaping * as HTML text or attribute * * @param text text to be escaped * @return a string */ public static String encodeIllegalHTMLCharacters(String text) { return encodeMarkupCharacters(text, true); }
public String generateRSS(Path indexFile) throws CorruptIndexException, IOException { StringBuffer output = new StringBuffer(); output.append(getRSSHeaders()); IndexSearcher searcher = null; try { reader = DirectoryReader.open(FSDirectory.open(indexFile)); searcher = new IndexSearcher(reader); GregorianCalendar gc = new java.util.GregorianCalendar(TimeZone.getDefault(), Locale.getDefault()); gc.setTime(new Date()); String nowDateTime = ISO8601.format(gc); gc.add(java.util.GregorianCalendar.MINUTE, -5); String fiveMinsAgo = ISO8601.format(gc); TermRangeQuery query = new TermRangeQuery( TikaCoreProperties.CREATED.getName(), new BytesRef(fiveMinsAgo), new BytesRef(nowDateTime), true, true); TopScoreDocCollector collector = TopScoreDocCollector.create(20); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; for (int i = 0; i < hits.length; i++) { Document doc = searcher.doc(hits[i].doc); output.append(getRSSItem(doc)); } } finally { if (reader != null) reader.close(); } output.append(getRSSFooters()); return output.toString(); }
protected String toSafeName(String key) { return ISO9075.encode(Text.escapeIllegalJcrChars(key)); }
/** * @param input ISO8601 string representation * @return Calendar value or null */ public static Calendar calendarFromString(String input) { if (input == null) { return null; } return ISO8601.parse(input); }
/** * Replace wildcards and return the expanded SQL statement. * * @param sql The SQL with embedded wildcards. * @return The SQL with no wildcards present. */ protected String createSchemaSql(String sql) { // replace prefix variable return Text.replace(sql, SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix); }
@Override @SuppressWarnings("unchecked") public T with(Node lockable, boolean isDeep, boolean isSessionScoped) throws RepositoryException, InterruptedException { return (T) super.with(lockable, isDeep, isSessionScoped); }
/** * Escapes input text suitable for the output format. * <p> * By default does XML-escaping. Can be overridden for * other formats. * * @param input raw text. * @return text suitably escaped. */ protected String escape(String input) { return Text.encodeIllegalXMLCharacters(input); }
/** * Replaces XML characters in the given string that might need escaping * as XML text or attribute * * @param text text to be escaped * @return a string */ public static String encodeIllegalXMLCharacters(String text) { return encodeMarkupCharacters(text, false); }