org.jdom.CDATA Java Examples

The following examples show how to use org.jdom.CDATA. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JDOMNodePointer.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
/**
 * Get the parent of the specified node.
 * @param node to check
 * @return parent Element
 */
private static Element nodeParent(Object node) {
    if (node instanceof Element) {
        Object parent = ((Element) node).getParent();
        return parent instanceof Element ? (Element) parent : null;
    }
    if (node instanceof Text) {
        return (Element) ((Text) node).getParent();
    }
    if (node instanceof CDATA) {
        return (Element) ((CDATA) node).getParent();
    }
    if (node instanceof ProcessingInstruction) {
        return (Element) ((ProcessingInstruction) node).getParent();
    }
    if (node instanceof Comment) {
        return (Element) ((Comment) node).getParent();
    }
    return null;
}
 
Example #2
Source File: HypertextAttribute.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Element getJDOMElement() {
    Element attributeElement = this.createRootElement("attribute");
    Iterator<String> langIter = this.getTextMap().keySet().iterator();
    while (langIter.hasNext()) {
        String currentLangCode = langIter.next();
        String hypertext = (String) this.getTextMap().get(currentLangCode);
        if (null != hypertext && hypertext.trim().length() > 0) {
            Element hypertextElement = new Element("hypertext");
            hypertextElement.setAttribute("lang", currentLangCode);
            CDATA cdata = new CDATA(hypertext);
            hypertextElement.addContent(cdata);
            attributeElement.addContent(hypertextElement);
        }
    }
    return attributeElement;
}
 
Example #3
Source File: UserRegConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void addTemplateElements(Element parent, Map<String, Template> templates) {
	Iterator<Entry<String, Template>> templatesIter = templates.entrySet().iterator();
	while (templatesIter.hasNext()) {
		Element templateElement = new Element(TEMPLATE);
		Entry<String, Template> current = templatesIter.next();
		Template template = current.getValue();
		
		templateElement.setAttribute(TEMPLATE_LANG_ATTR, current.getKey());
		
		Element subjectElem = new Element(TEMPLATE_SUBJECT_CHILD);
		subjectElem.addContent(new CDATA(template.getSubject()));
		templateElement.addContent(subjectElem);
		
		Element bodyElem = new Element(TEMPLATE_BODY_CHILD);
		bodyElem.addContent(new CDATA(template.getBody()));
		templateElement.addContent(bodyElem);
		
		parent.addContent(templateElement);
	}
}
 
Example #4
Source File: WorkflowNotifierDOM.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Element prepareMailElement(NotifierConfig notifierConfig) {
	Element mailElement = new Element(MAIL_CHILD);
	mailElement.setAttribute(MAIL_SENDERCODE_ATTR, notifierConfig.getSenderCode());
	//mailElement.setAttribute(MAIL_MAILATTRNAME_ATTR, notifierConfig.getMailAttrName());
	mailElement.setAttribute(MAIL_HTML_ATTR, String.valueOf(notifierConfig.isHtml()));
	
	Element subjectElement = new Element(MAIL_SUBJECT_CHILD);
	subjectElement.addContent(new CDATA(notifierConfig.getSubject()));
	mailElement.addContent(subjectElement);
	
	Element headerElement = new Element(MAIL_HEADER_CHILD);
	headerElement.addContent(new CDATA(notifierConfig.getHeader()));
	mailElement.addContent(headerElement);
	
	Element templateElement = new Element(MAIL_TEMPLATE_CHILD);
	templateElement.addContent(new CDATA(notifierConfig.getTemplate()));
	mailElement.addContent(templateElement);
	
	Element footerElement = new Element(MAIL_FOOTER_CHILD);
	footerElement.addContent(new CDATA(notifierConfig.getFooter()));
	mailElement.addContent(footerElement);
	
	return mailElement;
}
 
