private static List<String> getXPathValues(String xpathString, JXPathContext context) { List values = null; try { values = context.selectNodes(xpathString); } catch (RuntimeException e) { throw new RuntimeException("Error reading xpath " + xpathString, e); } List<String> ls = null; if (values == null) { ls = new ArrayList<String>(); } else { ls = new ArrayList<String>(values.size()); for (int i = 0; i < values.size(); i++) { Object value = values.get(i); String unwrappedValue = ""; if (value instanceof org.jdom2.Attribute) { unwrappedValue = ((org.jdom2.Attribute) value).getValue(); } else if (value instanceof org.jdom2.Element) { unwrappedValue = ((org.jdom2.Element) value).getValue(); } ls.add(unwrappedValue); } } return ls; } }
/** * {@inheritDoc} This implementation interprets the passed in key as an XPATH * expression. */ @Override public <T> List<QueryResult<T>> query(final T root, final String key, final NodeHandler<T> handler) { if (StringUtils.isEmpty(key)) { final QueryResult<T> result = createResult(root); return Collections.singletonList(result); } final JXPathContext context = createContext(root, handler); List<?> results = context.selectNodes(key); if (results == null) { results = Collections.emptyList(); } return convertResults(results); }
@SuppressWarnings("unchecked") public static synchronized ArrayList<Jr> getSubreports(Reports reports, String id, String format) { JXPathContext context = JXPathContext.newContext(reports); ArrayList<Jr> subReports = new ArrayList<Jr>(); subReports.addAll((ArrayList<Jr>) context.selectNodes("//jr[parent::media/parent::report/@id='" +id +"' and parent::media/@type='" +format +"' and @type='sr']")); return subReports; }
public static synchronized Translation getTranslation(Translations translations,String key) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(translations); StringBuffer sb = new StringBuffer(); sb.append("translation[@key='").append(key).append("']"); @SuppressWarnings("unchecked") List<Translation> listResult = (List<Translation>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Translation.class.getSimpleName()+" for key="+key);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Translation.class.getSimpleName()+" for key="+key);} return listResult.get(0); }
public static synchronized Lang getLang(Langs langs,String key) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(langs); StringBuffer sb = new StringBuffer(); sb.append("lang[@key='").append(key).append("']"); @SuppressWarnings("unchecked") List<Lang> listResult = (List<Lang>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Lang.class.getSimpleName()+" for key="+key);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Lang.class.getSimpleName()+" for key="+key);} return listResult.get(0); }
public static synchronized Description getDescription(Descriptions descriptions,String key) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(descriptions); StringBuffer sb = new StringBuffer(); sb.append("description[@key='").append(key).append("']"); @SuppressWarnings("unchecked") List<Description> listResult = (List<Description>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Description.class.getSimpleName()+" for key="+key);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Description.class.getSimpleName()+" for key="+key);} return listResult.get(0); }
public static synchronized Seed getSeed(Db dbSeed, String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(dbSeed); StringBuffer sb = new StringBuffer(); sb.append("seed[@code='"+code+"']"); @SuppressWarnings("unchecked") List<Seed> listResult = (List<Seed>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Seed.class.getSimpleName()+" for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Seed.class.getSimpleName()+" for code="+code);} return listResult.get(0); } }
public static synchronized MenuItem getMenuItem(Menu menu,String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(menu); StringBuffer sb = new StringBuffer(); sb.append("//menuItem[@code='").append(code).append("']"); @SuppressWarnings("unchecked") List<MenuItem> listResult = (List<MenuItem>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+MenuItem.class.getSimpleName()+" for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+MenuItem.class.getSimpleName()+" for code="+code);} return listResult.get(0); } }
public static synchronized Type getType(Types types,String key) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(types); StringBuffer sb = new StringBuffer(); sb.append("type[@key='").append(key).append("']"); @SuppressWarnings("unchecked") List<Type> listResult = (List<Type>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Type.class.getSimpleName()+" for key="+key);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Type.class.getSimpleName()+" for key="+key);} return listResult.get(0); }
public static synchronized RoleAutoAssign getAutoAssign(AclContainer aclContainer,String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(aclContainer); StringBuffer sb = new StringBuffer(); sb.append("roleAutoAssign[@code='").append(code).append("']"); @SuppressWarnings("unchecked") List<RoleAutoAssign> listResult = (List<RoleAutoAssign>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+RoleAutoAssign.class.getSimpleName()+" for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+RoleAutoAssign.class.getSimpleName()+" for code="+code);} return listResult.get(0); }
public static synchronized View getView(Access access, String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(access); StringBuffer sb = new StringBuffer(); sb.append("//view[@code='").append(code).append("']"); @SuppressWarnings("unchecked") List<View> listResult = (List<View>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+View.class.getSimpleName()+" for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+View.class.getSimpleName()+" for code="+code);} return listResult.get(0); } }
public static synchronized Finance getFinance(Figures figures,String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(figures); StringBuffer sb = new StringBuffer(); sb.append("finance[@code='").append(code).append("']"); @SuppressWarnings("unchecked") List<Finance> list = (List<Finance>)context.selectNodes(sb.toString()); if(list.size()==0){throw new ExlpXpathNotFoundException("No "+Finance.class.getSimpleName()+" for code="+code);} else if(list.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Finance.class.getSimpleName()+" for code="+code);} return list.get(0); } }
@SuppressWarnings("unchecked") public static synchronized Renderer getRenderer(Html html, String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(html); List<Renderer> listResult = (List<Renderer>)context.selectNodes("//renderer[@code='"+code+"']"); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Renderer.class.getSimpleName()+" found for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("No unique "+Renderer.class.getSimpleName()+" for code="+code);} return listResult.get(0); }
public static synchronized Template getTemplate(Mail mail, String lang, String type) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(mail); @SuppressWarnings("unchecked") List<Template> listResult = (List<Template>)context.selectNodes("template[@lang='"+lang+"' and @type='"+type+"']"); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Template.class.getSimpleName()+" for lang="+lang+" and type="+type);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Template.class.getSimpleName()+" for lang="+lang+" and type="+type);} return listResult.get(0); } }
public static synchronized Report getReport(Reports reports, String id) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(reports); @SuppressWarnings("unchecked") List<Report> listResult = (List<Report>)context.selectNodes("report[@id='"+id+"']"); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Report.class.getSimpleName()+" for id="+id);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Report.class.getSimpleName()+" for id="+id);} return listResult.get(0); }
public static synchronized Mail getMail(Mails mails, String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(mails); @SuppressWarnings("unchecked") List<Mail> listResult = (List<Mail>)context.selectNodes("mail[@code='"+code+"']"); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Mail.class.getSimpleName()+" for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Mail.class.getSimpleName()+" for code="+code);} return listResult.get(0); }
@SuppressWarnings("unchecked") public static synchronized Template getTemplate(Templates templates, String id) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(templates); List<Template> listResult = (List<Template>)context.selectNodes("//template[@id='" +id +"']"); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Template.class.getSimpleName()+" for id="+id);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Template.class.getSimpleName()+" for id="+id);} return listResult.get(0); }
public static Status getStatus(List<Status> list, String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { Aht aht = new Aht(); aht.getStatus().addAll(list); JXPathContext context = JXPathContext.newContext(aht); StringBuffer sb = new StringBuffer(); sb.append("status[@code='").append(code).append("']"); @SuppressWarnings("unchecked") List<Status> listResult = (List<Status>)context.selectNodes(sb.toString()); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Status.class.getSimpleName()+" for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Status.class.getSimpleName()+" for code="+code);} return listResult.get(0); }
@SuppressWarnings("unchecked") public static synchronized File getFile(Dir dirs, String code) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { JXPathContext context = JXPathContext.newContext(dirs); List<File> listResult = (List<File>)context.selectNodes("//file[@code='"+code+"']"); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No file found for code="+code);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("No unique file for code="+code);} return listResult.get(0); } }
public static synchronized Media getMedia(List<Media> list, String type) throws ExlpXpathNotFoundException, ExlpXpathNotUniqueException { Report report = new Report(); report.getMedia().addAll(list); JXPathContext context = JXPathContext.newContext(report); @SuppressWarnings("unchecked") List<Media> listResult = (List<Media>)context.selectNodes("media[@type='"+type+"']"); if(listResult.size()==0){throw new ExlpXpathNotFoundException("No "+Media.class.getSimpleName()+" for type="+type);} else if(listResult.size()>1){throw new ExlpXpathNotUniqueException("Multiple "+Media.class.getSimpleName()+" for type="+type);} return listResult.get(0); }