List of usage examples for org.dom4j QName equals
public boolean equals(Object object)
From source file:com.zimbra.cs.dav.caldav.Filter.java
License:Open Source License
protected void parse(Element elem) { for (Object o : elem.elements()) { if (o instanceof Element) { Element e = (Element) o; QName name = e.getQName(); if (canHaveCompFilter() && name.equals(DavElements.E_COMP_FILTER)) mComps.add(new CompFilter(e)); else if (canHavePropFilter() && name.equals(DavElements.E_PROP_FILTER)) mProps.add(new PropFilter(e)); else if (canHaveParamFilter() && name.equals(DavElements.E_PARAM_FILTER)) mParams.add(new ParamFilter(e)); else if (name.equals(DavElements.E_TEXT_MATCH)) mTextMatches.add(new TextMatch(e)); else if (name.equals(DavElements.E_TIME_RANGE)) mTimeRange = new TimeRange(e); else if (name.equals(DavElements.E_IS_NOT_DEFINED)) mIsNotDefinedSet = true; else//from www .j a va2s. co m ZimbraLog.dav.info("unrecognized filter " + name.getNamespaceURI() + ":" + name.getName()); } } }
From source file:com.zimbra.cs.dav.carddav.Filter.java
License:Open Source License
protected void parse(Element elem) { for (Object o : elem.elements()) { if (o instanceof Element) { Element e = (Element) o; QName name = e.getQName(); if (canHavePropFilter() && name.equals(DavElements.CardDav.E_PROP_FILTER)) mProps.add(new PropFilter(e)); else if (canHaveParamFilter() && name.equals(DavElements.CardDav.E_PARAM_FILTER)) mParams.add(new ParamFilter(e, this)); else if (name.equals(DavElements.CardDav.E_TEXT_MATCH)) mTextMatch = new TextMatch(e, this); else if (name.equals(DavElements.CardDav.E_IS_NOT_DEFINED)) mIsNotDefinedSet = true; else/* ww w.j a va2s. c om*/ ZimbraLog.dav.info("unrecognized filter " + name.getNamespaceURI() + ":" + name.getName()); } } }
From source file:com.zimbra.cs.dav.resource.MailItemResource.java
License:Open Source License
@Override public void patchProperties(DavContext ctxt, java.util.Collection<Element> set, java.util.Collection<QName> remove) throws DavException, IOException { List<QName> reqProps = new ArrayList<QName>(); for (QName n : remove) { mDeadProps.remove(n);//w w w . j a v a 2 s.c om reqProps.add(n); } for (Element e : set) { QName name = e.getQName(); if (name.equals(DavElements.E_DISPLAYNAME) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) { // rename folder try { String val = e.getText(); String uri = getUri(); Mailbox mbox = getMailbox(ctxt); mbox.rename(ctxt.getOperationContext(), mId, type, val, mFolderId); setProperty(DavElements.P_DISPLAYNAME, val); UrlNamespace.addToRenamedResource(getOwner(), uri, this); UrlNamespace.addToRenamedResource(getOwner(), uri.substring(0, uri.length() - 1), this); } catch (ServiceException se) { ctxt.getResponseProp().addPropError(DavElements.E_DISPLAYNAME, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } mDeadProps.remove(name); continue; } else if (name.equals(DavElements.E_CALENDAR_COLOR) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) { // change color String colorStr = e.getText(); Color color = new Color(colorStr.substring(0, 7)); byte col = (byte) COLOR_LIST.indexOf(colorStr); if (col >= 0) color.setColor(col); try { Mailbox mbox = getMailbox(ctxt); mbox.setColor(ctxt.getOperationContext(), new int[] { mId }, type, color); } catch (ServiceException se) { ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_COLOR, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } mDeadProps.remove(name); continue; } else if (name.equals(DavElements.E_SUPPORTED_CALENDAR_COMPONENT_SET)) { // change default view @SuppressWarnings("unchecked") List<Element> elements = e.elements(DavElements.E_COMP); boolean isTodo = false; boolean isEvent = false; for (Element element : elements) { Attribute attr = element.attribute(DavElements.P_NAME); if (attr != null && CalComponent.VTODO.name().equals(attr.getValue())) { isTodo = true; } else if (attr != null && CalComponent.VEVENT.name().equals(attr.getValue())) { isEvent = true; } } if (isEvent ^ isTodo) { // we support a calendar collection of type event or todo, not both or none. Type type = (isEvent) ? Type.APPOINTMENT : Type.TASK; try { Mailbox mbox = getMailbox(ctxt); mbox.setFolderDefaultView(ctxt.getOperationContext(), mId, type); // Update the view for this collection. This collection may get cached if display name is modified. // See UrlNamespace.addToRenamedResource() if (this instanceof Collection) { ((Collection) this).view = type; } } catch (ServiceException se) { ctxt.getResponseProp().addPropError(name, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } } else { ctxt.getResponseProp().addPropError(name, new DavException.CannotModifyProtectedProperty(name)); } continue; } mDeadProps.put(name, e); reqProps.add(name); } String configVal = ""; if (mDeadProps.size() > 0) { org.dom4j.Document doc = org.dom4j.DocumentHelper.createDocument(); Element top = doc.addElement(CONFIG_KEY); for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) top.add(entry.getValue().detach()); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputFormat format = OutputFormat.createCompactFormat(); XMLWriter writer = new XMLWriter(out, format); writer.write(doc); configVal = new String(out.toByteArray(), "UTF-8"); if (configVal.length() > PROP_LENGTH_LIMIT) for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) ctxt.getResponseProp().addPropError(entry.getKey(), new DavException("prop length exceeded", DavProtocol.STATUS_INSUFFICIENT_STORAGE)); } Mailbox mbox = null; try { mbox = getMailbox(ctxt); mbox.lock.lock(); Metadata data = mbox.getConfig(ctxt.getOperationContext(), CONFIG_KEY); if (data == null) { data = new Metadata(); } data.put(Integer.toString(mId), configVal); mbox.setConfig(ctxt.getOperationContext(), CONFIG_KEY, data); } catch (ServiceException se) { for (QName qname : reqProps) ctxt.getResponseProp().addPropError(qname, new DavException(se.getMessage(), HttpServletResponse.SC_FORBIDDEN)); } finally { if (mbox != null) mbox.lock.release(); } }
From source file:com.zimbra.cs.dav.service.method.AclReports.java
License:Open Source License
private ArrayList<DavResource> getMatchingPrincipals(DavContext ctxt, QName prop, String match, GalSearchType type) throws DavException, ServiceException { Provisioning prov = Provisioning.getInstance(); ArrayList<DavResource> ret = new ArrayList<DavResource>(); Account authAccount = ctxt.getAuthAccount(); if (prop.equals(DavElements.E_DISPLAYNAME)) { if (!authAccount.isFeatureGalEnabled() || !authAccount.isFeatureGalAutoCompleteEnabled()) return ret; SearchGalResult result = prov.searchGal(prov.getDomain(authAccount), match, type, Provisioning.GalMode.zimbra, null); for (GalContact ct : result.getMatches()) { String email = (String) ct.getAttrs().get(ContactConstants.A_email); if (email != null) { Account acct = prov.get(Key.AccountBy.name, email); if (acct != null) ret.add(UrlNamespace.getPrincipal(ctxt, acct)); }//from w ww . j av a 2s .com } } else if (prop.equals(DavElements.E_CALENDAR_HOME_SET)) { int index = match.lastIndexOf('/'); if (index > 0) match = match.substring(index + 1); Account acct = prov.get(Key.AccountBy.name, match); if (acct != null) ret.add(UrlNamespace.getPrincipal(ctxt, acct)); } return ret; }
From source file:org.orbeon.oxf.processor.generator.RequestGenerator.java
License:Open Source License
@Override public ProcessorOutput createOutput(String name) { final ProcessorOutput output = new DigestTransformerOutputImpl(RequestGenerator.this, name) { public void readImpl(final PipelineContext pipelineContext, XMLReceiver xmlReceiver) { final State state = (State) getFilledOutState(pipelineContext); // Transform the resulting document into SAX TransformerUtils.sourceToSAX(new DocumentSource(state.requestDocument), new ForwardingXMLReceiver(xmlReceiver) { @Override public void startElement(String uri, String localname, String qName, Attributes attributes) throws SAXException { try { if (REQUEST_PRIVATE_NAMESPACE_URI.equals(uri)) { // Special treatment for this element if (FILE_ITEM_ELEMENT.equals(qName)) { // Marker for file item final String parameterName = attributes .getValue(PARAMETER_NAME_ATTRIBUTE); final int parameterPosition = Integer .parseInt(attributes.getValue(PARAMETER_POSITION_ATTRIBUTE)); final FileItem fileItem = (FileItem) ((Object[]) getRequest( pipelineContext).getParameterMap() .get(parameterName))[parameterPosition]; final AttributesImpl newAttributes = new AttributesImpl(); super.startPrefixMapping(XMLConstants.XSI_PREFIX, XMLConstants.XSI_URI); super.startPrefixMapping(XMLConstants.XSD_PREFIX, XMLConstants.XSD_URI); newAttributes.addAttribute(XMLConstants.XSI_URI, "type", "xsi:type", "CDATA", useBase64(pipelineContext, fileItem) ? XMLConstants.XS_BASE64BINARY_QNAME.getQualifiedName() : XMLConstants.XS_ANYURI_QNAME.getQualifiedName()); super.startElement("", "value", "value", newAttributes); writeFileItem(pipelineContext, fileItem, state.isSessionScope, useBase64(pipelineContext, fileItem), getXMLReceiver()); super.endElement("", "value", "value"); super.endPrefixMapping(XMLConstants.XSD_PREFIX); super.endPrefixMapping(XMLConstants.XSI_PREFIX); }//from www . ja v a 2 s . c o m } else if (localname.equals("body") && uri.equals("")) { // Marker for request body // Read InputStream into FileItem object, if not already present // We do this so we can read the body multiple times, if needed. // For large files, there will be a performance hit. If we knew // we didn't need to read it multiple times, we could avoid // saving the stream, but practically, it can happen, and it is // convenient. final Context context = getContext(pipelineContext); if (context.bodyFileItem != null || getRequest(pipelineContext).getInputStream() != null) { final ExternalContext.Request request = getRequest(pipelineContext); if (context.bodyFileItem == null) { final FileItem fileItem = new DiskFileItemFactory( getMaxMemorySizeProperty(), SystemUtils.getTemporaryDirectory()).createItem("dummy", "dummy", false, null); pipelineContext.addContextListener( new PipelineContext.ContextListenerAdapter() { public void contextDestroyed(boolean success) { fileItem.delete(); } }); final OutputStream outputStream = fileItem.getOutputStream(); NetUtils.copyStream(request.getInputStream(), outputStream); outputStream.close(); context.bodyFileItem = fileItem; } // Serialize the stream into the body element final AttributesImpl newAttributes = new AttributesImpl(); super.startPrefixMapping(XMLConstants.XSI_PREFIX, XMLConstants.XSI_URI); super.startPrefixMapping(XMLConstants.XSD_PREFIX, XMLConstants.XSD_URI); newAttributes.addAttribute(XMLConstants.XSI_URI, "type", "xsi:type", "CDATA", useBase64(pipelineContext, context.bodyFileItem) ? XMLConstants.XS_BASE64BINARY_QNAME.getQualifiedName() : XMLConstants.XS_ANYURI_QNAME.getQualifiedName()); super.startElement(uri, localname, qName, newAttributes); final String uriOrNull = writeFileItem(pipelineContext, context.bodyFileItem, state.isSessionScope, useBase64(pipelineContext, context.bodyFileItem), getXMLReceiver()); super.endElement(uri, localname, qName); super.endPrefixMapping(XMLConstants.XSD_PREFIX); super.endPrefixMapping(XMLConstants.XSI_PREFIX); // If the body is available as a URL, store it into the pipeline context. // This is done so that native code can access the body even if it has been read // already. Possibly, this could be handled more transparently by ExternalContext, // so that Request.getInputStream() works even upon multiple reads. // NOTE 2013-05-30: We used to store this into the request, but request attributes // are forwarded by LocalRequest. This means that a forwarded-to request might get // the wrong body! Instead, we now use PipelineContext, which is scoped to be per // request. Again, if ExternalContext was handling this, we could just leave it to // ExternalContext. if (uriOrNull != null) pipelineContext.setAttribute(BODY_REQUEST_ATTRIBUTE, uriOrNull); } } else { super.startElement(uri, localname, qName, attributes); } } catch (IOException e) { throw new OXFException(e); } } @Override public void endElement(String uri, String localname, String qName) throws SAXException { if (REQUEST_PRIVATE_NAMESPACE_URI.equals(uri) || localname.equals("body") && uri.equals("")) { // Ignore end element } else { super.endElement(uri, localname, qName); } } }); } protected boolean fillOutState(PipelineContext pipelineContext, DigestState digestState) { final State state = (State) digestState; if (state.requestDocument == null) { // Read config document final Document config = readCacheInputAsDOM4J(pipelineContext, INPUT_CONFIG); // Try to find stream-type attribute final QName streamTypeQName = Dom4jUtils.extractAttributeValueQName(config.getRootElement(), "stream-type"); if (streamTypeQName != null && !(streamTypeQName.equals(XMLConstants.XS_BASE64BINARY_QNAME) || streamTypeQName.equals(XMLConstants.XS_ANYURI_QNAME))) throw new OXFException( "Invalid value for stream-type attribute: " + streamTypeQName.getQualifiedName()); state.requestedStreamType = streamTypeQName; state.isSessionScope = "session".equals(config.getRootElement().attributeValue("stream-scope")); // Read and store request state.requestDocument = readRequestAsDOM4J(pipelineContext, config); // Check if the body was requested state.bodyRequested = XPathUtils.selectSingleNode(state.requestDocument, "/*/body") != null; } final Context context = getContext(pipelineContext); return !context.hasUpload && !state.bodyRequested; } protected byte[] computeDigest(PipelineContext pipelineContext, DigestState digestState) { final State state = (State) digestState; return XMLUtils.getDigest(new DocumentSource(state.requestDocument)); } }; addOutput(name, output); return output; }
From source file:org.orbeon.oxf.processor.serializer.BinaryTextXMLReceiver.java
License:Open Source License
public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) { if (elementLevel++ == 0) { // This is the root element // Get xsi:type attribute and determine whether the input is binary or text String xsiType = attributes.getValue(XMLConstants.XSI_TYPE_QNAME.getNamespaceURI(), XMLConstants.XSI_TYPE_QNAME.getName()); if (xsiType == null) throw new OXFException("Root element must contain an xsi:type attribute"); int colonIndex = xsiType.indexOf(':'); if (colonIndex == -1) throw new OXFException("Type xs:string or xs:base64Binary must be specified"); String typePrefix = xsiType.substring(0, colonIndex); String typeLocalName = xsiType.substring(colonIndex + 1); if (prefixMappings == null) throw new OXFException("Undeclared prefix in xsi:type: " + typePrefix); String typeNamespaceURI = prefixMappings.get(typePrefix); if (typeNamespaceURI == null) throw new OXFException("Undeclared prefix in xsi:type: " + typePrefix); QName typeQName = new QName(typeLocalName, new Namespace(typePrefix, typeNamespaceURI)); boolean isBinaryInput; if (typeQName.equals(XMLConstants.XS_BASE64BINARY_QNAME)) { isBinaryInput = true;//from w w w.j a v a2s.c o m } else if (typeQName.equals(XMLConstants.XS_STRING_QNAME)) { isBinaryInput = false; } else throw new OXFException("Type xs:string or xs:base64Binary must be specified"); // Set last-modified if available final String validityAttribute = attributes.getValue("last-modified"); if (StringUtils.isNotBlank(validityAttribute)) { // Override caching settings which may have taken place before if (response != null) response.setPageCaching(DateUtils.parseRFC1123(validityAttribute)); } // Set filename if available final String fileName = attributes.getValue("filename"); if (StringUtils.isNotBlank(fileName)) { if (response != null) response.setHeader("Content-Disposition", "attachment; filename=" + fileName); } // Set status code if available final String statusCode = attributes.getValue("status-code"); if (StringUtils.isNotBlank(statusCode)) { if (response != null) response.setStatus(Integer.parseInt(statusCode)); } // Set ContentHandler and headers depending on input type final String contentTypeAttribute = attributes.getValue("content-type"); if (isBinaryInput) { // Get content-type final String contentType = getContentType(contentTypeAttribute, DEFAULT_BINARY_CONTENT_TYPE); if (response != null) response.setContentType(contentType); outputContentHandler = new Base64XMLReceiver(outputStream); } else { // Get content-type and encoding final String contentType = getContentType(contentTypeAttribute, DEFAULT_TEXT_CONTENT_TYPE); final String encoding = getEncoding(contentTypeAttribute, CachedSerializer.DEFAULT_ENCODING); // Always set the content type with a charset attribute if (response != null) response.setContentType(contentType + "; charset=" + encoding); try { writer = new OutputStreamWriter(outputStream, encoding); } catch (UnsupportedEncodingException e) { throw new OXFException(e); } outputContentHandler = new TextXMLReceiver(writer); } } }
From source file:org.orbeon.oxf.properties.PropertySet.java
License:Open Source License
/** * Get a property.// w w w . j av a 2s . c o m * * @param name property name * @param type property type to check against, or null * @return property object if found */ private Property getProperty(String name, final QName type) { // Try first from exact properties Property property = exactProperties.get(name); if (property == null) { // If not found try traversing tree which contains properties with wildcards // Parse name and put into array final String[] tokensArray; { final List<String> tokensList = new ArrayList<String>(); for (StringTokenizer nameTokenizer = new StringTokenizer(name, "."); nameTokenizer.hasMoreTokens();) tokensList.add(nameTokenizer.nextToken()); tokensArray = tokensList.toArray(new String[tokensList.size()]); } // Call recursive worker property = getPropertyWorker(wildcardProperties, tokensArray, 0); if (property == null) return null; } // Found a value, check type if (type != null && !type.equals(property.type)) throw new OXFException("Invalid attribute type requested for property '" + name + "': expected " + type.getQualifiedName() + ", found " + property.type.getQualifiedName()); // Return value return property; }
From source file:org.orbeon.oxf.xforms.processor.handlers.xhtml.XFormsSelect1Handler.java
License:Open Source License
private static void addItemAttributes(Item item, AttributesImpl spanAttributes) { final Map<QName, String> itemAttributes = item.jAttributes(); if (itemAttributes != null && itemAttributes.size() > 0) { for (final Map.Entry<QName, String> entry : itemAttributes.entrySet()) { final QName attributeQName = entry.getKey(); if (!attributeQName.equals(XFormsConstants.CLASS_QNAME)) { // class is handled separately final String attributeName = Itemset.getAttributeName(attributeQName); spanAttributes.addAttribute("", attributeName, attributeName, XMLReceiverHelper.CDATA, entry.getValue()); }// ww w . ja v a2s. c om } } }
From source file:org.orbeon.oxf.xforms.XFormsModelBinds.java
License:Open Source License
public Item evaluateBindByType(RuntimeBind bind, int position, QName mipType) throws XPathException { if (mipType.equals(XFormsConstants.RELEVANT_QNAME)) { // Relevant final Boolean relevant = evaluateRelevantMIP(bind, position); return (relevant != null) ? BooleanValue.get(relevant) : null; } else if (mipType.equals(XFormsConstants.READONLY_QNAME)) { // Readonly final Boolean readonly = evaluateReadonlyMIP(bind, position); return (readonly != null) ? BooleanValue.get(readonly) : null; } else if (mipType.equals(XFormsConstants.REQUIRED_QNAME)) { // Required final Boolean required = evaluateRequiredMIP(bind, position); return (required != null) ? BooleanValue.get(required) : null; } else if (mipType.equals(XFormsConstants.TYPE_QNAME)) { // Type// w w w .j av a 2s . com final NamespaceMapping namespaceMapping = bind.staticBind.namespaceMapping(); final QName type = bind.evaluateTypeQName(namespaceMapping.mapping); return (type != null) ? new QNameValue(type.getNamespacePrefix(), type.getNamespaceURI(), type.getName(), null) : null; } else if (mipType.equals(XFormsConstants.CONSTRAINT_QNAME)) { // Constraint // TODO: Add support for other constraint levels. if (bind.staticBind.constraintsByLevel().nonEmpty()) return BooleanValue.get(failedConstraintMIPs(StaticBind.jErrorLevel(), bind, position).isEmpty()); else return null; } else if (mipType.equals(XFormsConstants.CALCULATE_QNAME)) { // Calculate final String result = evaluateCalculateBind(bind, position); return (result != null) ? new StringValue(result) : null; } else if (mipType.equals(XFormsConstants.XXFORMS_DEFAULT_QNAME)) { // xxf:default final String result = evaluateXXFormsDefaultBind(bind, position); return (result != null) ? new StringValue(result) : null; } else { // Try custom MIPs final String result = evaluateCustomMIP(bind, Model.buildCustomMIPName(mipType.getQualifiedName()), position); return (result != null) ? new StringValue(result) : null; } }