Example #5
Source File: SaveEGTask.java    From BART with MIT License 5 votes vote down vote up
private void saveDependencies(Element rootElement)   {
    String dependencies = dto.getDependencies();
    if(dependencies == null)return;
    if(dependencies.isEmpty())return;
    Element dependenciesElement = new Element("dependencies");       
    dependenciesElement.addContent(new CDATA(dependencies));
    rootElement.addContent(dependenciesElement);
}
 
Example #6
Source File: JDOMNodePointer.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Add the specified content to this element.
 * @param content List
 */
private void addContent(List content) {
    Element element = (Element) node;
    int count = content.size();

    for (int i = 0; i < count; i++) {
        Object child = content.get(i);
        if (child instanceof Element) {
            child = ((Element) child).clone();
            element.addContent((Element) child);
        }
        else if (child instanceof Text) {
            child = ((Text) child).clone();
            element.addContent((Text) child);
        }
        else if (node instanceof CDATA) {
            child = ((CDATA) child).clone();
            element.addContent((CDATA) child);
        }
        else if (node instanceof ProcessingInstruction) {
            child = ((ProcessingInstruction) child).clone();
            element.addContent((ProcessingInstruction) child);
        }
        else if (node instanceof Comment) {
            child = ((Comment) child).clone();
            element.addContent((Comment) child);
        }
    }
}
 
Example #7
Source File: CustomWalker.java    From consulo with Apache License 2.0 5 votes vote down vote up
private final boolean isTextLike(final Content c) {
  switch (c.getCType()) {
    case Text:
    case CDATA:
    case EntityRef:
      return true;
    default:
      // nothing.
  }
  return false;
}
 
Example #8
Source File: XmlConfigurationAccessor.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public void writeConfiguration(XQueryRunConfiguration runConfiguration, Element element) {
    Element configuration = new Element(CONFIGURATION_TAG);
    element.addContent(configuration);
    if (runConfiguration.getMainFileName() != null)
        configuration.setAttribute("mainFileName", runConfiguration.getMainFileName());
    if (runConfiguration.getVMParameters() != null)
        configuration.setAttribute("vmParameters", runConfiguration.getVMParameters());
    if (runConfiguration.getProgramParameters() != null)
        configuration.setAttribute("programParameters", runConfiguration.getProgramParameters());
    if (runConfiguration.getRawWorkingDirectory() != null)
        configuration.setAttribute("workingDirectory", runConfiguration.getRawWorkingDirectory());
    configuration.setAttribute("alternativeJrePathEnabled", Boolean.toString(runConfiguration.isAlternativeJrePathEnabled()));
    if (runConfiguration.getAlternativeJrePath() != null)
        configuration.setAttribute("alternativeJrePath", runConfiguration.getAlternativeJrePath());
    configuration.setAttribute("contextItemEnabled", Boolean.toString(runConfiguration.isContextItemEnabled()));
    configuration.setAttribute("contextItemFromEditorEnabled", Boolean.toString(runConfiguration.isContextItemFromEditorEnabled()));
    if (runConfiguration.getContextItemText() != null) {
        Element contextItemTextElement = new Element("contextItemText");
        contextItemTextElement.addContent(new CDATA(runConfiguration.getContextItemText()));
        configuration.addContent(contextItemTextElement);
    }
    if (runConfiguration.getContextItemFile() != null) {
        configuration.setAttribute("contextItemFile", runConfiguration.getContextItemFile());
    }
    if (runConfiguration.getContextItemType() != null) {
        configuration.setAttribute("contextItemType", runConfiguration.getContextItemType());
    }
    if (runConfiguration.getDataSourceName() != null) {
        configuration.setAttribute("dataSourceName", runConfiguration.getDataSourceName());
    }
}
 
Example #9
Source File: XmlRenderer.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public Element renderCDATAElement(Element parent, String elementName, String data) {
	Element element = null;
    if (data != null) {
        element = renderElement(parent, elementName);
        element.addContent(new CDATA(data));
    }
    return element;
}
 
