/** * checks whether style with styleID exist * * @param styleID styleID of the Style in the style-Document * @return true if style exist, false if style not exist */ public boolean styleExist(String styleID) { for (XWPFStyle style : listStyle) { if (style.getStyleId().equals(styleID)) return true; } return false; }
/** * Get style by a styleID * * @param styleID styleID of the searched style * @return style */ public XWPFStyle getStyle(String styleID) { for (XWPFStyle style : listStyle) { try { if (style.getStyleId().equals(styleID)) return style; } catch (NullPointerException e) { // Ignore NPE } } return null; }
@SuppressWarnings("unchecked") private Map<String, String> mergeStyles(NiceXWPFDocument docMerge){ Map<String, String> styleIdsMap = new HashMap<String, String>(); XWPFStyles styles = this.getStyles(); if (null == styles) styles = createStyles(); XWPFStyles stylesMerge = docMerge.getStyles(); if (null == stylesMerge) return styleIdsMap; try { Field listStyleField = XWPFStyles.class.getDeclaredField("listStyle"); listStyleField.setAccessible(true); List<XWPFStyle> lists = (List<XWPFStyle>)listStyleField.get(stylesMerge); for (XWPFStyle xwpfStyle : lists) { if (styles.styleExist(xwpfStyle.getStyleId())) { String id = xwpfStyle.getStyleId(); xwpfStyle.setStyleId(UUID.randomUUID().toString()); styleIdsMap.put(id, xwpfStyle.getStyleId()); } styles.addStyle(xwpfStyle); } } catch (Exception e) { LOG.error("merge style error", e); } return styleIdsMap; }
/** * checks whether style with styleID exist * * @param styleID styleID of the Style in the style-Document * @return true if style exist, false if style not exist */ public boolean styleExist(String styleID) { for (XWPFStyle style : listStyle) { if (style.getStyleId().equals(styleID)) return true; } return false; }
/** *get style by a styleID * @param styleID styleID of the searched style * @return style */ public XWPFStyle getStyle(String styleID){ for (XWPFStyle style : listStyle) { if(style.getStyleId().equals(styleID)) return style; } return null; }
/** * checks whether style with styleID exist * @param styleID styleID of the Style in the style-Document * @return true if style exist, false if style not exist */ public boolean styleExist(String styleID){ for (XWPFStyle style : listStyle) { if (style.getStyleId().equals(styleID)) return true; } return false; } /**
/** * Get style by a styleID * * @param styleID styleID of the searched style * @return style */ public XWPFStyle getStyle(String styleID) { for (XWPFStyle style : listStyle) { try { if (style.getStyleId().equals(styleID)) return style; } catch (NullPointerException e) { // Ignore NPE } } return null; }