/** * Throws an {@link IllegalStateException} if this instance is locked. */ private void throwExceptionIfLocked() { Preconditions.checkState(!state.locked, "%s instance is read only", getElementId()); }
/** * Throws an {@link IllegalStateException} if this instance is locked. */ private void throwExceptionIfLocked() { Preconditions.checkState(!state.locked, "%s instance is read only", getElementId()); }
/** * Throws an {@link IllegalStateException} if this instance is locked. */ private void throwExceptionIfLocked() { Preconditions.checkState(!state.locked, "%s instance is read only", getElementId()); }
/** * Returns the QName of an element, possibly using the given metadata for * the name if it is not {@code null}. */ protected QName getName(Element e, ElementMetadata<?, ?> metadata) { return (metadata == null) ? e.getElementId() : metadata.getName(); }
/** * Returns the QName of an element, possibly using the given metadata for * the name if it is not {@code null}. */ protected QName getName(Element e, ElementMetadata<?, ?> metadata) { return (metadata == null) ? e.getElementId() : metadata.getName(); }
/** * Returns the QName of an element, possibly using the given metadata for * the name if it is not {@code null}. */ protected QName getName(Element e, ElementMetadata<?, ?> metadata) { return (metadata == null) ? e.getElementId() : metadata.getName(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Map.Entry<Element, List<ErrorContent>> error : errors.entrySet()) { sb.append(error.getKey().getElementId()); sb.append(" { "); List<String> errors = Lists.newArrayList(); for (ErrorContent element : error.getValue()) { errors.add(new ParseException(element).toXmlErrorMessage()); } sb.append(Join.join(", ", errors)); sb.append(" }"); } return sb.toString(); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Map.Entry<Element, List<ErrorContent>> error : errors.entrySet()) { sb.append(error.getKey().getElementId()); sb.append(" { "); List<String> errors = Lists.newArrayList(); for (ErrorContent element : error.getValue()) { errors.add(new ParseException(element).toXmlErrorMessage()); } sb.append(Join.join(", ", errors)); sb.append(" }"); } return sb.toString(); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Map.Entry<Element, List<ErrorContent>> error : errors.entrySet()) { sb.append(error.getKey().getElementId()); sb.append(" { "); List<String> errors = Lists.newArrayList(); for (ErrorContent element : error.getValue()) { errors.add(new ParseException(element).toXmlErrorMessage()); } sb.append(Join.join(", ", errors)); sb.append(" }"); } return sb.toString(); } }
/** * Sets the root element for generation. This is used to derive the default * metadata that should be used. */ private void setRootNamespace(ElementMetadata<?, ?> meta, Element e) { XmlNamespace rootNs = defaultNamespace; // If no default has been set, we use the namespace of the root element as // the default namespace. if (rootNs == USE_ROOT_ELEMENT_NAMESPACE) { if (meta != null) { rootNs = meta.getDefaultNamespace(); } else { rootNs = e.getElementId().getNs(); } } if (rootNs != null) { xw.setDefaultNamespace(rootNs); } }
/** * Sets the root element for generation. This is used to derive the default * metadata that should be used. */ private void setRootNamespace(ElementMetadata<?, ?> meta, Element e) { XmlNamespace rootNs = defaultNamespace; // If no default has been set, we use the namespace of the root element as // the default namespace. if (rootNs == USE_ROOT_ELEMENT_NAMESPACE) { if (meta != null) { rootNs = meta.getDefaultNamespace(); } else { rootNs = e.getElementId().getNs(); } } if (rootNs != null) { xw.setDefaultNamespace(rootNs); } }
/** * Sets the root element for generation. This is used to derive the default * metadata that should be used. */ private void setRootNamespace(ElementMetadata<?, ?> meta, Element e) { XmlNamespace rootNs = defaultNamespace; // If no default has been set, we use the namespace of the root element as // the default namespace. if (rootNs == USE_ROOT_ELEMENT_NAMESPACE) { if (meta != null) { rootNs = meta.getDefaultNamespace(); } else { rootNs = e.getElementId().getNs(); } } if (rootNs != null) { xw.setDefaultNamespace(rootNs); } }
@Override public String toString() { ToStringHelper helper = Objects.toStringHelper(this); helper.addValue(getElementId() + "@" + Integer.toHexString(hashCode())); Iterator<Attribute> aIter = getAttributeIterator(); while (aIter.hasNext()) { Attribute att = aIter.next(); helper.add(att.getAttributeKey().getId().toString(), att.getValue()); } if (hasTextValue()) { helper.addValue(getTextValue()); } return helper.toString(); } }
@Override public String toString() { ToStringHelper helper = Objects.toStringHelper(this); helper.addValue(getElementId() + "@" + Integer.toHexString(hashCode())); Iterator<Attribute> aIter = getAttributeIterator(); while (aIter.hasNext()) { Attribute att = aIter.next(); helper.add(att.getAttributeKey().getId().toString(), att.getValue()); } if (hasTextValue()) { helper.addValue(getTextValue()); } return helper.toString(); } }
@Override public String toString() { ToStringHelper helper = Objects.toStringHelper(this); helper.addValue(getElementId() + "@" + Integer.toHexString(hashCode())); Iterator<Attribute> aIter = getAttributeIterator(); while (aIter.hasNext()) { Attribute att = aIter.next(); helper.add(att.getAttributeKey().getId().toString(), att.getValue()); } if (hasTextValue()) { helper.addValue(getTextValue()); } return helper.toString(); } }
/** * Calculate the namespaces on an element using the given visitor to store * the namespaces. We cheat by using an attribute visitor for even visiting * the element names, because all we're doing with the visitor is adding a * QName. */ private static void calculateNamespaces(Map<String, XmlNamespace> namespaces, Element e, ElementMetadata<?, ?> metadata) { QName name = (metadata == null) ? e.getElementId() : metadata.getName(); addNamespace(namespaces, name); Iterator<Attribute> attIter = e.getAttributeIterator(metadata); while (attIter.hasNext()) { Attribute att = attIter.next(); AttributeKey<?> attKey = att.getAttributeKey(); AttributeMetadata<?> attMeta = (metadata == null) ? null : metadata.bindAttribute(attKey); name = (attMeta == null) ? attKey.getId() : attMeta.getName(); addNamespace(namespaces, name); } Iterator<Element> childIter = e.getElementIterator(metadata); while (childIter.hasNext()) { Element child = childIter.next(); ElementMetadata<?, ?> childMeta = (metadata == null) ? null : metadata.bindElement(child.getElementKey()); calculateNamespaces(namespaces, child, childMeta); } }
@Override public boolean startElement(XmlWriter xw, Element parent, Element e, ElementMetadata<?, ?> metadata) throws IOException { boolean isIcon = e.getElementId().equals(Source.ICON.getId()); boolean isLogo = e.getElementId().equals(Source.LOGO.getId()); if ((!isIcon && !isLogo) || !(parent instanceof Source)) { return super.startElement(xw, parent, e, metadata); } Source source = (Source) parent; if (isIcon && source.hasElement(Source.LOGO)) { // atom:logo takes precedence return false; } xw.startElement(Namespaces.rssNs, "image", null, null); xw.simpleElement(Namespaces.rssNs, "url", null, String.valueOf(e.getTextValue())); TextContent title = source.getTitle(); if (title != null) { xw.simpleElement(Namespaces.rssNs, "title", null, title.getPlainText()); } Link htmlLink = source.getHtmlLink(); if (htmlLink != null) { xw.simpleElement(Namespaces.rssNs, "link", null, htmlLink.getHref()); } xw.endElement(Namespaces.rssNs, "image"); return false; }
public Element parse(Element element) throws IOException, ParseException, ContentValidationException { ValidationContext vc = new ValidationContext(); ElementMetadata<?, ?> metadata = props.getRootMetadata(); this.rootHandler = createRootHandler(vc, element, metadata); QName elementName = (metadata == null) ? element.getElementId() : metadata.getName(); XmlNamespace elementNs = elementName.getNs(); this.rootNamespace = elementNs == null ? null : elementNs.getUri(); this.rootElementName = elementName.getLocalName(); try { eventSource.parse(this); } catch (SAXException e) { Exception rootException = e.getException(); if (rootException instanceof ParseException) { throwParseException((ParseException) rootException); } else if (rootException instanceof IOException) { LogUtils.logException(logger, Level.WARNING, null, e); throw (IOException) rootException; } else { LogUtils.logException(logger, Level.FINE, null, e); throw new ParseException(e); } } return element.resolve(metadata); }
public Element parse(Element element) throws IOException, ParseException, ContentValidationException { ValidationContext vc = new ValidationContext(); ElementMetadata<?, ?> metadata = props.getRootMetadata(); this.rootHandler = createRootHandler(vc, element, metadata); QName elementName = (metadata == null) ? element.getElementId() : metadata.getName(); XmlNamespace elementNs = elementName.getNs(); this.rootNamespace = elementNs == null ? null : elementNs.getUri(); this.rootElementName = elementName.getLocalName(); try { eventSource.parse(this); } catch (SAXException e) { Exception rootException = e.getException(); if (rootException instanceof ParseException) { throwParseException((ParseException) rootException); } else if (rootException instanceof IOException) { LogUtils.logException(logger, Level.WARNING, null, e); throw (IOException) rootException; } else { LogUtils.logException(logger, Level.FINE, null, e); throw new ParseException(e); } } return element.resolve(metadata); }
public Element parse(Element element) throws IOException, ParseException, ContentValidationException { ValidationContext vc = new ValidationContext(); ElementMetadata<?, ?> metadata = props.getRootMetadata(); this.rootHandler = createRootHandler(vc, element, metadata); QName elementName = (metadata == null) ? element.getElementId() : metadata.getName(); XmlNamespace elementNs = elementName.getNs(); this.rootNamespace = elementNs == null ? null : elementNs.getUri(); this.rootElementName = elementName.getLocalName(); try { eventSource.parse(this); } catch (SAXException e) { Exception rootException = e.getException(); if (rootException instanceof ParseException) { throwParseException((ParseException) rootException); } else if (rootException instanceof IOException) { LogUtils.logException(logger, Level.WARNING, null, e); throw (IOException) rootException; } else { LogUtils.logException(logger, Level.FINE, null, e); throw new ParseException(e); } } return element.resolve(metadata); }