Example #10
Source File: MessageNotifierConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createSubjectModel(MessageModel model, Element modelElem) {
	Element subjectElem = new Element(MODEL_SUBJECT_CHILD);
	subjectElem.addContent(new CDATA(model.getSubjectModel()));
	modelElem.addContent(subjectElem);
	
	Element bodyElem = new Element(MODEL_BODY_CHILD);
	bodyElem.addContent(new CDATA(model.getBodyModel()));
	modelElem.addContent(bodyElem);
}
 
Example #11
Source File: MessageNotifierConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void addRecipients(String[] recipients, String elementName, Element recipientsElem) {
	if (recipients!=null) {
		for (String address : recipients) {
			Element addressElem = new Element(elementName);
			addressElem.addContent(new CDATA(address));
			recipientsElem.addContent(addressElem);
		}
	}
}
 
Example #12
Source File: MessageNotifierConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create the senders element starting from the given MailConfig.
 * @param config The configuration.
 */
protected Element createModelElement(MessageModel model) {
	Element modelElem = new Element(MODEL_ELEM);
	
	Element subjectElem = new Element(MODEL_SUBJECT_CHILD);
	subjectElem.addContent(new CDATA(model.getSubjectModel()));
	modelElem.addContent(subjectElem);
	
	Element bodyElem = new Element(MODEL_BODY_CHILD);
	bodyElem.addContent(new CDATA(model.getBodyModel()));
	modelElem.addContent(bodyElem);
	
	return modelElem;
}
 
Example #13
Source File: MessageNotifierConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void addRecipients(String[] recipients, String elementName, Element recipientsElem) {
	if (recipients!=null) {
		for (String address : recipients) {
			Element addressElem = new Element(elementName);
			addressElem.addContent(new CDATA(address));
			recipientsElem.addContent(addressElem);
		}
	}
}
 
Example #14
Source File: EnumeratorAttribute.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setConfig(Element configElement) {
    if (null != this.getStaticItems()) {
        CDATA cdata = new CDATA(this.getStaticItems());
        configElement.addContent(cdata);
    }
    if (null != this.getExtractorBeanName()) {
        configElement.setAttribute("extractorBean", this.getExtractorBeanName());
    }
    if (null != this.getCustomSeparator()) {
        configElement.setAttribute("separator", this.getCustomSeparator());
    }
}
 
Example #15
Source File: PmdProfileExporter.java    From sonar-p3c-pmd with MIT License 5 votes vote down vote up
private static void exportPmdRulesetToXml(PmdRuleset pmdRuleset, Writer writer, String profileName) {
  Element eltRuleset = new Element("ruleset");
  for (PmdRule pmdRule : pmdRuleset.getPmdRules()) {
    Element eltRule = new Element("rule");
    addAttribute(eltRule, "ref", pmdRule.getRef());
    addAttribute(eltRule, "class", pmdRule.getClazz());
    addAttribute(eltRule, "message", pmdRule.getMessage());
    addAttribute(eltRule, "name", pmdRule.getName());
    addAttribute(eltRule, "language", pmdRule.getLanguage());
    addChild(eltRule, "priority", pmdRule.getPriority());
    if (pmdRule.hasProperties()) {
      Element eltProperties = new Element("properties");
      eltRule.addContent(eltProperties);
      for (PmdProperty prop : pmdRule.getProperties()) {
        Element eltProperty = new Element("property");
        eltProperty.setAttribute("name", prop.getName());
        if (prop.isCdataValue()) {
          Element eltValue = new Element("value");
          eltValue.addContent(new CDATA(prop.getCdataValue()));
          eltProperty.addContent(eltValue);
        } else {
          eltProperty.setAttribute("value", prop.getValue());
        }
        eltProperties.addContent(eltProperty);
      }
    }
    eltRuleset.addContent(eltRule);
  }
  XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
  try {
    serializer.output(new Document(eltRuleset), writer);
  } catch (IOException e) {
    throw new IllegalStateException("An exception occurred while generating the PMD configuration file from profile: " + profileName, e);
  }
}
 
