List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.doculibre.constellio.utils.connector.init.InitSolrConnectorHandler.java
License:Open Source License
@SuppressWarnings("unchecked") private void addCopyFields(Document schemaDocument, RecordCollection collection) { CopyFieldServices copyFieldServices = ConstellioSpringUtils.getCopyFieldServices(); EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); }// w w w.j a v a 2 s .c o m List<Element> dynamicFieldsElement = schemaDocument.getRootElement().elements("copyField"); for (Element elem : dynamicFieldsElement) { List<String> currentCopyField = new ArrayList<String>(); String source = elem.attributeValue("source"); currentCopyField.add(source); String destination = elem.attributeValue("dest"); currentCopyField.add(destination); String maxCharsString = elem.attributeValue("maxChars"); Integer maxChars = null; if (maxCharsString != null) { maxChars = Integer.valueOf(maxCharsString); } List<CopyField> newCopyFields = null; try { newCopyFields = copyFieldServices.newCopyFields(collection, source, destination, maxChars); for (CopyField newCopyField : newCopyFields) { copyFieldServices.makePersistent(newCopyField); } } catch (Exception e) { LOG.warn("CopyField associated with " + source + ", " + destination + " not added due to the following :"); LOG.warn(e.getMessage()); } } entityManager.getTransaction().commit(); }
From source file:com.doculibre.constellio.utils.izpack.UsersXmlFileUtils.java
License:Open Source License
@SuppressWarnings("unchecked") private static ConstellioUser toConstellioUser(Element element) { ConstellioUser constellioUser = new ConstellioUser(); constellioUser.setFirstName(element.attributeValue(FIRST_NAME)); constellioUser.setLastName(element.attributeValue(LAST_NAME)); constellioUser.setUsername(element.attributeValue(LOGIN)); constellioUser.setPasswordHash(element.attributeValue(PASSWORD_HASH)); Attribute locale = element.attribute(LOCALE); if (locale != null) { constellioUser.setLocaleCode(locale.getValue()); } else {//from w ww . j av a2s . c om constellioUser.setLocale(ConstellioSpringUtils.getDefaultLocale()); } Iterator<Element> rolesIt = element.elementIterator(ROLES); if (rolesIt != null) { Element roles = rolesIt.next(); for (Iterator<Element> it = roles.elementIterator(ROLE); it.hasNext();) { Element currentRole = it.next(); constellioUser.addRole(currentRole.attributeValue(VALUE)); } } return constellioUser; }
From source file:com.doculibre.constellio.utils.SolrSchemaUtils.java
License:Open Source License
public static IndexSchema getSchema(ConnectorType connectorType) { IndexSchema connectorTypeSchema;/*from w w w. j ava 2 s. c o m*/ String targetSchemaName; if (connectorType != null) { targetSchemaName = connectorType.getName(); } else { targetSchemaName = "constellio"; // Default } Resource[] classpathResources = ConstellioSpringUtils.getResources(SOLR_SCHEMA_PATTERN); if (classpathResources != null) { connectorTypeSchema = null; for (int i = 0; i < classpathResources.length; i++) { InputStream resourceInput = null; try { Resource resource = classpathResources[i]; resourceInput = resource.getInputStream(); Document schema = new SAXReader().read(resourceInput); Element schemaElement = schema.getRootElement(); String schemaName = schemaElement.attributeValue("name"); if (targetSchemaName.equals(schemaName)) { resourceInput = resource.getInputStream(); SolrConfig dummySolrConfig; URL dummySolrConfigURL = SolrSchemaUtils.class.getClassLoader() .getResource("config" + File.separator + "solrdefault" + File.separator); File dummySolrConfigDir = new File(dummySolrConfigURL.toURI()); File dummySolrConfigFile = new File(dummySolrConfigDir, "conf" + File.separator + "solrconfig.xml"); dummySolrConfig = new SolrConfig(dummySolrConfigDir.getPath(), dummySolrConfigFile.getPath(), null); connectorTypeSchema = new IndexSchema(dummySolrConfig, null, new InputSource(resourceInput)); break; } } catch (DocumentException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } finally { IOUtils.closeQuietly(resourceInput); } } } else { connectorTypeSchema = null; } return connectorTypeSchema; }
From source file:com.doculibre.constellio.utils.xml.SolrShemaXmlReader.java
License:Open Source License
private static Map<String, Map<String, String>> readFields(Document schemaDocument, Boolean readDynamicFields, Boolean checkTypes) {//w w w. j a v a2 s. co m Map<String, Map<String, String>> returnList = new HashMap<String, Map<String, String>>(); //AnalyzerClassServices analyzerClassServices = ConstellioSpringUtils.getAnalyzerClassServices(); FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices(); if (schemaDocument != null) { Element fieldsElement = schemaDocument.getRootElement().element("fields"); List<Element> fieldElements; if (readDynamicFields) { fieldElements = fieldsElement.elements("dynamicField"); } else { fieldElements = fieldsElement.elements("field"); } for (Iterator<Element> it = fieldElements.iterator(); it.hasNext();) { Element fieldElement = it.next(); if (checkTypes) { /*String analyzerClassName = fieldElement.attributeValue("analyzer"); if (analyzerClassName != null) { AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName); if (analyzerClass == null) { throw new RuntimeException("New Analyzers must be defined throught Constellio Interface"); } }*/ String typeName = fieldElement.attributeValue("type"); if (typeName == null) { throw new RuntimeException("A Field must have a type"); } FieldType fieldType = fieldTypeServices.get(typeName); if (fieldType == null) { throw new RuntimeException( "New Field type " + typeName + " must be defined throught Constellio Interface"); } } String fieldName = fieldElement.attributeValue("name"); if (fieldName == null) { throw new RuntimeException("A Field must have a name"); } List<Attribute> attributes = fieldElement.attributes(); Map<String, String> attributesToMap = new HashMap<String, String>(); for (Attribute att : attributes) { if (!att.getQualifiedName().equals("name")) { attributesToMap.put(att.getQualifiedName(), att.getValue()); } } returnList.put(fieldName, attributesToMap); } } return returnList; }
From source file:com.doculibre.constellio.utils.xml.SolrShemaXmlReader.java
License:Open Source License
public static List<List<String>> readCopyFields(Document schemaDocument) { List<List<String>> returnList = new ArrayList<List<String>>(); if (schemaDocument != null) { List<Element> dynamicFieldsElement = schemaDocument.getRootElement().elements("copyField"); for (Element elem : dynamicFieldsElement) { List<String> currentCopyField = new ArrayList<String>(); String source = elem.attributeValue("source"); currentCopyField.add(source); String destination = elem.attributeValue("dest"); currentCopyField.add(destination); String maxChars = elem.attributeValue("maxChars"); if (maxChars != null) { currentCopyField.add(maxChars); }//from ww w. j a v a 2 s . com returnList.add(currentCopyField); } } return returnList; }
From source file:com.doculibre.constellio.wicket.panels.results.DefaultSearchResultPanel.java
License:Open Source License
public DefaultSearchResultPanel(String id, SolrDocument doc, final SearchResultsDataProvider dataProvider) { super(id);// ww w. j a v a 2s .c o m RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); RecordServices recordServices = ConstellioSpringUtils.getRecordServices(); SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); String collectionName = dataProvider.getSimpleSearch().getCollectionName(); RecordCollection collection = collectionServices.get(collectionName); Record record = recordServices.get(doc); if (record != null) { SearchInterfaceConfig searchInterfaceConfig = searchInterfaceConfigServices.get(); IndexField uniqueKeyField = collection.getUniqueKeyIndexField(); IndexField defaultSearchField = collection.getDefaultSearchIndexField(); IndexField urlField = collection.getUrlIndexField(); IndexField titleField = collection.getTitleIndexField(); if (urlField == null) { urlField = uniqueKeyField; } if (titleField == null) { titleField = urlField; } final String recordURL = record.getUrl(); final String displayURL; if (record.getDisplayUrl().startsWith("/get?file=")) { HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest(); displayURL = ContextUrlUtils.getContextUrl(req) + record.getDisplayUrl(); } else { displayURL = record.getDisplayUrl(); } String title = record.getDisplayTitle(); final String protocol = StringUtils.substringBefore(displayURL, ":"); boolean linkEnabled = isLinkEnabled(protocol); // rcupration des champs highlight partir de la cl unique // du document, dans le cas de Nutch c'est l'URL QueryResponse response = dataProvider.getQueryResponse(); Map<String, Map<String, List<String>>> highlighting = response.getHighlighting(); Map<String, List<String>> fieldsHighlighting = highlighting.get(recordURL); String titleHighlight = getTitleFromHighlight(titleField.getName(), fieldsHighlighting); if (titleHighlight != null) { title = titleHighlight; } String excerpt = null; String description = getDescription(record); String summary = getSummary(record); if (StringUtils.isNotBlank(description) && searchInterfaceConfig.isDescriptionAsExcerpt()) { excerpt = description; } else { excerpt = getExcerptFromHighlight(defaultSearchField.getName(), fieldsHighlighting); if (excerpt == null) { excerpt = description; } } toggleSummaryLink = new WebMarkupContainer("toggleSummaryLink"); add(toggleSummaryLink); toggleSummaryLink.setVisible(StringUtils.isNotBlank(summary)); toggleSummaryLink.add(new AttributeModifier("onclick", new LoadableDetachableModel() { @Override protected Object load() { return "toggleSearchResultSummary('" + summaryLabel.getMarkupId() + "')"; } })); summaryLabel = new Label("summary", summary); add(summaryLabel); summaryLabel.setOutputMarkupId(true); summaryLabel.setVisible(StringUtils.isNotBlank(summary)); ExternalLink titleLink; if (displayURL.startsWith("file://")) { HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest(); String newDisplayURL = ContextUrlUtils.getContextUrl(req) + "app/getSmbFile?" + SmbServletPage.RECORD_ID + "=" + record.getId() + "&" + SmbServletPage.COLLECTION + "=" + collectionName; titleLink = new ExternalLink("titleLink", newDisplayURL); } else { titleLink = new ExternalLink("titleLink", displayURL); } final RecordModel recordModel = new RecordModel(record); AttributeModifier computeClickAttributeModifier = new AttributeModifier("onmousedown", true, new LoadableDetachableModel() { @Override protected Object load() { Record record = recordModel.getObject(); SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); WebRequest webRequest = (WebRequest) RequestCycle.get().getRequest(); HttpServletRequest httpRequest = webRequest.getHttpServletRequest(); return ComputeSearchResultClickServlet.getCallbackJavascript(httpRequest, simpleSearch, record); } }); titleLink.add(computeClickAttributeModifier); titleLink.setEnabled(linkEnabled); boolean resultsInNewWindow; PageParameters params = RequestCycle.get().getPageParameters(); if (params != null && params.getString(POPUP_LINK) != null) { resultsInNewWindow = params.getBoolean(POPUP_LINK); } else { resultsInNewWindow = searchInterfaceConfig.isResultsInNewWindow(); } titleLink.add(new SimpleAttributeModifier("target", resultsInNewWindow ? "_blank" : "_self")); // Add title title = StringUtils.remove(title, "\n"); title = StringUtils.remove(title, "\r"); if (StringUtils.isEmpty(title)) { title = StringUtils.defaultString(displayURL); title = StringUtils.substringAfterLast(title, "/"); title = StringUtils.substringBefore(title, "?"); try { title = URLDecoder.decode(title, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (title.length() > 120) { title = title.substring(0, 120) + " ..."; } } Label titleLabel = new Label("title", title); titleLink.add(titleLabel.setEscapeModelStrings(false)); add(titleLink); Label excerptLabel = new Label("excerpt", excerpt); add(excerptLabel.setEscapeModelStrings(false)); // add(new ExternalLink("url", url, // url).add(computeClickAttributeModifier).setEnabled(linkEnabled)); if (displayURL.startsWith("file://")) { // Creates a Windows path for file URLs String urlLabel = StringUtils.substringAfter(displayURL, "file:"); urlLabel = StringUtils.stripStart(urlLabel, "/"); urlLabel = "\\\\" + StringUtils.replace(urlLabel, "/", "\\"); try { urlLabel = URLDecoder.decode(urlLabel, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } add(new Label("url", urlLabel)); } else { add(new Label("url", displayURL)); } final ReloadableEntityModel<RecordCollection> collectionModel = new ReloadableEntityModel<RecordCollection>( collection); add(new ListView("searchResultFields", new LoadableDetachableModel() { @Override protected Object load() { RecordCollection collection = collectionModel.getObject(); return collection.getSearchResultFields(); } /** * Detaches from the current request. Implement this method with * custom behavior, such as setting the model object to null. */ protected void onDetach() { recordModel.detach(); collectionModel.detach(); } }) { @Override protected void populateItem(ListItem item) { SearchResultField searchResultField = (SearchResultField) item.getModelObject(); IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); Record record = recordModel.getObject(); IndexField indexField = searchResultField.getIndexField(); Locale locale = getLocale(); String indexFieldTitle = indexField.getTitle(locale); if (StringUtils.isBlank(indexFieldTitle)) { indexFieldTitle = indexField.getName(); } StringBuffer fieldValueSb = new StringBuffer(); List<Object> fieldValues = indexFieldServices.extractFieldValues(record, indexField); Map<String, String> defaultLabelledValues = indexFieldServices .getDefaultLabelledValues(indexField, locale); for (Object fieldValue : fieldValues) { if (fieldValueSb.length() > 0) { fieldValueSb.append("\n"); } String fieldValueLabel = indexField.getLabelledValue("" + fieldValue, locale); if (fieldValueLabel == null) { fieldValueLabel = defaultLabelledValues.get("" + fieldValue); } if (fieldValueLabel == null) { fieldValueLabel = "" + fieldValue; } fieldValueSb.append(fieldValueLabel); } item.add(new Label("indexField", indexFieldTitle)); item.add(new MultiLineLabel("indexFieldValue", fieldValueSb.toString())); item.setVisible(fieldValueSb.length() > 0); } @SuppressWarnings("unchecked") @Override public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { List<SearchResultField> searchResultFields = (List<SearchResultField>) getModelObject(); visible = !searchResultFields.isEmpty(); } return visible; } }); // md5 ConstellioSession session = ConstellioSession.get(); ConstellioUser user = session.getUser(); // TODO Provide access to unauthenticated users ? String md5 = ""; if (user != null) { IntelliGIDServiceInfo intelligidServiceInfo = ConstellioSpringUtils.getIntelliGIDServiceInfo(); if (intelligidServiceInfo != null) { Collection<Object> md5Coll = doc.getFieldValues(IndexField.MD5); if (md5Coll != null) { for (Object md5Obj : md5Coll) { try { String md5Str = new String(Hex.encodeHex(Base64.decodeBase64(md5Obj.toString()))); InputStream is = HttpClientHelper .get(intelligidServiceInfo.getIntelligidUrl() + "/connector/checksum", "md5=" + URLEncoder.encode(md5Str, "ISO-8859-1"), "username=" + URLEncoder.encode(user.getUsername(), "ISO-8859-1"), "password=" + URLEncoder.encode(Base64.encodeBase64String( ConstellioSession.get().getPassword().getBytes())), "ISO-8859-1"); try { Document xmlDocument = new SAXReader().read(is); Element root = xmlDocument.getRootElement(); for (Iterator<Element> it = root.elementIterator("fichier"); it.hasNext();) { Element fichier = it.next(); String url = fichier.attributeValue("url"); md5 += "<a href=\"" + url + "\">" + url + "</a> "; } } finally { IOUtils.closeQuietly(is); } } catch (Exception e) { e.printStackTrace(); } } } } } Label md5Label = new Label("md5", md5) { public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { visible = StringUtils.isNotBlank(this.getModelObjectAsString()); } return visible; } }; md5Label.setEscapeModelStrings(false); add(md5Label); add(new ElevatePanel("elevatePanel", record, dataProvider.getSimpleSearch())); } else { setVisible(false); } }
From source file:com.dp2345.service.impl.LogConfigServiceImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Cacheable("logConfig") public List<LogConfig> getAll() { try {/* w w w . j a v a2 s. c o m*/ File dp2345XmlFile = new ClassPathResource(CommonAttributes.DP2345_XML_PATH).getFile(); Document document = new SAXReader().read(dp2345XmlFile); List<org.dom4j.Element> elements = document.selectNodes("/dp2345/logConfig"); List<LogConfig> logConfigs = new ArrayList<LogConfig>(); for (org.dom4j.Element element : elements) { String operation = element.attributeValue("operation"); String urlPattern = element.attributeValue("urlPattern"); LogConfig logConfig = new LogConfig(); logConfig.setOperation(operation); logConfig.setUrlPattern(urlPattern); logConfigs.add(logConfig); } return logConfigs; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.dp2345.service.impl.TemplateServiceImpl.java
License:Open Source License
/** * ??/*from ww w . j a va2 s . c om*/ * * @param element * */ private Template getTemplate(Element element) { String id = element.attributeValue("id"); String type = element.attributeValue("type"); String name = element.attributeValue("name"); String templatePath = element.attributeValue("templatePath"); String staticPath = element.attributeValue("staticPath"); String description = element.attributeValue("description"); Template template = new Template(); template.setId(id); template.setType(Type.valueOf(type)); template.setName(name); template.setTemplatePath(templatePath); template.setStaticPath(staticPath); template.setDescription(description); return template; }
From source file:com.dp2345.util.SettingUtils.java
License:Open Source License
/** * ?//from w ww. ja v a 2 s . c o m * * @return */ public static Setting get() { Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); net.sf.ehcache.Element cacheElement = cache.get(Setting.CACHE_KEY); Setting setting; if (cacheElement != null) { setting = (Setting) cacheElement.getObjectValue(); } else { setting = new Setting(); try { File dp2345XmlFile = new ClassPathResource(CommonAttributes.DP2345_XML_PATH).getFile(); Document document = new SAXReader().read(dp2345XmlFile); List<Element> elements = document.selectNodes("/dp2345/setting"); for (Element element : elements) { String name = element.attributeValue("name"); String value = element.attributeValue("value"); try { beanUtils.setProperty(setting, name, value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } return setting; }
From source file:com.dp2345.util.SettingUtils.java
License:Open Source License
/** * /*from ww w . ja v a 2s .c om*/ * * @param setting * */ public static void set(Setting setting) { try { File dp2345XmlFile = new ClassPathResource(CommonAttributes.DP2345_XML_PATH).getFile(); Document document = new SAXReader().read(dp2345XmlFile); List<Element> elements = document.selectNodes("/dp2345/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(dp2345XmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }