/** * Returns a string representation of the ResourceKey based on the pieces that are passed as parameters * * @param schema the string representation of the schema * @param identifier the string representation of the identifier * @param factoryParameters the set of factory parameters (<code>null</code> allowed) * @return the string version with the pieces delimited and concatenated */ public static String createStringResourceKey( final String schema, final String identifier, final Map factoryParameters ) { final String factoryParamString = convertFactoryParametersToString( factoryParameters ); final CSVQuoter quoter = new CSVQuoter( ';' ); return quoter.doQuoting( SERIALIZATION_PREFIX + schema ) + DELIMITER + quoter.doQuoting( identifier ) + ( factoryParamString == null ? "" : DELIMITER + quoter.doQuoting( factoryParamString ) ); }
/** * A streaming version of the quoting algorithm for more performance. Encodes the string, so that the string can * safely be used in CSV files. If the string does not need quoting, the original string is returned unchanged. * * @param original the unquoted string. * @param writer the writer. * @throws IOException if an IO error occured. */ public void doQuoting( final String original, final Writer writer ) throws IOException { if ( isQuotingNeeded( original ) ) { writer.write( quate ); applyQuote( writer, original ); writer.write( quate ); } else { writer.write( original ); } }
quoter = new CSVQuoter( separator.charAt( 0 ) ); final RenderBox content = contentProducer.getContent( row, col ); if ( content == null ) { writer.print( quoter.getSeparator() ); continue; if ( content.getX() != colPos || ( content.getY() + contentOffset ) != rowPos ) { writer.print( quoter.getSeparator() ); continue; quoter.doQuoting( formattedtext, writer ); if ( col < lastColumn ) { writer.print( quoter.getSeparator() );
public CsvTemplateProducer( final OutputProcessorMetaData metaData, final SheetLayout sheetLayout, final String encoding ) { this.metaData = metaData; this.sheetLayout = sheetLayout; this.encoding = encoding; this.idMapping = new HashMap<InstanceID, String>(); final String separator = metaData.getConfiguration().getConfigProperty( CSVTableModule.SEPARATOR, CSVTableModule.SEPARATOR_DEFAULT ); if ( separator.length() == 0 ) { throw new IllegalArgumentException( "CSV separate cannot be an empty string." ); } if ( this.encoding == null ) { this.encoding = metaData.getConfiguration().getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.csv.Encoding", EncodingRegistry.getPlatformDefaultEncoding() ); } quoter = new CSVQuoter( separator.charAt( 0 ) ); }
protected void inspectElement( final ReportElement element ) { String uuid = idMapping.get( element.getObjectID() ); if ( uuid == null ) { return; } if ( element.getComputedStyle().getBooleanStyleProperty( ElementStyleKeys.VISIBLE ) == false ) { return; } if ( textExtractor == null ) { textExtractor = new FastTextExtractor(); } try { textExtractor.compute( element, getRuntime() ); String text = textExtractor.getText(); if ( StringUtils.isEmpty( text ) == false ) { values.put( uuid, csvQuoter.doQuoting( text ) ); } } catch ( ContentProcessingException rse ) { throw new InvalidReportStateException( rse ); } } }
/** * Decodes the string, so that all escape sequences get removed. If the string was not quoted, then the string is * returned unchanged. * * @param nativeString the quoted string. * @return The unquoted string. */ public String undoQuoting( final String nativeString ) { if ( isQuotingNeeded( nativeString ) ) { final StringBuilder b = new StringBuilder( nativeString.length() ); final int length = nativeString.length() - 1; int start = 1; int pos = start; while ( pos != -1 ) { pos = nativeString.indexOf( doubleQuate, start ); if ( pos == -1 ) { b.append( nativeString.substring( start, length ) ); } else { b.append( nativeString.substring( start, pos ) ); start = pos + 1; } } return b.toString(); } else { return nativeString; } }
final RenderBox content = contentProducer.getContent( row, col ); if ( content == null ) { writer.print( quoter.getSeparator() ); continue; writer.print( quoter.getSeparator() ); continue; writer.write( formattedtext ); if ( col < lastColumn ) { writer.print( quoter.getSeparator() );
if (isQuotingNeeded(nativeString))
final CSVQuoter innerQuoter = new CSVQuoter( '=' ); final CSVQuoter quoter = new CSVQuoter( ':' ); final StringBuilder sb = new StringBuilder(); for ( Iterator iterator = factoryParameters.keySet().iterator(); iterator.hasNext(); ) { if ( key instanceof FactoryParameterKey ) { final FactoryParameterKey fkey = (FactoryParameterKey) key; entrySb.append( innerQuoter.doQuoting( "f:" + fkey.getName() ) ); } else if ( key instanceof LoaderParameterKey ) { final LoaderParameterKey fkey = (LoaderParameterKey) key; entrySb.append( innerQuoter.doQuoting( "l:" + fkey.getName() ) ); } else { throw new IllegalArgumentException( String.valueOf( key ) ); if ( value != null ) { entrySb.append( innerQuoter.doQuoting( String.valueOf( value ) ) ); sb.append( quoter.doQuoting( entrySb.toString() ) );
/** * A streaming version of the quoting algorithm for more performance. Encodes the string, so that the string can * safely be used in CSV files. If the string does not need quoting, the original string is returned unchanged. * * @param original the unquoted string. * @param writer the writer. * @throws IOException if an IO error occured. */ public void doQuoting (final String original, final Writer writer) throws IOException { if (isQuotingNeeded(original)) { writer.write(quate); applyQuote(writer, original); writer.write(quate); } else { writer.write(original); } }
/** * Encodes the string, so that the string can safely be used in CSV files. If the string does not need quoting, the * original string is returned unchanged. * * @param original the unquoted string. * @return The quoted string */ public String doQuoting( final String original ) { if ( forceQuote || isQuotingNeeded( original ) ) { final StringBuffer retval = new StringBuffer( original.length() + 5 ); // a safe guess most of the time. retval.append( quate ); applyQuote( retval, original ); retval.append( quate ); return retval.toString(); } else { return original; } }
/** * Encodes the string, so that the string can safely be used in CSV files. If the string * does not need quoting, the original string is returned unchanged. * * @param original the unquoted string. * @return The quoted string */ public String doQuoting (final String original) { if (isQuotingNeeded(original)) { final StringBuffer retval = new StringBuffer(original.length() + 5); // a safe guess most of the time. retval.append(quate); applyQuote(retval, original); retval.append(quate); return retval.toString(); } else { return original; } }