Example #16
Source File: ContentThreadConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Crea l'elemento della configurazione relativa alle mail.
 * 
 * @param config
 * La configurazione del servizio contentThread.
 * @return L'elemento di configurazione relativo alle mail.
 */
private Element createMailElement(ContentThreadConfig config) {
	Element mailElem = new Element(MAIL_ELEM);

	mailElem.setAttribute(MAIL_ALSOHTML_ATTR, String.valueOf(config.isAlsoHtml()));
	mailElem.setAttribute(MAIL_SENDERCODE_ATTR, config.getSenderCode());
	mailElem.setAttribute(MAIL_MAILATTRNAME_ATTR, config.getMailAttrName());

	Element subject = new Element(MAIL_SUBJECT_CHILD);
	subject.addContent(new CDATA(config.getSubject()));
	mailElem.addContent(subject);

	//

	Element htmlHeader = new Element(MAIL_HTML_HEADER_CHILD);
	htmlHeader.addContent(new CDATA(config.getHtmlHeader()));
	mailElem.addContent(htmlHeader);

	Element htmlFooter = new Element(MAIL_HTML_FOOTER_CHILD);
	htmlFooter.addContent(new CDATA(config.getHtmlFooter()));
	mailElem.addContent(htmlFooter);

	Element htmlSeparator = new Element(MAIL_HTML_SEPARATOR_CHILD);
	htmlSeparator.addContent(new CDATA(config.getHtmlSeparator()));
	mailElem.addContent(htmlSeparator);

	//

	Element textHeader = new Element(MAIL_TEXT_HEADER_CHILD);
	textHeader.addContent(new CDATA(config.getTextHeader()));
	mailElem.addContent(textHeader);

	Element textFooter = new Element(MAIL_TEXT_FOOTER_CHILD);
	textFooter.addContent(new CDATA(config.getTextFooter()));
	mailElem.addContent(textFooter);

	Element textSeparator = new Element(MAIL_TEXT_SEPARATOR_CHILD);
	textSeparator.addContent(new CDATA(config.getTextSeparator()));
	mailElem.addContent(textSeparator);

	//

	Element htmlHeaderM = new Element(MAIL_HTML_HEADER_CHILD_MOVE);
	htmlHeaderM.addContent(new CDATA(config.getHtmlHeaderMove()));
	mailElem.addContent(htmlHeaderM);

	Element htmlFooterM = new Element(MAIL_HTML_FOOTER_CHILD_MOVE);
	htmlFooterM.addContent(new CDATA(config.getHtmlFooterMove()));
	mailElem.addContent(htmlFooterM);

	Element htmlSeparatorM = new Element(MAIL_HTML_SEPARATOR_CHILD_MOVE);
	htmlSeparatorM.addContent(new CDATA(config.getHtmlSeparatorMove()));
	mailElem.addContent(htmlSeparatorM);

	//

	Element textHeaderM = new Element(MAIL_TEXT_HEADER_CHILD_MOVE);
	textHeaderM.addContent(new CDATA(config.getTextHeaderMove()));
	mailElem.addContent(textHeaderM);

	Element textFooterM = new Element(MAIL_TEXT_FOOTER_CHILD_MOVE);
	textFooterM.addContent(new CDATA(config.getTextFooterMove()));
	mailElem.addContent(textFooterM);

	Element textSeparatorM = new Element(MAIL_TEXT_SEPARATOR_CHILD_MOVE);
	textSeparatorM.addContent(new CDATA(config.getTextSeparatorMove()));
	mailElem.addContent(textSeparatorM);

	return mailElem;
}
 
