List of usage examples for org.jdom2 Element getTextTrim
public String getTextTrim()
From source file:org.jreserve.gui.wrapper.jdom.JDomUtil.java
License:Open Source License
private static String getNonEmptyString(Element element) throws IOException { String str = element.getTextTrim(); if (str == null || str.length() == 0) { String msg = "Value not set at '%s'!"; throw new IOException(String.format(msg, getPath(element))); }// w w w . j a v a 2 s.co m return str; }
From source file:org.mycore.datamodel.ifs.MCRSimpleContentStoreSelector.java
License:Open Source License
public MCRSimpleContentStoreSelector() { MCRConfiguration config = MCRConfiguration.instance(); String file = config.getString("MCR.IFS.ContentStoreSelector.ConfigFile"); Element xml = MCRURIResolver.instance().resolve("resource:" + file); if (xml == null) { throw new MCRConfigurationException("Could not load configuration file from resource:" + file); }//from w w w . j av a2s.co m typeStoreMap = new HashMap<>(); List<Element> stores = xml.getChildren("store"); storeIDs = new String[stores.size() + 1]; for (int i = 0; i < stores.size(); i++) { Element store = (Element) stores.get(i); String storeID = store.getAttributeValue("ID"); storeIDs[i] = storeID; List<Element> types = store.getChildren(); for (Object type1 : types) { Element type = (Element) type1; String typeID = type.getTextTrim(); typeStoreMap.put(typeID, storeID); } } defaultID = xml.getAttributeValue("default"); // NOTE: if defaultID is listed as a <store> it's inserted twice here storeIDs[storeIDs.length - 1] = defaultID; }
From source file:org.mycore.datamodel.ifs.MCRSimpleFCTDetector.java
License:Open Source License
/** * Adds a detection rule from the file content type definition XML file. The * detector parses the <rules> element provided with each content type * in the file content types XML definition. * /*from ww w .j a va 2s . com*/ * @param type * the file content type the rule is for * @param xRules * the rules XML element containing the rules for detecting that * type */ public void addRule(MCRFileContentType type, Element xRules) { Vector rules = new Vector(); rulesTable.put(type, rules); typesList.add(type); try { List extensions = xRules.getChildren("extension"); for (Object extension : extensions) { Element elem = (Element) extension; double score = elem.getAttribute("score").getDoubleValue(); String ext = elem.getTextTrim(); rules.addElement(new MCRExtensionRule(ext, score)); } List patterns = xRules.getChildren("pattern"); for (Object pattern1 : patterns) { Element elem = (Element) pattern1; double score = elem.getAttribute("score").getDoubleValue(); int offset = elem.getAttribute("offset").getIntValue(); String format = elem.getAttributeValue("format"); String pattern = elem.getTextTrim(); rules.addElement(new MCRPatternRule(pattern, format, offset, score)); } List doctypes = xRules.getChildren("doctype"); for (Object doctype1 : doctypes) { Element elem = (Element) doctype1; double score = elem.getAttribute("score").getDoubleValue(); String doctype = elem.getTextTrim(); rules.addElement(new MCRDoctypeRule(doctype, score)); } List strings = xRules.getChildren("string"); for (Object string1 : strings) { Element elem = (Element) string1; double score = elem.getAttribute("score").getDoubleValue(); String string = elem.getTextTrim(); rules.addElement(new MCRStringRule(string, score)); } } catch (Exception exc) { String msg = "Error parsing detection rules for file content type " + type.getLabel(); throw new MCRConfigurationException(msg, exc); } }
From source file:org.mycore.datamodel.metadata.MCRMetaBoolean.java
License:Open Source License
/** * This method read the XML input stream part from a DOM part for the * metadata of the document./*w w w . j ava 2 s .c o m*/ * * @param element * a relevant JDOM element for the metadata */ @Override public void setFromDOM(org.jdom2.Element element) { super.setFromDOM(element); setValue(element.getTextTrim()); }
From source file:org.mycore.datamodel.metadata.MCRMetaISO8601Date.java
License:Open Source License
@Override public void setFromDOM(org.jdom2.Element element) { super.setFromDOM(element); setFormat(element.getAttributeValue("format")); setDate(element.getTextTrim()); export = (Element) element.clone(); }
From source file:org.mycore.datamodel.metadata.MCRMetaNumber.java
License:Open Source License
/** * This method read the XML input stream part from a DOM part for the * metadata of the document.//from ww w . j a v a2 s. c om * * @param element * a relevant JDOM element for the metadata */ @Override public final void setFromDOM(org.jdom2.Element element) { super.setFromDOM(element); setMeasurement(element.getAttributeValue("measurement")); setDimension(element.getAttributeValue("dimension")); setNumber(element.getTextTrim()); }
From source file:org.mycore.datamodel.metadata.validator.MCREditorOutValidator.java
License:Open Source License
public static String checkMetaObjectWithLangNotEmpty(Element datasubtag, Class<? extends MCRMetaInterface> metaClass) { String text = datasubtag.getTextTrim(); if (text == null || text.length() == 0) { return "Element " + datasubtag.getName() + " has no text."; }/* w w w. ja va2s . c om*/ return checkMetaObjectWithLang(datasubtag, metaClass); }
From source file:org.mycore.mir.authorization.accesskeys.MIRAccessKeyServlet.java
License:Open Source License
@Override protected void doGetPost(MCRServletJob job) throws Exception { HttpServletRequest req = job.getRequest(); HttpServletResponse res = job.getResponse(); final MCRUserInformation userInfo = MCRSessionMgr.getCurrentSession().getUserInformation(); if (userInfo.equals(MCRSystemUserInformation.getGuestInstance())) { res.sendError(HttpServletResponse.SC_FORBIDDEN, "Access can only be granted to personalized users"); return;/*from www. ja va 2s .co m*/ } final Document doc = (Document) (job.getRequest().getAttribute("MCRXEditorSubmission")); if (doc == null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } final String action = req.getParameter("action"); final Element xml = doc.getRootElement(); final String objId = xml.getAttributeValue("objId"); final MCRObjectID mcrObjId = MCRObjectID.getInstance(objId); if (action == null) { final String accessKey = xml.getTextTrim(); String message = checkAccessKey(mcrObjId, accessKey); if (message != null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, message); return; } final MIRAccessKeyPair accKP = MIRAccessKeyManager.getKeyPair(mcrObjId); if (accessKey.equals(accKP.getReadKey())) MIRAccessKeyManager.addAccessKey(mcrObjId, accessKey); else if (accessKey.equals(accKP.getWriteKey())) MIRAccessKeyManager.addAccessKey(mcrObjId, accessKey); } else if ("create".equals(action)) { if (!MCRAccessManager.checkPermission(mcrObjId, PERMISSION_WRITE)) { throw MCRAccessException.missingPermission("Add access key to object.", mcrObjId.toString(), PERMISSION_WRITE); } final MIRAccessKeyPair accKP = MIRAccessKeyPairTransformer.buildAccessKeyPair(xml); MIRAccessKeyManager.createKeyPair(accKP); } else if ("edit".equals(action)) { if (!MCRAccessManager.checkPermission(mcrObjId, PERMISSION_WRITE)) { throw MCRAccessException.missingPermission("Update access key on object.", mcrObjId.toString(), PERMISSION_WRITE); } final MIRAccessKeyPair accKP = MIRAccessKeyPairTransformer.buildAccessKeyPair(xml); MIRAccessKeyManager.updateKeyPair(accKP); } else if ("delete".equals(action)) { if (!MCRAccessManager.checkPermission(mcrObjId, PERMISSION_WRITE)) { throw MCRAccessException.missingPermission("Delete access key on object.", mcrObjId.toString(), PERMISSION_WRITE); } MIRAccessKeyManager.deleteKeyPair(mcrObjId); } else { res.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } res.sendRedirect(getReturnURL(req)); }
From source file:org.mycore.mir.wizard.command.MIRWizardDownloadDBLib.java
License:Open Source License
@Override public void doExecute() { Element library = getInputXML().getChild("database").getChild("library"); if (library != null && library.getChildren().size() > 0) { String libDir = MCRConfigurationDir.getConfigurationDirectory().getAbsolutePath() + File.separator + "lib"; boolean success = true; for (Element lib : library.getChildren()) { String url = lib.getTextTrim(); String fname = FilenameUtils.getName(url); try { File file = new File(libDir + File.separator + fname); FileUtils.copyURLToFile(new URL(url), file); loadLib(file.toURI().toURL()); success = true;//from w w w .jav a 2 s .c om } catch (Exception ex) { ex.printStackTrace(); success = false; } if (success) { this.result.setAttribute("lib", fname); this.result.setAttribute("url", url); this.result.setAttribute("to", libDir); break; } } this.result.setSuccess(success); } }
From source file:org.mycore.mir.wizard.command.MIRWizardMCRCommand.java
License:Open Source License
@Override public void doExecute() { Session currentSession = MCRHIBConnection.instance().getSession(); try {/* w ww . j av a2s. c om*/ for (Element command : getInputXML().getChildren()) { String cmd = command.getTextTrim(); cmd = cmd.replaceAll("\n", "").replaceAll("\r", "").replaceAll(" ", " "); cmd = cmd.replaceAll(" ", " "); for (Attribute attr : command.getAttributes()) { if (attr.getValue().startsWith("resource:")) { File tmpFile = File.createTempFile("resfile", ".xml"); MCRContent source = new MCRJDOMContent(MCRURIResolver.instance().resolve(attr.getValue())); source.sendTo(tmpFile); cmd = cmd.replace("{" + attr.getName() + "}", tmpFile.getAbsolutePath()); } else { cmd = cmd.replace("{" + attr.getName() + "}", attr.getValue()); } } MCRCommandManager mcrCmdMgr = new MCRCommandManager(); Transaction tx = currentSession.beginTransaction(); try { mcrCmdMgr.invokeCommand(cmd); tx.commit(); } catch (HibernateException e) { tx.rollback(); this.result.setResult(result + e.toString()); this.result.setSuccess(false); return; } catch (InvocationTargetException e) { e.printStackTrace(); this.result.setResult(result + e.toString()); this.result.setSuccess(false); return; } } this.result.setSuccess(true); } catch (Exception ex) { ex.printStackTrace(); this.result.setResult(ex.toString()); this.result.setSuccess(false); } }