Java Code Examples for org.openide.xml.XMLUtil#toAttributeValue()

The following examples show how to use org.openide.xml.XMLUtil#toAttributeValue() . 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: ElementJavadoc.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private StringBuilder getFieldHeader(VariableElement fdoc) {
    StringBuilder sb = new StringBuilder();
    sb.append("<pre>"); //NOI18N
    fdoc.getAnnotationMirrors().forEach((annotationDesc) -> {
        appendAnnotation(sb, annotationDesc, true);
    });
    fdoc.getModifiers().forEach((modifier) -> {
        sb.append(modifier).append(' '); //NOI18N
    });
    appendType(sb, fdoc.asType(), false, false, false);
    sb.append(" <b>").append(fdoc.getSimpleName()).append("</b>"); //NOI18N
    String val = null;
    try {
        val = XMLUtil.toAttributeValue(fdoc.getConstantValue().toString());
    } catch (Exception ex) {}
    if (val != null && val.length() > 0)
        sb.append(" = ").append(val); //NOI18N
    sb.append("</pre>"); //NOI18N
    return sb;
}
 
Example 2
Source File: Task.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void perform() {
    if (!terminal().isVisibleInContainer()) {
	return ;
    }
    String newTitle = terminal().getTitle();
    if (terminal().isConnected() && newTitle != null) {
	String escaped;
	try {
	    escaped = XMLUtil.toAttributeValue(newTitle);
	} catch (CharConversionException ex) {
	    escaped = newTitle;
	}

	newTitle = "<html><b>" + escaped + "</b></html>";	// NOI18N
    }
    container().setTitle(terminal(), newTitle);
}
 
Example 3
Source File: BasicInfoPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages("ERR_Coord_breaks_pom=Error: Group Id or Artifact Id would invalidate Maven POM xml file.")
private boolean checkCoord(JTextField field) {
    String coord = field.getText();
    boolean result = false;
    try {
        String escaped = XMLUtil.toAttributeValue(coord);
        result = escaped.length() == coord.length() && coord.indexOf(">") == -1
                && coord.indexOf(" ") == -1;
    } catch (CharConversionException ex) {
        // ignore this one
    }
    if (result) {
        result = !containsMultiByte(coord);
    } else {
        category.setErrorMessage(ERR_Coord_breaks_pom());
    }

    if (result) {
        category.setErrorMessage(null);
    }

    return result;
}
 
Example 4
Source File: BreadCrumbsNodeImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static String escape(String s) {
    if (s != null) {
        //unescape unicode sequences first (would be better if Pretty would not print them, but that might be more difficult):
        Matcher matcher = UNICODE_SEQUENCE.matcher(s);
        
        if (matcher.find()) {
            StringBuilder result = new StringBuilder();
            int lastReplaceEnd = 0;
            do {
                result.append(s.substring(lastReplaceEnd, matcher.start()));
                int ch = Integer.parseInt(matcher.group(1), 16);
                result.append((char) ch);
                lastReplaceEnd = matcher.end();
            } while (matcher.find());
            result.append(s.substring(lastReplaceEnd));
            s = result.toString();
        }
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (CharConversionException ex) {
        }
    }
    return null;
}
 
Example 5
Source File: RemotePlatformProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void writeProperties(
        @NonNull final Map<String,String> props,
        @NonNull final Element element,
        @NonNull final Document doc) throws IOException {
    final Collection<String> sortedProps = new TreeSet<>(props.keySet());
    for (String name : sortedProps) {
        final String val = props.get(name);
        try {
            XMLUtil.toAttributeValue(name);
            XMLUtil.toAttributeValue(val);
            final Element propElement = doc.createElement(ELM_PROPERTY);
            propElement.setAttribute(ATTR_NAME,name);
            propElement.setAttribute(ATTR_VALUE,val);
            element.appendChild(propElement);
        } catch (CharConversionException e) {
            LOG.log(
                Level.WARNING,
                "Cannot store property: {0} value: {1}",       //NOI18N
                new Object[] {
                    name,
                    val
                });
        }
    }
}
 
Example 6
Source File: HtmlCompletionItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String escape(String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (Exception ex) {
        }
    }
    return s;
}
 
Example 7
Source File: CompletionProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String escape(String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (Exception ex) {}
    }
    return s;
}
 
Example 8
Source File: JspCompletionItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String escape(String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (Exception ex) {
        }
    }
    return s;
}
 
Example 9
Source File: Controller.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run() {
    List<OutputTab> toRemove = null;
    for (OutputTab t : components) {
        NbIO io = t.getIO();
        if (!ioToTab.containsKey(io)) {
            if (toRemove == null) {
                toRemove = new LinkedList<OutputTab>();
            }
            toRemove.add(t);
            continue;
        }
        if (LOG) {
            log ("Update name for " + io.getName() + " stream " +
                "closed is " + io.isStreamClosed());
        }
        String escaped;
        try {
            escaped = XMLUtil.toAttributeValue(io.getName());
        } catch (CharConversionException e) {
            escaped = io.getName();
        }
        String name = io.isStreamClosed() ?  io.getName() + " " : //NOI18N
            (DONT_USE_HTML ? io.getName() + " * " : "<html><b>" + escaped + " </b>&nbsp;</html>"); //NOI18N

        if (LOG) {
            log("  set name to " + name);
        }
        //#88204 apostophes are escaped in xm but not html
        io.getIOContainer().setTitle(t, name.replace("&apos;", "'"));
    }
    if (toRemove != null) {
        components.removeAll(toRemove);
    }
    nameUpdater = null;
}
 
Example 10
Source File: OutputTab.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void disableHtmlName() {
    Controller.getDefault().removeFromUpdater(this);
    String escaped;
    try {
        escaped = XMLUtil.toAttributeValue(io.getName() + " ");
    } catch (CharConversionException e) {
        escaped = io.getName() + " ";
    }
    //#88204 apostophes are escaped in xm but not html
    io.getIOContainer().setTitle(this, escaped.replace("&apos;", "'"));
}
 
Example 11
Source File: ChangeTypeFix.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static String escape(String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (Exception ex) {}
    }
    return s;
}
 
Example 12
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
public static String escape(@NonNull final String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (CharConversionException ex) {
        }
    }
    return null;
}
 
Example 13
Source File: UIUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static String escape(String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (CharConversionException ex) {
        }
    }
    return null;
}
 
Example 14
Source File: PropertyRefFinder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String escapeAttrValue(String attrValue) {
    try {
        return XMLUtil.toAttributeValue(attrValue);
    } catch (CharConversionException e) {
        return null;
    }
}
 
Example 15
Source File: JavaElementRefFinder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String escapeAttrValue(String attrValue) {
    try {
        return XMLUtil.toAttributeValue(attrValue);
    } catch (CharConversionException e) {
        return null;
    }
}
 
Example 16
Source File: SpringXMLConfigCompletionItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String escape(String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (Exception ex) {}
    }
    return s;
}
 
Example 17
Source File: ElementCompletionItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String escape(String s) {
    if (s != null) {
        try {
            return XMLUtil.toAttributeValue(s);
        } catch (Exception ex) {}
    }
    return s;
}