Example #17
Source File: NewsletterConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Element createMailElement(NewsletterConfig config) {
	Element mailElem = new Element(MAIL_ELEM);
	mailElem.setAttribute(MAIL_ALSOHTML_ATTR, String.valueOf(config.isAlsoHtml()));
	mailElem.setAttribute(MAIL_SENDERCODE_ATTR, config.getSenderCode());
	mailElem.setAttribute(MAIL_UNSUBSCRIPTIONPAGE_ATTR, config.getUnsubscriptionPageCode());
	Element subject = new Element(MAIL_SUBJECT_CHILD);
	subject.addContent(new CDATA(config.getSubject()));
	mailElem.addContent(subject);
	Element htmlHeader = new Element(MAIL_HTML_HEADER_CHILD);
	htmlHeader.addContent(new CDATA(config.getHtmlHeader()));
	mailElem.addContent(htmlHeader);
	Element htmlFooter = new Element(MAIL_HTML_FOOTER_CHILD);
	htmlFooter.addContent(new CDATA(config.getHtmlFooter()));
	mailElem.addContent(htmlFooter);
	Element htmlSeparator = new Element(MAIL_HTML_SEPARATOR_CHILD);
	htmlSeparator.addContent(new CDATA(config.getHtmlSeparator()));
	mailElem.addContent(htmlSeparator);
	Element textHeader = new Element(MAIL_TEXT_HEADER_CHILD);
	textHeader.addContent(new CDATA(config.getTextHeader()));
	mailElem.addContent(textHeader);
	Element textFooter = new Element(MAIL_TEXT_FOOTER_CHILD);
	textFooter.addContent(new CDATA(config.getTextFooter()));
	mailElem.addContent(textFooter);
	Element textSeparator = new Element(MAIL_TEXT_SEPARATOR_CHILD);
	textSeparator.addContent(new CDATA(config.getTextSeparator()));
	mailElem.addContent(textSeparator);
	Element subscribersHtmlFooter = new Element(MAIL_SUBSCRIBER_HTML_FOOTER_CHILD);
	subscribersHtmlFooter.addContent(new CDATA(config.getSubscribersHtmlFooter()));
	mailElem.addContent(subscribersHtmlFooter);
	Element subscribersTextFooter = new Element(MAIL_SUBSCRIBER_TEXT_FOOTER_CHILD);
	subscribersTextFooter.addContent(new CDATA(config.getSubscribersTextFooter()));
	mailElem.addContent(subscribersTextFooter);
	Element subscriptionElem = new Element(MAIL_SUBSCRIPTION_CHILD);
	subscriptionElem.setAttribute(MAIL_SUBSCRIPTION_PAGECODE_ATTR, config.getSubscriptionPageCode());
	subscriptionElem.setAttribute(MAIL_SUBSCRIPTION_TOKENVALIDITY_ATTR, String.valueOf(config.getSubscriptionTokenValidityDays()));
	Element subscriptionSubject = new Element(MAIL_SUBSCRIPTION_SUBJECT_CHILD);
	subscriptionSubject.addContent(new CDATA(config.getSubscriptionSubject()));
	subscriptionElem.addContent(subscriptionSubject); 
	Element subscriptionTextBody = new Element(MAIL_SUBSCRIPTION_HTML_CHILD);
	subscriptionTextBody.addContent(new CDATA(config.getSubscriptionHtmlBody()));
	subscriptionElem.addContent(subscriptionTextBody); 
	Element subscriptionHtmlBody = new Element(MAIL_SUBSCRIPTION_TEXT_CHILD);
	subscriptionHtmlBody.addContent(new CDATA(config.getSubscriptionTextBody()));
	subscriptionElem.addContent(subscriptionHtmlBody); 
	mailElem.addContent(subscriptionElem);
	return mailElem;
}
 
Example #18
Source File: JDOMStreamWriter.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void writeCData(String data) throws XMLStreamException {
    currentNode.addContent(new CDATA(data));
}
 
