List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:org.unitedinternet.cosmo.calendar.query.ComponentFilter.java
/** * Construct a ComponentFilter object from a DOM Element. * @param element The element./*from w w w . j av a 2 s . co m*/ * @param timezone The timezone. * @throws ParseException - if something is wrong this exception is thrown. */ public ComponentFilter(Element element, VTimeZone timezone) throws ParseException { // Name must be present validateName(element); final ElementIterator i = DomUtil.getChildren(element); int childCount = 0; while (i.hasNext()) { final Element child = i.nextElement(); childCount++; // if is-not-defined is present, then nothing else can be present validateNotDefinedState(childCount); Initializers.getInitializer(child.getLocalName()).initialize(child, timezone, this, childCount); } }
From source file:org.unitedinternet.cosmo.calendar.query.ParamFilter.java
/** * Construct a ParamFilter object from a DOM Element * @param element The element./* w ww . j ava 2 s . c om*/ * @throws ParseException - if something is wrong this exception is thrown. */ public ParamFilter(Element element) throws ParseException { // Get name which must be present name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException( "CALDAV:param-filter a property parameter name (e.g., \"PARTSTAT\") is required", -1); } // Can only have a single ext-match element ElementIterator i = DomUtil.getChildren(element); if (i.hasNext()) { Element child = i.nextElement(); if (i.hasNext()) { throw new ParseException( "CALDAV:param-filter only a single text-match or is-not-defined element is allowed", -1); } if (ELEMENT_CALDAV_TEXT_MATCH.equals(child.getLocalName())) { textMatchFilter = new TextMatchFilter(child); } else if (ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) { isNotDefinedFilter = new IsNotDefinedFilter(); } else { throw new ParseException("CALDAV:param-filter an invalid element name found", -1); } } }
From source file:org.unitedinternet.cosmo.calendar.query.PropertyFilter.java
/** * Construct a PropertyFilter object from a DOM Element * @param element The element./*from ww w . j a va 2 s .com*/ * @param timezone The timezone. * @throws ParseException - if something is wrong this exception is thrown. */ public PropertyFilter(Element element, VTimeZone timezone) throws ParseException { // Name must be present name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException("CALDAV:prop-filter a calendar property name (e.g., \"ATTENDEE\") is required", -1); } ElementIterator i = DomUtil.getChildren(element); int childCount = 0; while (i.hasNext()) { Element child = i.nextElement(); childCount++; // if is-not-defined is present, then nothing else can be present if (childCount > 1 && isNotDefinedFilter != null) { throw new ParseException("CALDAV:is-not-defined cannnot be present with other child" + " elements", -1); } if (ELEMENT_CALDAV_TIME_RANGE.equals(child.getLocalName())) { // Can only have one time-range or text-match if (timeRangeFilter != null) { throw new ParseException( "CALDAV:prop-filter only one time-range or text-match " + "element permitted", -1); } timeRangeFilter = new TimeRangeFilter(child, timezone); } else if (ELEMENT_CALDAV_TEXT_MATCH.equals(child.getLocalName())) { // Can only have one time-range or text-match if (textMatchFilter != null) { throw new ParseException( "CALDAV:prop-filter only one time-range or text-match element permitted", -1); } textMatchFilter = new TextMatchFilter(child); } else if (ELEMENT_CALDAV_PARAM_FILTER.equals(child.getLocalName())) { // Add to list paramFilters.add(new ParamFilter(child)); } else if (ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) { if (childCount > 1) { throw new ParseException( "CALDAV:is-not-defined cannnot be present with other " + "child elements", -1); } isNotDefinedFilter = new IsNotDefinedFilter(); } else { throw new ParseException("CALDAV:prop-filter an invalid element name found", -1); } } }
From source file:org.unitedinternet.cosmo.dav.caldav.report.CaldavOutputFilter.java
/** * Returns an <code>OutputFilter</code> representing the given * <code><C:calendar-data/>> element. * @param cdata the given calendar data. * @return output filter./*w w w. j a va 2 s .c o m*/ * @throws CosmoDavException - if something is wrong this exception is thrown. */ public static OutputFilter createFromXml(Element cdata) throws CosmoDavException { OutputFilter result = null; Period expand = null; Period limit = null; Period limitfb = null; String contentType = DomUtil.getAttribute(cdata, ATTR_CALDAV_CONTENT_TYPE, NAMESPACE_CALDAV); if (contentType != null && !contentType.equals(ICALENDAR_MEDIA_TYPE)) { throw new UnsupportedCalendarDataException(contentType); } String version = DomUtil.getAttribute(cdata, ATTR_CALDAV_CONTENT_TYPE, NAMESPACE_CALDAV); if (version != null && !version.equals(ICALENDAR_VERSION)) { throw new UnsupportedCalendarDataException(); } // Look at each child element of calendar-data for (ElementIterator iter = DomUtil.getChildren(cdata); iter.hasNext();) { Element child = iter.nextElement(); if (ELEMENT_CALDAV_COMP.equals(child.getLocalName())) { // At the top-level of calendar-data there should only be one // <comp> element as VCALENDAR components are the only top-level // components allowed in iCalendar data if (result != null) { return null; } // Get required name attribute and verify it is VCALENDAR String name = DomUtil.getAttribute(child, ATTR_CALDAV_NAME, null); if (name == null || !Calendar.VCALENDAR.equals(name)) { return null; } // Now parse filter item result = parseCalendarDataComp(child); } else if (ELEMENT_CALDAV_EXPAND.equals(child.getLocalName())) { expand = parsePeriod(child, true); } else if (ELEMENT_CALDAV_LIMIT_RECURRENCE_SET.equals(child.getLocalName())) { limit = parsePeriod(child, true); } else if (ELEMENT_CALDAV_LIMIT_FREEBUSY_SET.equals(child.getLocalName())) { limitfb = parsePeriod(child, true); } else { LOG.warn("Ignoring child " + child.getTagName() + " of " + cdata.getTagName()); } } // Now add any limit/expand options, creating a filter if one is not // already present if (result == null && (expand != null || limit != null || limitfb != null)) { result = new OutputFilter("VCALENDAR"); result.setAllSubComponents(); result.setAllProperties(); } if (expand != null) { result.setExpand(expand); } if (limit != null) { result.setLimit(limit); } if (limitfb != null) { result.setLimitfb(limitfb); } return result; }
From source file:org.unitedinternet.cosmo.dav.caldav.report.CaldavOutputFilter.java
private static OutputFilter parseCalendarDataComp(Element comp) { // Get required name attribute String name = DomUtil.getAttribute(comp, ATTR_CALDAV_NAME, null); if (name == null) { return null; }/* ww w.j av a2 s . c o m*/ // Now create filter item OutputFilter result = new OutputFilter(name); // Look at each child element ElementIterator i = DomUtil.getChildren(comp); while (i.hasNext()) { Element child = i.nextElement(); if (ELEMENT_CALDAV_ALLCOMP.equals(child.getLocalName())) { // Validity check if (result.hasSubComponentFilters()) { result = null; return null; } result.setAllSubComponents(); } else if (ELEMENT_CALDAV_ALLPROP.equals(child.getLocalName())) { // Validity check if (result.hasPropertyFilters()) { result = null; return null; } result.setAllProperties(); } else if (ELEMENT_CALDAV_COMP.equals(child.getLocalName())) { // Validity check if (result.isAllSubComponents()) { result = null; return null; } OutputFilter subfilter = parseCalendarDataComp(child); if (subfilter == null) { result = null; return null; } else { result.addSubComponent(subfilter); } } else if (ELEMENT_CALDAV_PROP.equals(child.getLocalName())) { // Validity check if (result.isAllProperties()) { result = null; return null; } // Get required name attribute String propname = DomUtil.getAttribute(child, ATTR_CALDAV_NAME, null); if (propname == null) { result = null; return null; } // Get optional novalue attribute boolean novalue = false; String novaluetxt = DomUtil.getAttribute(child, ATTR_CALDAV_NOVALUE, null); if (novaluetxt != null) { if (VALUE_YES.equals(novaluetxt)) { novalue = true; } else if (VALUE_NO.equals(novaluetxt)) { novalue = false; } else { result = null; return null; } } // Now add property item result.addProperty(propname, novalue); } } return result; }
From source file:org.unitedinternet.cosmo.util.DomWriter.java
private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing element " + e.getNodeName()); String local = e.getLocalName(); if (local == null) { local = e.getNodeName();// www . jav a 2s .c o m } String ns = e.getNamespaceURI(); if (ns != null) { String prefix = e.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, local, ns); writer.writeNamespace(prefix, ns); } else { writer.setDefaultNamespace(ns); writer.writeStartElement(ns, local); writer.writeDefaultNamespace(ns); } } else { writer.writeStartElement(local); } NamedNodeMap attributes = e.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { writeAttribute((Attr) attributes.item(i), writer); } NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { writeNode(children.item(i), writer); } writer.writeEndElement(); }
From source file:org.warlock.itk.distributionenvelope.Payload.java
/** * Handle signed content after decryption. The content is signed and encrypted * separately, and when a payload is decrypted it may or may not be signed. This * method checks if the payload has been signed: if not it is returned unchanged. * If the content has been signed, the signature is verified before the content * that was signed, is returned./*from www . jav a2 s. c o m*/ * @param decrypted Decrypted * @return * @throws Exception If the signature verification fails. */ private byte[] checkSignature(byte[] decrypted) throws Exception { String tryXml = null; try { tryXml = new String(decrypted); } catch (Exception e) { return decrypted; } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(tryXml))); Element rootElement = doc.getDocumentElement(); String rname = rootElement.getLocalName(); if ((rname == null) || !rname.contentEquals("Signature")) { return decrypted; } String rns = rootElement.getNamespaceURI(); if ((rns == null) || !rns.contentEquals(CfHNamespaceContext.DSNAMESPACE)) { return decrypted; } // We have a signed payload... Verify as an enveloping signature and return // the Object if the signature verifies OK. // verifySignature(rootElement); return getSignatureObject(rootElement); }
From source file:org.wso2.carbon.bpel.b4p.extension.PeopleActivity.java
private void init(ExtensionContext extensionContext, Element element) throws FaultException { if (!element.getLocalName().equals(BPEL4PeopleConstants.PEOPLE_ACTIVITY) || !element.getNamespaceURI().equals(BPEL4PeopleConstants.B4P_NAMESPACE)) { throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "No " + BPEL4PeopleConstants.PEOPLE_ACTIVITY + " activity found"); }/* w w w. jav a2 s . co m*/ name = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_NAME); inputVarName = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_INPUT_VARIABLE); outputVarName = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_OUTPUT_VARIABLE); isSkipable = "yes".equalsIgnoreCase(element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_IS_SKIPABLE)); processStandardElement(element); processAttachmentPropagationElement(element); String duDir = extensionContext.getDUDir().toString(); String duVersion = duDir.substring(duDir.lastIndexOf('-') + 1); if (duVersion.endsWith("/")) { duVersion = duVersion.substring(0, duVersion.lastIndexOf("/")); } else if (duVersion.endsWith("\\")) { duVersion = duVersion.substring(0, duVersion.lastIndexOf("\\")); } // //Commenting this logic to fix memory issues. // DeploymentUnitDir du = new DeploymentUnitDir(new File(extensionContext.getDUDir())); // processId = new QName(extensionContext.getProcessModel().getQName().getNamespaceURI(), // extensionContext.getProcessModel().getQName().getLocalPart() + "-" + // du.getStaticVersion()); processId = new QName(extensionContext.getProcessModel().getQName().getNamespaceURI(), extensionContext.getProcessModel().getQName().getLocalPart() + "-" + duVersion); Integer tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId); DeploymentUnitDir du = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore() .getTenantsProcessStore(tenantId).getDeploymentUnitDir(processId); isTwoWay = activityType.equals(InteractionType.TASK); deriveServiceEPR(du, extensionContext); }
From source file:org.wso2.carbon.bpel.core.ode.integration.BPELProcessProxy.java
/** * Create-and-copy a service-ref element. * * @param elmt Service Reference element * @return wrapped element//from w ww.j a va 2 s. c om */ public static MutableEndpoint createServiceRef(final Element elmt) { Document doc = DOMUtils.newDocument(); QName elQName = new QName(elmt.getNamespaceURI(), elmt.getLocalName()); // If we get a service-ref, just copy it, otherwise make a service-ref // wrapper if (!EndpointReference.SERVICE_REF_QNAME.equals(elQName)) { Element serviceref = doc.createElementNS(EndpointReference.SERVICE_REF_QNAME.getNamespaceURI(), EndpointReference.SERVICE_REF_QNAME.getLocalPart()); serviceref.appendChild(doc.importNode(elmt, true)); doc.appendChild(serviceref); } else { doc.appendChild(doc.importNode(elmt, true)); } return EndpointFactory.createEndpoint(doc.getDocumentElement()); }
From source file:org.wso2.carbon.identity.entitlement.pap.PAPPolicyReader.java
/** * @param doc/*from www. ja v a 2 s. c om*/ * @return * @throws org.wso2.balana.ParsingException */ private AbstractPolicy handleDocument(Document doc) throws ParsingException { // handle the policy, if it's a known type Element root = doc.getDocumentElement(); String name = root.getLocalName(); // see what type of policy this is if (name.equals("Policy")) { return Policy.getInstance(root); } else if (name.equals("PolicySet")) { return PolicySet.getInstance(root, policyFinder); } else { // this isn't a root type that we know how to handle throw new ParsingException("Unknown root document type: " + name); } }