/** * Writes s String to the output stream.<p> * * @param s the String to write * @throws SAXException in case of I/O errors */ private void write(String s) throws SAXException { try { m_writer.write(s); } catch (IOException e) { throw new SAXException(Messages.get().getBundle().key(Messages.ERR_IOERROR_0), e); } }
/** * Writes s String to the output stream.<p> * * @param s the String to write * @throws SAXException in case of I/O errors */ private void write(String s) throws SAXException { try { m_writer.write(s); } catch (IOException e) { throw new SAXException(Messages.get().getBundle().key(Messages.ERR_IOERROR_0), e); } }
/** * Writes a linebreak to the output stream, also handles the indentation.<p> * * @throws SAXException in case of I/O errors */ private void writeNewLine() throws SAXException { try { // write new line m_writer.write("\r\n"); // write indentation for (int i = 1; i < m_indentLevel; i++) { m_writer.write(INDENT_STR); } // flush the stream m_writer.flush(); } catch (IOException e) { throw new SAXException(Messages.get().getBundle().key(Messages.ERR_IOERROR_0), e); } } }
/** * Writes a linebreak to the output stream, also handles the indentation.<p> * * @throws SAXException in case of I/O errors */ private void writeNewLine() throws SAXException { try { // write new line m_writer.write("\r\n"); // write indentation for (int i = 1; i < m_indentLevel; i++) { m_writer.write(INDENT_STR); } // flush the stream m_writer.flush(); } catch (IOException e) { throw new SAXException(Messages.get().getBundle().key(Messages.ERR_IOERROR_0), e); } } }
/** * Internal helper that throws a <code>{@link CmsRuntimeException}</code> if the * configuration of this instance has been frozen ({@link #setFrozen(boolean)}).<p> * * @throws CmsRuntimeException if the configuration of this instance has been frozen * ({@link #setFrozen(boolean)}) */ private void checkFrozen() throws CmsRuntimeException { if (m_frozen) { throw new CmsRuntimeException(Messages.get().container(Messages.ERR_FILE_VIEW_SETTINGS_FROZEN_0)); } }
/** * Internal helper that throws a <code>{@link CmsRuntimeException}</code> if the * configuration of this instance has been frozen ({@link #setFrozen(boolean)}).<p> * * @throws CmsRuntimeException if the configuration of this instance has been frozen * ({@link #setFrozen(boolean)}) */ private void checkFrozen() throws CmsRuntimeException { if (m_frozen) { throw new CmsRuntimeException(Messages.get().container(Messages.ERR_FILE_VIEW_SETTINGS_FROZEN_0)); } }
/** * Returns the Integer (int) value for the given String value.<p> * * All parse errors are caught and the given default value is returned in this case.<p> * * @param value the value to parse as int * @param defaultValue the default value in case of parsing errors * @param key a key to be included in the debug output in case of parse errors * * @return the int value for the given parameter value String */ public static int getIntValue(String value, int defaultValue, String key) { int result; try { result = Integer.valueOf(value).intValue(); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_PARSE_INT_2, value, key)); } result = defaultValue; } return result; }
/** * Returns the color value (<code>{@link Color}</code>) for the given String value.<p> * * All parse errors are caught and the given default value is returned in this case.<p> * * @param value the value to parse as color * @param defaultValue the default value in case of parsing errors * @param key a key to be included in the debug output in case of parse errors * * @return the int value for the given parameter value String */ public static Color getColorValue(String value, Color defaultValue, String key) { Color result; try { char pre = value.charAt(0); if (pre != '#') { value = "#" + value; } result = Color.decode(value); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_PARSE_COLOR_2, value, key)); } result = defaultValue; } return result; }
/** * * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) */ public void writeExternal(ObjectOutput out) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_WRITE_UUID_1, toString())); } out.writeObject(toString()); } }
/** * Returns the closest Integer (int) value for the given String value.<p> * * All parse errors are caught and the given default value is returned in this case.<p> * * @param value the value to parse as int, can also represent a float value * @param defaultValue the default value in case of parsing errors * @param key a key to be included in the debug output in case of parse errors * * @return the closest int value for the given parameter value String */ public static int getIntValueRounded(String value, int defaultValue, String key) { int result; try { result = Math.round(Float.parseFloat(value)); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_PARSE_INT_2, value, key)); } result = defaultValue; } return result; }
/** * Returns the Long (long) value for the given String value.<p> * * All parse errors are caught and the given default value is returned in this case.<p> * * @param value the value to parse as long * @param defaultValue the default value in case of parsing errors * @param key a key to be included in the debug output in case of parse errors * * @return the long value for the given parameter value String */ public static long getLongValue(String value, long defaultValue, String key) { long result; try { result = Long.valueOf(value).longValue(); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_PARSE_INT_2, value, key)); } result = defaultValue; } return result; }
/** * Returns the Integer (int) value for the given String value.<p> * * All parse errors are caught and the given default value is returned in this case.<p> * * @param value the value to parse as int * @param defaultValue the default value in case of parsing errors * @param key a key to be included in the debug output in case of parse errors * * @return the int value for the given parameter value String */ public static int getIntValue(String value, int defaultValue, String key) { int result; try { result = Integer.valueOf(value).intValue(); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_PARSE_INT_2, value, key)); } result = defaultValue; } return result; }
/** * Returns the color value (<code>{@link Color}</code>) for the given String value.<p> * * All parse errors are caught and the given default value is returned in this case.<p> * * @param value the value to parse as color * @param defaultValue the default value in case of parsing errors * @param key a key to be included in the debug output in case of parse errors * * @return the int value for the given parameter value String */ public static Color getColorValue(String value, Color defaultValue, String key) { Color result; try { char pre = value.charAt(0); if (pre != '#') { value = "#" + value; } result = Color.decode(value); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_PARSE_COLOR_2, value, key)); } result = defaultValue; } return result; }
/** * * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) */ public void writeExternal(ObjectOutput out) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_WRITE_UUID_1, toString())); } out.writeObject(toString()); } }
/** * Internally tidies with cleanup and XHTML.<p> * * @param content HTML to clean * * @return the tidy HTML */ private String tidy(final String content) { CmsHtmlConverter converter = new CmsHtmlConverter(CmsEncoder.ENCODING_UTF_8, new StringBuffer( CmsHtmlConverter.PARAM_WORD).append(";").append(CmsHtmlConverter.PARAM_XHTML).toString()); String result = content; try { result = converter.convertToString(content); } catch (UnsupportedEncodingException e) { // should never happen if (LOG.isWarnEnabled()) { LOG.warn(Messages.get().getBundle().key(Messages.LOG_WARN_TIDY_FAILURE_0), e); } } return result; } }
/** * Checks if all resources are present.<p> * * @param cms an initialized OpenCms user context which must have read access to all resources * @param resources a list of vfs resource names to check * * @throws CmsIllegalArgumentException in case not all resources exist or can be read with the given OpenCms user context */ public static void checkResources(CmsObject cms, List<String> resources) throws CmsIllegalArgumentException { StringBuffer result = new StringBuffer(128); ListIterator<String> it = resources.listIterator(); while (it.hasNext()) { String resourcePath = it.next(); try { CmsResource resource = cms.readResource(resourcePath); // append folder separator, if resource is a folder and does not and with a slash if (resource.isFolder() && !resourcePath.endsWith("/")) { it.set(resourcePath + "/"); } } catch (@SuppressWarnings("unused") CmsException e) { result.append(resourcePath); result.append('\n'); } } if (result.length() > 0) { throw new CmsIllegalArgumentException( Messages.get().container(Messages.ERR_MISSING_RESOURCES_1, result.toString())); } }
/** * Format an Object argument using this conversion * specification. * @param s the Object to format. * @return the formatted String. * @exception CmsIllegalArgumentException if the * conversion character is neither s nor S. */ String internalsprintf(Object s) throws CmsIllegalArgumentException { String s2 = ""; if ((m_conversionCharacter == 's') || (m_conversionCharacter == 'S')) { s2 = printSFormat(s.toString()); } else { throw new CmsIllegalArgumentException(Messages.get().container( Messages.ERR_INVALID_DOUBLE_FMT_CHAR_2, "String", new Character(m_conversionCharacter))); } return s2; }
/** * Format an Object argument using this conversion * specification. * @param s the Object to format. * @return the formatted String. * @exception CmsIllegalArgumentException if the * conversion character is neither s nor S. */ String internalsprintf(Object s) throws CmsIllegalArgumentException { String s2 = ""; if ((m_conversionCharacter == 's') || (m_conversionCharacter == 'S')) { s2 = printSFormat(s.toString()); } else { throw new CmsIllegalArgumentException( Messages.get().container( Messages.ERR_INVALID_DOUBLE_FMT_CHAR_2, "String", new Character(m_conversionCharacter))); } return s2; }
/** * Converts the given HTML code according to the settings of this converter.<p> * * If an any error occurs during the conversion process, the original input is returned unmodified.<p> * * @param htmlInput HTML input stored in an array of bytes * @return array of bytes containing the converted HTML */ public byte[] convertToByteSilent(byte[] htmlInput) { try { return convertToByte(htmlInput); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(Messages.get().getBundle().key(Messages.LOG_CONVERSION_BYTE_FAILED_0), e); } return htmlInput; } }
/** * Internally tidies with cleanup and XHTML.<p> * * @param content HTML to clean * * @return the tidy HTML */ private String tidy(final String content) { CmsHtmlConverter converter = new CmsHtmlConverter( CmsEncoder.ENCODING_UTF_8, new StringBuffer(CmsHtmlConverter.PARAM_WORD).append(";").append(CmsHtmlConverter.PARAM_XHTML).toString()); String result = content; try { result = converter.convertToString(content); } catch (UnsupportedEncodingException e) { // should never happen if (LOG.isWarnEnabled()) { LOG.warn(Messages.get().getBundle().key(Messages.LOG_WARN_TIDY_FAILURE_0), e); } } return result; } }