Example #19
Source File: StaxSerializer.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
    // need to check if the namespace is declared before we write the
    // start element because that will put the namespace in the context.
    String elPrefix = e.getNamespacePrefix();
    String elUri = e.getNamespaceURI();

    String boundPrefix = writer.getPrefix(elUri);
    boolean writeElementNS = false;
    if (boundPrefix == null || !elPrefix.equals(boundPrefix)) {
        writeElementNS = true;
    }

    writer.writeStartElement(elPrefix, e.getName(), elUri);

    List<?> namespaces = e.getAdditionalNamespaces();
    for (Iterator<?> itr = namespaces.iterator(); itr.hasNext();) {
        Namespace ns = (Namespace)itr.next();

        String prefix = ns.getPrefix();
        String uri = ns.getURI();

        writer.setPrefix(prefix, uri);
        writer.writeNamespace(prefix, uri);

        if (elUri.equals(uri) && elPrefix.equals(prefix)) {
            writeElementNS = false;
        }
    }

    for (Iterator<?> itr = e.getAttributes().iterator(); itr.hasNext();) {
        Attribute attr = (Attribute)itr.next();
        String attPrefix = attr.getNamespacePrefix();
        String attUri = attr.getNamespaceURI();

        if (attUri == null || attUri.isEmpty()) {
            writer.writeAttribute(attr.getName(), attr.getValue());
        } else {
            writer.writeAttribute(attPrefix, attUri, attr.getName(), attr.getValue());

            if (!isDeclared(writer, attPrefix, attUri)) {
                if (elUri.equals(attUri) && elPrefix.equals(attPrefix)) {
                    if (writeElementNS) {
                        writer.setPrefix(attPrefix, attUri);
                        writer.writeNamespace(attPrefix, attUri);
                        writeElementNS = false;
                    }
                } else {
                    writer.setPrefix(attPrefix, attUri);
                    writer.writeNamespace(attPrefix, attUri);
                }
            }
        }
    }

    if (writeElementNS) {
        if (elPrefix == null || elPrefix.length() == 0) {
            writer.writeDefaultNamespace(elUri);
        } else {
            writer.writeNamespace(elPrefix, elUri);
        }
    }

    for (Iterator<?> itr = e.getContent().iterator(); itr.hasNext();) {
        Content n = (Content)itr.next();
        if (n instanceof CDATA) {
            writer.writeCData(n.getValue());
        } else if (n instanceof Text) {
            writer.writeCharacters(((Text)n).getText());
        } else if (n instanceof Element) {
            writeElement((Element)n, writer);
        } else if (n instanceof Comment) {
            writer.writeComment(n.getValue());
        } else if (n instanceof EntityRef) {
            // EntityRef ref = (EntityRef) n;
            // writer.writeEntityRef(ref.)
        }
    }

    writer.writeEndElement();
}
 
Example #20
Source File: JDOMNodePointer.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
/**
 * Execute test against node on behalf of pointer.
 * @param pointer Pointer
 * @param node to test
 * @param test to execute
 * @return true if node passes test
 */
