protected void validateActionDocument(String fileName, Element rootElement) { if (!Validator.equals(rootElement.getName(), "definition")) { throwValidationException(1000, fileName, rootElement); } List<Element> elements = rootElement.elements(); if (elements.isEmpty()) { throwValidationException(1001, fileName, rootElement, new String[] {"command"}); } for (Element element : elements) { String elementName = element.getName(); if (elementName.equals("command")) { String attributeValue = element.attributeValue("name"); if (attributeValue == null) { throwValidationException(1003, fileName, element, "name"); } else if (Validator.isNull(attributeValue)) { throwValidationException(1006, fileName, element, "name"); } validateActionCommandElement( fileName, element, new String[] {"execute"}, new String[] {"function"}, new String[0]); } else { throwValidationException(1002, fileName, element, elementName); } } }
protected void validateTestSuiteDocument(String fileName, Element rootElement) { if (!Validator.equals(rootElement.getName(), "definition")) { throwValidationException(1000, fileName, rootElement); } List<Element> elements = rootElement.elements(); if (elements.isEmpty()) { throwValidationException(1001, fileName, rootElement, new String[] {"execute"}); } for (Element element : elements) { String elementName = element.getName(); if (elementName.equals("execute")) { validateExecuteElement( fileName, element, new String[] {"test-case", "test-class", "test-suite"}, ".+", new String[0]); } else { throwValidationException(1002, fileName, element, elementName); } } }
protected void validateTestCaseDocument(String fileName, Element rootElement) { if (!Validator.equals(rootElement.getName(), "definition")) { throwValidationException(1000, fileName, rootElement); } List<Element> elements = rootElement.elements(); if (elements.isEmpty()) { throwValidationException(1001, fileName, rootElement, new String[] {"command"}); } for (Element element : elements) { String elementName = element.getName(); if (elementName.equals("command")) { String attributeValue = element.attributeValue("name"); if (attributeValue == null) { throwValidationException(1003, fileName, element, "name"); } else if (Validator.isNull(attributeValue)) { throwValidationException(1006, fileName, element, "name"); } validateBlockElement( fileName, element, new String[] {"execute", "var"}, new String[] {"action", "macro"}, new String[] {"var"}, new String[0]); } else if (elementName.equals("set-up") || elementName.equals("tear-down")) { List<Attribute> attributes = element.attributes(); for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("line-number")) { throwValidationException(1005, fileName, element, attributeName); } } validateBlockElement( fileName, element, new String[] {"execute", "var"}, new String[] {"action", "macro"}, new String[] {"var"}, new String[0]); } else if (elementName.equals("var")) { validateVarElement(fileName, element); } else { throwValidationException(1002, fileName, element, elementName); } } }
public static String exportReferencedContent( PortletDataContext portletDataContext, Element dlFileEntryTypesElement, Element dlFoldersElement, Element dlFileEntriesElement, Element dlFileRanksElement, Element dlRepositoriesElement, Element dlRepositoryEntriesElement, Element entityElement, String content) throws Exception { content = exportDLFileEntries( portletDataContext, dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement, dlRepositoryEntriesElement, entityElement, content, false); content = exportLayoutFriendlyURLs(portletDataContext, content); content = exportLinksToLayout(portletDataContext, content); String entityElementName = entityElement.getName(); if (!entityElementName.equals("article")) { content = StringUtil.replace(content, StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND); } return content; }
protected void validate(List<Element> children, Set<String> elNames) throws PortalException { for (Element el : children) { if (el.getName().equals("meta-data")) { continue; } String elName = el.attributeValue("name", StringPool.BLANK); String elType = el.attributeValue("type", StringPool.BLANK); if (Validator.isNull(elName) || elName.startsWith(JournalStructureConstants.RESERVED)) { throw new StructureXsdException(); } else { char[] c = elName.toCharArray(); for (int i = 0; i < c.length; i++) { if ((!Validator.isChar(c[i])) && (!Validator.isDigit(c[i])) && (c[i] != CharPool.DASH) && (c[i] != CharPool.UNDERLINE)) { throw new StructureXsdException(); } } String completePath = elName; Element parent = el.getParent(); while (!parent.isRootElement()) { completePath = parent.attributeValue("name", StringPool.BLANK) + StringPool.SLASH + completePath; parent = parent.getParent(); } String elNameLowerCase = completePath.toLowerCase(); if (elNames.contains(elNameLowerCase)) { throw new StructureXsdException(); } else { elNames.add(elNameLowerCase); } } if (Validator.isNull(elType)) { throw new StructureXsdException(); } validate(el.elements(), elNames); } }
protected void validatePathTrElement(String fileName, Element trElement) { List<Element> elements = trElement.elements(); for (Element element : elements) { String elementName = element.getName(); if (!elementName.equals("td")) { throwValidationException(1002, fileName, element, elementName); } } if (elements.size() < 3) { throwValidationException(1001, fileName, trElement, new String[] {"td"}); } if (elements.size() > 3) { Element element = elements.get(3); String elementName = element.getName(); throwValidationException(1002, fileName, element, elementName); } }
@Override public boolean validateReference(Element rootElement, Element referenceElement) { String elementName = referenceElement.getName(); if (elementName.equals("missing-reference")) { String uuid = referenceElement.attributeValue("uuid"); long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id")); return validateMissingReference(uuid, groupId); } return true; }
protected void validateBlockElement( String fileName, Element commandElement, String[] allowedBlockChildElementNames, String[] allowedExecuteAttributeNames, String[] allowedExecuteChildElementNames, String[] allowedIfConditionElementNames) { List<Element> elements = commandElement.elements(); if (elements.isEmpty()) { throwValidationException(1001, fileName, commandElement, allowedBlockChildElementNames); } for (Element element : elements) { String elementName = element.getName(); if (!ArrayUtil.contains(allowedBlockChildElementNames, elementName)) { throwValidationException(1002, fileName, element, elementName); } if (elementName.equals("echo") || elementName.equals("fail")) { validateSimpleElement(fileName, element, new String[] {"message"}); } else if (elementName.equals("execute")) { validateExecuteElement( fileName, element, allowedExecuteAttributeNames, ".+", allowedExecuteChildElementNames); } else if (elementName.equals("if")) { validateIfElement( fileName, element, allowedBlockChildElementNames, allowedExecuteAttributeNames, allowedExecuteChildElementNames, allowedIfConditionElementNames); } else if (elementName.equals("var")) { validateVarElement(fileName, element); } else if (elementName.equals("while")) { validateWhileElement( fileName, element, allowedBlockChildElementNames, allowedExecuteAttributeNames, allowedExecuteChildElementNames, allowedIfConditionElementNames); } else { throwValidationException(1002, fileName, element, elementName); } } }
protected void validateMacroDocument(String fileName, Element rootElement) { if (!Validator.equals(rootElement.getName(), "definition")) { throwValidationException(1000, fileName, rootElement); } List<Element> elements = rootElement.elements(); if (elements.isEmpty()) { throwValidationException(1001, fileName, rootElement, new String[] {"command", "var"}); } for (Element element : elements) { String elementName = element.getName(); if (elementName.equals("command")) { String attributeValue = element.attributeValue("name"); if (attributeValue == null) { throwValidationException(1003, fileName, element, "name"); } else if (Validator.isNull(attributeValue)) { throwValidationException(1006, fileName, element, "name"); } validateBlockElement( fileName, element, new String[] {"echo", "execute", "fail", "if", "var", "while"}, new String[] {"action", "macro"}, new String[] {"var"}, new String[] {"condition", "contains", "equals", "isset"}); } else if (elementName.equals("var")) { validateVarElement(fileName, element); } else { throwValidationException(1002, fileName, element, elementName); } } }
protected Map<String, Object> insertRequestVariables(Element element) { Map<String, Object> map = new HashMap<>(); if (element == null) { return map; } for (Element childElement : element.elements()) { String name = childElement.getName(); if (name.equals("attribute")) { Element nameElement = childElement.element("name"); Element valueElement = childElement.element("value"); map.put(nameElement.getText(), valueElement.getText()); } else if (name.equals("parameter")) { Element nameElement = childElement.element("name"); List<Element> valueElements = childElement.elements("value"); if (valueElements.size() == 1) { Element valueElement = valueElements.get(0); map.put(nameElement.getText(), valueElement.getText()); } else { List<String> values = new ArrayList<>(); for (Element valueElement : valueElements) { values.add(valueElement.getText()); } map.put(nameElement.getText(), values); } } else { List<Element> elements = childElement.elements(); if (!elements.isEmpty()) { map.put(name, insertRequestVariables(childElement)); } else { map.put(name, childElement.getText()); } } } return map; }
protected void validatePathDocument(String fileName, Element rootElement) { Element headElement = rootElement.element("head"); Element titleElement = headElement.element("title"); String title = titleElement.getText(); int x = fileName.lastIndexOf(StringPool.SLASH); int y = fileName.lastIndexOf(CharPool.PERIOD); String shortFileName = fileName.substring(x + 1, y); if ((title == null) || !shortFileName.equals(title)) { throwValidationException(0, fileName); } Element bodyElement = rootElement.element("body"); Element tableElement = bodyElement.element("table"); Element theadElement = tableElement.element("thead"); Element trElement = theadElement.element("tr"); Element tdElement = trElement.element("td"); String tdText = tdElement.getText(); if ((tdText == null) || !shortFileName.equals(tdText)) { throwValidationException(0, fileName); } Element tbodyElement = tableElement.element("tbody"); List<Element> elements = tbodyElement.elements(); for (Element element : elements) { String elementName = element.getName(); if (elementName.equals("tr")) { validatePathTrElement(fileName, element); } else { throwValidationException(1002, fileName, element, elementName); } } }
protected void validateSimpleElement( String fileName, Element element, String[] neededAttributes) { Map<String, Boolean> hasNeededAttributes = new HashMap<String, Boolean>(); for (String neededAttribute : neededAttributes) { hasNeededAttributes.put(neededAttribute, false); } List<Attribute> attributes = element.attributes(); for (Attribute attribute : attributes) { String attributeName = attribute.getName(); String attributeValue = attribute.getValue(); if (Validator.isNull(attributeValue)) { throwValidationException(1006, fileName, element, attributeName); } if (hasNeededAttributes.containsKey(attributeName)) { hasNeededAttributes.put(attributeName, true); } if (!attributeName.equals("line-number") && !hasNeededAttributes.containsKey(attributeName)) { throwValidationException(1005, fileName, element, attributeName); } } for (String neededAttribute : neededAttributes) { if (!hasNeededAttributes.get(neededAttribute)) { throwValidationException(1004, fileName, element, neededAttributes); } } List<Element> childElements = element.elements(); if (!childElements.isEmpty()) { Element childElement = childElements.get(0); String childElementName = childElement.getName(); throwValidationException(1002, fileName, childElement, childElementName); } }
protected void validateWhileElement( String fileName, Element whileElement, String[] allowedBlockChildElementNames, String[] allowedExecuteAttributeNames, String[] allowedExecuteChildElementNames, String[] allowedIfConditionElementNames) { List<Element> elements = whileElement.elements(); Set<String> elementNames = new HashSet<String>(); for (Element element : elements) { String elementName = element.getName(); elementNames.add(elementName); if (elementName.equals("condition")) { validateExecuteElement( fileName, element, allowedExecuteAttributeNames, ".*(is|Is).+", allowedExecuteChildElementNames); } else if (elementName.equals("then")) { validateBlockElement( fileName, element, allowedBlockChildElementNames, allowedExecuteAttributeNames, allowedExecuteChildElementNames, allowedIfConditionElementNames); } else { throwValidationException(1002, fileName, element, elementName); } } if (!elementNames.contains("condition") || !elementNames.contains("then")) { throwValidationException(1001, fileName, whileElement, new String[] {"condition", "then"}); } }
protected void populateSkinnyJournalArticle( SkinnyJournalArticle skinnyJournalArticle, Element parentElement) { List<Element> elements = parentElement.elements(); for (Element element : elements) { String elementName = element.getName(); if (elementName.equals("dynamic-element")) { Element dynamicElementElement = element.element("dynamic-content"); if (dynamicElementElement != null) { skinnyJournalArticle.addDynamicElement( element.attributeValue("name"), dynamicElementElement.getTextTrim()); } } else { populateSkinnyJournalArticle(skinnyJournalArticle, element); } } }
public List<Element> getAllChildElements(Element element, String elementName) { List<Element> allChildElements = new ArrayList<Element>(); List<Element> childElements = element.elements(); if (childElements.isEmpty()) { return allChildElements; } for (Element childElement : childElements) { String childElementName = childElement.getName(); if (childElementName.equals(elementName)) { allChildElements.add(childElement); } allChildElements.addAll(getAllChildElements(childElement, elementName)); } return allChildElements; }
protected void validateIfElement( String fileName, Element ifElement, String[] allowedBlockChildElementNames, String[] allowedExecuteAttributeNames, String[] allowedExecuteChildElementNames, String[] allowedIfConditionElementNames) { List<Element> elements = ifElement.elements(); Set<String> elementNames = new HashSet<String>(); boolean hasAllowedIfConditionElementNames = false; for (Element element : elements) { String elementName = element.getName(); elementNames.add(elementName); if (ArrayUtil.contains(allowedIfConditionElementNames, elementName)) { hasAllowedIfConditionElementNames = true; } if (elementName.equals("condition")) { validateExecuteElement( fileName, element, allowedExecuteAttributeNames, ".*(is|Is).+", allowedExecuteChildElementNames); } else if (elementName.equals("contains")) { validateSimpleElement(fileName, element, new String[] {"string", "substring"}); } else if (elementName.equals("else") || elementName.equals("then")) { validateBlockElement( fileName, element, allowedBlockChildElementNames, allowedExecuteAttributeNames, allowedExecuteChildElementNames, allowedIfConditionElementNames); } else if (elementName.equals("elseif")) { validateIfElement( fileName, element, allowedBlockChildElementNames, allowedExecuteAttributeNames, allowedExecuteChildElementNames, allowedIfConditionElementNames); } else if (elementName.equals("equals")) { validateSimpleElement(fileName, element, new String[] {"arg1", "arg2"}); } else if (elementName.equals("isset")) { validateSimpleElement(fileName, element, new String[] {"var"}); } else { throwValidationException(1002, fileName, element, elementName); } } if (!hasAllowedIfConditionElementNames) { throwValidationException(1001, fileName, ifElement, allowedIfConditionElementNames); } if (!elementNames.contains("then")) { throwValidationException(1001, fileName, ifElement, new String[] {"then"}); } }
protected void validateExecuteElement( String fileName, Element executeElement, String[] allowedExecuteAttributeNames, String allowedExecuteAttributeValuesRegex, String[] allowedExecuteChildElementNames) { boolean hasAllowedAttributeName = false; List<Attribute> attributes = executeElement.attributes(); for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (ArrayUtil.contains(allowedExecuteAttributeNames, attributeName)) { hasAllowedAttributeName = true; break; } } if (!hasAllowedAttributeName) { throwValidationException(1004, fileName, executeElement, allowedExecuteAttributeNames); } String action = executeElement.attributeValue("action"); String function = executeElement.attributeValue("function"); String macro = executeElement.attributeValue("macro"); String selenium = executeElement.attributeValue("selenium"); String testCase = executeElement.attributeValue("test-case"); String testClass = executeElement.attributeValue("test-class"); String testSuite = executeElement.attributeValue("test-suite"); if (action != null) { if (Validator.isNull(action) || !action.matches(allowedExecuteAttributeValuesRegex)) { throwValidationException(1006, fileName, executeElement, "action"); } for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("action") && !attributeName.equals("line-number") && !attributeName.startsWith("locator") && !attributeName.startsWith("locator-key") && !attributeName.startsWith("value")) { throwValidationException(1005, fileName, executeElement, attributeName); } if (attributeName.equals("locator") || attributeName.equals("locator-key") || attributeName.equals("value")) { throwValidationException(1005, fileName, executeElement, attributeName); } } } else if (function != null) { if (Validator.isNull(function) || !function.matches(allowedExecuteAttributeValuesRegex)) { throwValidationException(1006, fileName, executeElement, "function"); } for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("function") && !attributeName.equals("line-number") && !attributeName.startsWith("locator") && !attributeName.startsWith("value")) { throwValidationException(1005, fileName, executeElement, attributeName); } if (attributeName.equals("locator") || attributeName.equals("value")) { throwValidationException(1005, fileName, executeElement, attributeName); } } } else if (macro != null) { if (Validator.isNull(macro) || !macro.matches(allowedExecuteAttributeValuesRegex)) { throwValidationException(1006, fileName, executeElement, "macro"); } for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("macro") && !attributeName.equals("line-number")) { throwValidationException(1005, fileName, executeElement, attributeName); } } } else if (selenium != null) { if (Validator.isNull(selenium) || !selenium.matches(allowedExecuteAttributeValuesRegex)) { throwValidationException(1006, fileName, executeElement, "selenium"); } for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("argument1") && !attributeName.equals("argument2") && !attributeName.equals("line-number") && !attributeName.equals("selenium")) { throwValidationException(1005, fileName, executeElement, attributeName); } } } else if (testCase != null) { if (Validator.isNull(testCase) || !testCase.matches(allowedExecuteAttributeValuesRegex)) { throwValidationException(1006, fileName, executeElement, "test-case"); } for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("line-number") && !attributeName.equals("test-case")) { throwValidationException(1005, fileName, executeElement, attributeName); } } } else if (testClass != null) { if (Validator.isNull(testClass) || !testClass.matches(allowedExecuteAttributeValuesRegex)) { throwValidationException(1006, fileName, executeElement, "test-class"); } for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("line-number") && !attributeName.equals("test-class")) { throwValidationException(1005, fileName, executeElement, attributeName); } } } else if (testSuite != null) { if (Validator.isNull(testSuite) || !testSuite.matches(allowedExecuteAttributeValuesRegex)) { throwValidationException(1006, fileName, executeElement, "test-suite"); } for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!attributeName.equals("line-number") && !attributeName.equals("test-suite")) { throwValidationException(1005, fileName, executeElement, attributeName); } } } else { throwValidationException(0, fileName); } List<Element> elements = executeElement.elements(); if (allowedExecuteChildElementNames.length == 0) { if (!elements.isEmpty()) { Element element = elements.get(0); String elementName = element.getName(); throwValidationException(1002, fileName, element, elementName); } } else { String executeElementName = executeElement.getName(); for (Element element : elements) { String elementName = element.getName(); if (executeElementName.equals("condition")) { throwValidationException(1002, fileName, element, elementName); } if (elementName.equals("var")) { validateVarElement(fileName, element); } else { throwValidationException(1002, fileName, element, elementName); } } } }
protected void validateActionCommandElement( String fileName, Element commandElement, String[] allowedBlockChildElementNames, String[] allowedExecuteAttributeNames, String[] allowedExecuteChildElementNames) { List<Element> elements = commandElement.elements(); if (elements.isEmpty()) { throwValidationException(1001, fileName, commandElement, new String[] {"case", "default"}); } for (Element element : elements) { List<Element> childElements = element.elements(); String elementName = element.getName(); if (childElements.size() > 1) { throwValidationException(2000, fileName, childElements.get(1), elementName); } if (elementName.equals("case")) { List<Attribute> attributes = element.attributes(); boolean hasNeededAttributeName = false; for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (attributeName.equals("comparator")) { String attributeValue = attribute.getValue(); if (!attributeValue.equals("contains") && !attributeValue.equals("endsWith") && !attributeValue.equals("equals") && !attributeValue.equals("startsWith")) { throwValidationException(1006, fileName, element, attributeName); } } else if (attributeName.startsWith("locator") || attributeName.startsWith("locator-key")) { String attributeValue = attribute.getValue(); if (Validator.isNull(attributeValue)) { throwValidationException(1006, fileName, element, attributeName); } hasNeededAttributeName = true; } if (!attributeName.equals("comparator") && !attributeName.equals("line-number") && !attributeName.startsWith("locator") && !attributeName.startsWith("locator-key")) { throwValidationException(1005, fileName, element, attributeName); } if (attributeName.equals("locator") || attributeName.equals("locator-key")) { throwValidationException(1005, fileName, element, attributeName); } } if (!hasNeededAttributeName) { throwValidationException( 1004, fileName, element, new String[] {"locator1", "locator-key1"}); } validateBlockElement( fileName, element, new String[] {"execute"}, new String[] {"function"}, new String[0], new String[0]); } else if (elementName.equals("default")) { List<Attribute> attributes = element.attributes(); if (attributes.size() != 1) { Attribute attribute = attributes.get(1); String attributeName = attribute.getName(); throwValidationException(1005, fileName, element, attributeName); } validateBlockElement( fileName, element, new String[] {"execute"}, new String[] {"function"}, new String[0], new String[0]); } else { throwValidationException(1002, fileName, element, elementName); } } }
protected void validateVarElement(String fileName, Element element) { List<Attribute> attributes = element.attributes(); Map<String, String> attributeMap = new HashMap<String, String>(); for (Attribute attribute : attributes) { String attributeName = attribute.getName(); String attributeValue = attribute.getValue(); if (!attributeName.equals("value") && Validator.isNull(attributeValue)) { throwValidationException(1006, fileName, element, attributeName); } if (!_allowedVarAttributes.contains(attributeName)) { throwValidationException(1005, fileName, element, attributeName); } attributeMap.put(attributeName, attributeValue); } if (!attributeMap.containsKey("name")) { throwValidationException(1004, fileName, element, new String[] {"name"}); } else { String nameValue = attributeMap.get("name"); if (Validator.isNull(nameValue)) { throwValidationException(1006, fileName, element, "name"); } } String varText = element.getText(); if (Validator.isNull(varText) && !attributeMap.containsKey("locator-key") && !attributeMap.containsKey("path") && !attributeMap.containsKey("value")) { throwValidationException(1004, fileName, element, new String[] {"value"}); } if (!attributeMap.containsKey("value")) { String locatorKeyValue = attributeMap.get("locator-key"); String pathValue = attributeMap.get("path"); if (Validator.isNull(locatorKeyValue) && Validator.isNotNull(pathValue)) { throwValidationException(1004, fileName, element, new String[] {"locator-key"}); } if (Validator.isNotNull(locatorKeyValue) && Validator.isNull(pathValue)) { throwValidationException(1004, fileName, element, new String[] {"path"}); } } else { String varValue = attributeMap.get("value"); Pattern pattern = Pattern.compile("\\$\\{([^\\}]*?)\\}"); Matcher matcher = pattern.matcher(varValue); while (matcher.find()) { String statement = matcher.group(1); Pattern statementPattern = Pattern.compile("(.*)\\?(.*)\\(([^\\)]*?)\\)"); Matcher statementMatcher = statementPattern.matcher(statement); if (statementMatcher.find()) { String operand = statementMatcher.group(1); String method = statementMatcher.group(2); if (operand.equals("") || method.equals("")) { throwValidationException(1006, fileName, element, "value"); } if (!_methodNames.contains(method)) { throwValidationException(1013, fileName, element, method); } } else { if (statement.matches(".*[\\?\\(\\)\\}\\{].*")) { throwValidationException(1006, fileName, element, "value"); } } } } List<Element> childElements = element.elements(); if (!childElements.isEmpty()) { Element childElement = childElements.get(0); String childElementName = childElement.getName(); throwValidationException(1002, fileName, childElement, childElementName); } }
protected int doProcess(WebDAVRequest webDAVRequest) throws Exception { WebDAVStorage storage = webDAVRequest.getWebDAVStorage(); if (!storage.isSupportsClassTwo()) { return HttpServletResponse.SC_METHOD_NOT_ALLOWED; } HttpServletRequest request = webDAVRequest.getHttpServletRequest(); HttpServletResponse response = webDAVRequest.getHttpServletResponse(); Lock lock = null; Status status = null; String lockUuid = webDAVRequest.getLockUuid(); long timeout = WebDAVUtil.getTimeout(request); if (Validator.isNull(lockUuid)) { // Create new lock String owner = null; String xml = new String(FileUtil.getBytes(request.getInputStream())); if (Validator.isNotNull(xml)) { if (_log.isDebugEnabled()) { _log.debug("Request XML\n" + XMLFormatter.toString(xml)); } Document document = SAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); boolean exclusive = false; Element lockscopeElement = rootElement.element("lockscope"); for (Element element : lockscopeElement.elements()) { String name = GetterUtil.getString(element.getName()); if (name.equals("exclusive")) { exclusive = true; } } if (!exclusive) { return HttpServletResponse.SC_BAD_REQUEST; } Element ownerElement = rootElement.element("owner"); owner = ownerElement.getTextTrim(); if (Validator.isNull(owner)) { List<Element> hrefElements = ownerElement.elements("href"); for (Element hrefElement : hrefElements) { owner = "<D:href>" + hrefElement.getTextTrim() + "</D:href>"; } } } else { _log.error("Empty request XML"); return HttpServletResponse.SC_PRECONDITION_FAILED; } status = storage.lockResource(webDAVRequest, owner, timeout); lock = (Lock) status.getObject(); } else { try { // Refresh existing lock lock = storage.refreshResourceLock(webDAVRequest, lockUuid, timeout); status = new Status(HttpServletResponse.SC_OK); } catch (WebDAVException wde) { if (wde.getCause() instanceof NoSuchLockException) { return HttpServletResponse.SC_PRECONDITION_FAILED; } else { throw wde; } } } // Return lock details if (lock == null) { return status.getCode(); } long depth = WebDAVUtil.getDepth(request); String xml = getResponseXML(lock, depth); if (_log.isDebugEnabled()) { _log.debug("Response XML\n" + xml); } String lockToken = "<" + WebDAVUtil.TOKEN_PREFIX + lock.getUuid() + ">"; response.setContentType(ContentTypes.TEXT_XML_UTF8); response.setHeader("Lock-Token", lockToken); response.setStatus(status.getCode()); if (_log.isDebugEnabled()) { _log.debug("Returning lock token " + lockToken); } try { ServletResponseUtil.write(response, xml); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e); } } return status.getCode(); }