Here you can find the source of getStylingHyphenFormat(String cssProperties)
Parameter | Description |
---|---|
cssProperties | a parameter |
public static String getStylingHyphenFormat(String cssProperties)
//package com.java2s; /******************************************************************************* * Copyright (c) 2008 Actuate Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w ww . ja va 2s . com * Actuate Corporation - initial API and implementation *******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { /** * Converts CSS properties to hyphen format. * * @param cssProperties * @return string format * @since 2.5.1 */ public static String getStylingHyphenFormat(String cssProperties) { if (cssProperties == null) { return null; } StringBuilder returnStr = new StringBuilder(); String[] properties = cssProperties.split(";"); //$NON-NLS-1$ if (properties == null || properties.length == 0) { return cssProperties; } for (int j = 0; j < properties.length; j++) { if (j != 0) { returnStr.append(";"); //$NON-NLS-1$ } String[] pair = properties[j].split(":");//$NON-NLS-1$ if (pair == null || pair.length <= 1) { returnStr.append(properties[j]).append(";");//$NON-NLS-1$ continue; } List<String> words = new ArrayList<String>(3); int begin = 0; int i = 0; for (; i < pair[0].length(); i++) { if (Character.isUpperCase(pair[0].charAt(i)) && i != 0) { words.add(pair[0].substring(begin, i).toLowerCase()); begin = i; } } if (begin != i) { words.add(pair[0].substring(begin, i).toLowerCase()); } StringBuilder sb = new StringBuilder(); i = 0; for (i = 0; i < words.size(); i++) { if (i != 0) { sb.append("-");//$NON-NLS-1$ } sb.append(words.get(i)); } returnStr.append(sb); for (i = 1; i < pair.length; i++) { returnStr.append(":").append(pair[i]);//$NON-NLS-1$ } } return returnStr.toString(); } }