public static boolean testNode(
    NodePointer pointer,
    Object node,
    NodeTest test) {
    if (test == null) {
        return true;
    }
    if (test instanceof NodeNameTest) {
        if (!(node instanceof Element)) {
            return false;
        }

        NodeNameTest nodeNameTest = (NodeNameTest) test;
        QName testName = nodeNameTest.getNodeName();
        String namespaceURI = nodeNameTest.getNamespaceURI();
        boolean wildcard = nodeNameTest.isWildcard();
        String testPrefix = testName.getPrefix();
        if (wildcard && testPrefix == null) {
            return true;
        }
        if (wildcard
            || testName.getName()
                    .equals(JDOMNodePointer.getLocalName(node))) {
            String nodeNS = JDOMNodePointer.getNamespaceURI(node);
            return equalStrings(namespaceURI, nodeNS) || nodeNS == null
                    && equalStrings(testPrefix, getPrefix(node));
        }
        return false;
    }
    if (test instanceof NodeTypeTest) {
        switch (((NodeTypeTest) test).getNodeType()) {
            case Compiler.NODE_TYPE_NODE :
                return true;
            case Compiler.NODE_TYPE_TEXT :
                return (node instanceof Text) || (node instanceof CDATA);
            case Compiler.NODE_TYPE_COMMENT :
                return node instanceof Comment;
            case Compiler.NODE_TYPE_PI :
                return node instanceof ProcessingInstruction;
            default:
                return false;
        }
    }
    if (test instanceof ProcessingInstructionTest && node instanceof ProcessingInstruction) {
        String testPI = ((ProcessingInstructionTest) test).getTarget();
        String nodePI = ((ProcessingInstruction) node).getTarget();
        return testPI.equals(nodePI);
    }
    return false;
}
 
Example #21
Source File: JDOMNodePointer.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
public String asPath() {
    if (id != null) {
        return "id('" + escape(id) + "')";
    }

    StringBuffer buffer = new StringBuffer();
    if (parent != null) {
        buffer.append(parent.asPath());
    }
    if (node instanceof Element) {
        // If the parent pointer is not a JDOMNodePointer, it is
        // the parent's responsibility to produce the node test part
        // of the path
        if (parent instanceof JDOMNodePointer) {
            if (buffer.length() == 0
                || buffer.charAt(buffer.length() - 1) != '/') {
                buffer.append('/');
            }
            String nsURI = getNamespaceURI();
            String ln = JDOMNodePointer.getLocalName(node);

            if (nsURI == null) {
                buffer.append(ln);
                buffer.append('[');
                buffer.append(getRelativePositionByQName()).append(']');
            }
            else {
                String prefix = getNamespaceResolver().getPrefix(nsURI);
                if (prefix != null) {
                    buffer.append(prefix);
                    buffer.append(':');
                    buffer.append(ln);
                    buffer.append('[');
                    buffer.append(getRelativePositionByQName());
                    buffer.append(']');
                }
                else {
                    buffer.append("node()");
                    buffer.append('[');
                    buffer.append(getRelativePositionOfElement());
                    buffer.append(']');
                }
            }

        }
    }
    else if (node instanceof Text || node instanceof CDATA) {
        buffer.append("/text()");
        buffer.append('[').append(getRelativePositionOfTextNode()).append(
            ']');
    }
    else if (node instanceof ProcessingInstruction) {
        buffer.append("/processing-instruction(\'").append(((ProcessingInstruction) node).getTarget()).append(
            "')");
        buffer.append('[').append(getRelativePositionOfPI()).append(
            ']');
    }
    return buffer.toString();
}
 
Example #22
Source File: JDOMModelTest.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
private void appendXMLSignature(
    StringBuffer buffer,
    Object object,
    boolean elements,
    boolean attributes,
    boolean text,
    boolean pi) 
{
    if (object instanceof Document) {
        buffer.append("<D>");
        appendXMLSignature(
            buffer,
            ((Document) object).getContent(),
            elements,
            attributes,
            text,
            pi);
        buffer.append("</D");
    }
    else if (object instanceof Element) {
        String tag = elements ? ((Element) object).getName() : "E";
        buffer.append("<");
        buffer.append(tag);
        buffer.append(">");
        appendXMLSignature(
            buffer,
            ((Element) object).getContent(),
            elements,
            attributes,
            text,
            pi);
        buffer.append("</");
        buffer.append(tag);
        buffer.append(">");
    }
    else if (object instanceof Text || object instanceof CDATA) {
        if (text) {
            String string = ((Text) object).getText();
            string = string.replace('\n', '=');
            buffer.append(string);
        }
    }
}